Skip to content

Commit

Permalink
iio: adc: meson-saradc: check for devm_kasprintf failure
Browse files Browse the repository at this point in the history
devm_kasprintf() may return NULL on failure of internal allocation thus
the assignments to  init.name  are not safe if not checked. On error
meson_sar_adc_clk_init() returns negative values so -ENOMEM in the
(unlikely) failure case of devm_kasprintf() should be fine here.

Signed-off-by: Nicholas Mc Guire <[email protected]>
Fixes: 3adbf34 ("iio: adc: add a driver for the SAR ADC found in Amlogic Meson SoCs")
Acked-by: Martin Blumenstingl <[email protected]>
Tested-by: Martin Blumenstingl <[email protected]>
Signed-off-by: Jonathan Cameron <[email protected]>
  • Loading branch information
Nicholas Mc Guire authored and jic23 committed Nov 25, 2018
1 parent bac257b commit aad172b
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions drivers/iio/adc/meson_saradc.c
Original file line number Diff line number Diff line change
Expand Up @@ -658,6 +658,9 @@ static int meson_sar_adc_clk_init(struct iio_dev *indio_dev,

init.name = devm_kasprintf(&indio_dev->dev, GFP_KERNEL, "%pOF#adc_div",
indio_dev->dev.of_node);
if (!init.name)
return -ENOMEM;

init.flags = 0;
init.ops = &clk_divider_ops;
clk_parents[0] = __clk_get_name(priv->clkin);
Expand All @@ -677,6 +680,9 @@ static int meson_sar_adc_clk_init(struct iio_dev *indio_dev,

init.name = devm_kasprintf(&indio_dev->dev, GFP_KERNEL, "%pOF#adc_en",
indio_dev->dev.of_node);
if (!init.name)
return -ENOMEM;

init.flags = CLK_SET_RATE_PARENT;
init.ops = &clk_gate_ops;
clk_parents[0] = __clk_get_name(priv->adc_div_clk);
Expand Down

0 comments on commit aad172b

Please sign in to comment.