linux-amlogic.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] iio: adc: meson-saradc: check for devm_kasprintf failure
@ 2018-11-22  7:46 Nicholas Mc Guire
  2018-11-22 21:44 ` Martin Blumenstingl
  0 siblings, 1 reply; 3+ messages in thread
From: Nicholas Mc Guire @ 2018-11-22  7:46 UTC (permalink / raw)
  To: linus-amlogic

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 <hofrat@osadl.org>
Fixes: 3adbf3427330 ("iio: adc: add a driver for the SAR ADC found in Amlogic Meson SoCs")
---

Problem located with an experimental coccinelle script

Patch was compile tested with: multi_v7_defconfig (implies ARCH_MESON=y &
MESON_SARADC=y)

Patch is against 4.20-rc3 (localversion-next is next-20181122)

 drivers/iio/adc/meson_saradc.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/drivers/iio/adc/meson_saradc.c b/drivers/iio/adc/meson_saradc.c
index 028ccd2..672a5de 100644
--- a/drivers/iio/adc/meson_saradc.c
+++ b/drivers/iio/adc/meson_saradc.c
@@ -589,6 +589,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);
@@ -608,6 +611,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);
-- 
2.1.4

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* [PATCH] iio: adc: meson-saradc: check for devm_kasprintf failure
  2018-11-22  7:46 [PATCH] iio: adc: meson-saradc: check for devm_kasprintf failure Nicholas Mc Guire
@ 2018-11-22 21:44 ` Martin Blumenstingl
  2018-11-25 10:39   ` Jonathan Cameron
  0 siblings, 1 reply; 3+ messages in thread
From: Martin Blumenstingl @ 2018-11-22 21:44 UTC (permalink / raw)
  To: linus-amlogic

On Thu, Nov 22, 2018 at 8:52 AM Nicholas Mc Guire <hofrat@osadl.org> wrote:
>
> 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 <hofrat@osadl.org>
> Fixes: 3adbf3427330 ("iio: adc: add a driver for the SAR ADC found in Amlogic Meson SoCs")
Acked-by: Martin Blumenstingl <martin.blumenstingl@googlemail.com>

thank you for the patch!
I tested the non-error case on my Odroid-C1 and it still works fine.


Regards
Martin

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [PATCH] iio: adc: meson-saradc: check for devm_kasprintf failure
  2018-11-22 21:44 ` Martin Blumenstingl
@ 2018-11-25 10:39   ` Jonathan Cameron
  0 siblings, 0 replies; 3+ messages in thread
From: Jonathan Cameron @ 2018-11-25 10:39 UTC (permalink / raw)
  To: linus-amlogic

On Thu, 22 Nov 2018 22:44:55 +0100
Martin Blumenstingl <martin.blumenstingl@googlemail.com> wrote:

> On Thu, Nov 22, 2018 at 8:52 AM Nicholas Mc Guire <hofrat@osadl.org> wrote:
> >
> > 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 <hofrat@osadl.org>
> > Fixes: 3adbf3427330 ("iio: adc: add a driver for the SAR ADC found in Amlogic Meson SoCs")  
> Acked-by: Martin Blumenstingl <martin.blumenstingl@googlemail.com>
> 
> thank you for the patch!
> I tested the non-error case on my Odroid-C1 and it still works fine.
Applied.  I also added a tested by tag for you Martin as it's always nice
for the log to reflect when people make the effort!

Applied to the togreg branch of iio.git and pushed out as testing for
the autobuilders to play with it.

Thanks,

Jonathan

> 
> 
> Regards
> Martin

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2018-11-25 10:39 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-11-22  7:46 [PATCH] iio: adc: meson-saradc: check for devm_kasprintf failure Nicholas Mc Guire
2018-11-22 21:44 ` Martin Blumenstingl
2018-11-25 10:39   ` Jonathan Cameron

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).