Skip to contentSkip to conversation

iio: adc: meson-saradc: use NULL instead of 0 for pointer

PATCH In review Paolo Cretaro 3 participants 7 messages May 28, 2017 – Jun 6, 2017

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 iio: adc: meson-saradc: use NULL instead of 0 for pointer

Fix sparse warning: Using plain integer as NULL pointer

---
 drivers/iio/adc/meson_saradc.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/iio/adc/meson_saradc.c +1 -1
index 81cd39a57fe3..fb3f67a9ae1f 100644
@@ -481,7 +481,7 @@ static void meson_sar_adc_clear_fifo(struct iio_dev *indio_dev)
 		if (!meson_sar_adc_get_fifo_count(indio_dev))
 			break;
 
-		regmap_read(priv->regmap, MESON_SAR_ADC_FIFO_RD, 0);
+		regmap_read(priv->regmap, MESON_SAR_ADC_FIFO_RD, NULL);
 	}
 }
 
Signature · 1 line
2.13.0
maintainer
#1 lore raw
Quoted 3 lines · On Sun, 28 May 2017 13:24:38 +0200 Paolo Cretaro <[email protected]> wrote:

Fix sparse warning: Using plain integer as NULL pointer

This looks fine to me, but ideally you should always try to include the driver author - particularly in the case of patches to a recent driver such as this one.

To that end I've cc'd Martin.

Jonathan

Quoted 17 lines
---
 drivers/iio/adc/meson_saradc.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/iio/adc/meson_saradc.c +1 -1
index 81cd39a57fe3..fb3f67a9ae1f 100644
@@ -481,7 +481,7 @@ static void meson_sar_adc_clear_fifo(struct iio_dev *indio_dev)
 		if (!meson_sar_adc_get_fifo_count(indio_dev))
 			break;
 
-		regmap_read(priv->regmap, MESON_SAR_ADC_FIFO_RD, 0);
+		regmap_read(priv->regmap, MESON_SAR_ADC_FIFO_RD, NULL);
 	}
 }
 
#2 lore raw
Quoted 9 lines · Jonathan Cameron
Quoted 3 lines · On Sun, 28 May 2017 13:24:38 +0200 Paolo Cretaro <[email protected]> wrote:

Fix sparse warning: Using plain integer as NULL pointer

This looks fine to me, but ideally you should always try to include the driver author - particularly in the case of patches to a recent driver such as this one.

Sure, thanks for pointing this out, I just felt a bit embarrassed to bother too many people with such a trivial patch.

Paolo

Quoted 22 lines

To that end I've cc'd Martin.

Jonathan

Quoted 17 lines
---
 drivers/iio/adc/meson_saradc.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/iio/adc/meson_saradc.c +1 -1
index 81cd39a57fe3..fb3f67a9ae1f 100644
@@ -481,7 +481,7 @@ static void meson_sar_adc_clear_fifo(struct iio_dev *indio_dev)
 		if (!meson_sar_adc_get_fifo_count(indio_dev))
 			break;
 
-		regmap_read(priv->regmap, MESON_SAR_ADC_FIFO_RD, 0);
+		regmap_read(priv->regmap, MESON_SAR_ADC_FIFO_RD, NULL);
 	}
 }
 
reviewer Acked-by
#3 lore raw
In reply to Jonathan Cameron

Hi Paolo, Hi Jonathan,

Quoted 11 lines · Jonathan Cameron
Quoted 3 lines · On Sun, 28 May 2017 13:24:38 +0200 Paolo Cretaro <[email protected]> wrote:

Fix sparse warning: Using plain integer as NULL pointer

This looks fine to me, but ideally you should always try to include the driver author - particularly in the case of patches to a recent driver such as this one.

To that end I've cc'd Martin.

thanks for spotting this (and providing a patch to fix it) this looks good to me, so:

if you can wait until next weekend then I can also test this on real hardware.

Quoted 13 lines

Jonathan

Quoted 12 lines
---
 drivers/iio/adc/meson_saradc.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/iio/adc/meson_saradc.c +0 -0
index 81cd39a57fe3..fb3f67a9ae1f 100644
@@ -481,7 +481,7 @@ static void meson_sar_adc_clear_fifo(struct iio_dev *indio_dev)
              if (!meson_sar_adc_get_fifo_count(indio_dev))
                      break;
 
Quoted 6 lines

drivers/iio/adc/meson_saradc.c static void meson_sar_adc_clear_fifo(struct iio_dev *indio_dev) · line 487

Quoted 5 lines
drivers/iio/adc/meson_saradc.c +1 -1
-             regmap_read(priv->regmap, MESON_SAR_ADC_FIFO_RD, 0);
+             regmap_read(priv->regmap, MESON_SAR_ADC_FIFO_RD, NULL);
      }
 }
 

Regards,
Martin

maintainer
#4 lore raw
Quoted 13 lines · On Sun, 28 May 2017 23:17:57 +0200 Martin Blumenstingl…

Hi Paolo, Hi Jonathan,

Quoted 10 lines · Jonathan Cameron
Quoted 3 lines · On Sun, 28 May 2017 13:24:38 +0200 Paolo Cretaro <[email protected]> wrote:

Fix sparse warning: Using plain integer as NULL pointer

This looks fine to me, but ideally you should always try to include the driver author - particularly in the case of patches to a recent driver such as this one.

Quoted 6 lines
Quoted 1 line

To that end I've cc'd Martin.

thanks for spotting this (and providing a patch to fix it) this looks good to me, so:

if you can wait until next weekend then I can also test this on real hardware.

I've applied it to the togreg branch of iio.git but as that always goes out as testing for at least a few days first (which I will happily rebase) give me a shout if anything goes wrong!

Jonathan

Quoted 23 lines
Quoted 14 lines

Jonathan

Quoted 12 lines
---
 drivers/iio/adc/meson_saradc.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/iio/adc/meson_saradc.c +0 -0
index 81cd39a57fe3..fb3f67a9ae1f 100644
@@ -481,7 +481,7 @@ static void meson_sar_adc_clear_fifo(struct iio_dev *indio_dev)
              if (!meson_sar_adc_get_fifo_count(indio_dev))
                      break;
 
Quoted 6 lines

drivers/iio/adc/meson_saradc.c static void meson_sar_adc_clear_fifo(struct iio_dev *indio_dev) · line 487

Quoted 5 lines
drivers/iio/adc/meson_saradc.c +1 -1
-             regmap_read(priv->regmap, MESON_SAR_ADC_FIFO_RD, 0);
+             regmap_read(priv->regmap, MESON_SAR_ADC_FIFO_RD, NULL);
      }
 }
 

Regards,
Martin

#5 lore raw

Hi Paolo, Hi Jonathan,

Quoted 17 lines · Jonathan Cameron
Quoted 14 lines · On Sun, 28 May 2017 23:17:57 +0200 Martin Blumenstingl…

Hi Paolo, Hi Jonathan,

Quoted 11 lines · Jonathan Cameron
Quoted 3 lines · On Sun, 28 May 2017 13:24:38 +0200 Paolo Cretaro <[email protected]> wrote:

Fix sparse warning: Using plain integer as NULL pointer

This looks fine to me, but ideally you should always try to include the driver author - particularly in the case of patches to a recent driver such as this one.

To that end I've cc'd Martin.

Quoted 8 lines
Quoted 5 lines

thanks for spotting this (and providing a patch to fix it) this looks good to me, so:

if you can wait until next weekend then I can also test this on real hardware.

I've applied it to the togreg branch of iio.git but as that always goes out as testing for at least a few days first (which I will happily rebase) give me a shout if anything goes wrong!

I have tested this on actual hardware and it seems that there's a bug in the meson-saradc driver (before and after this patch):
if there are still "old" values in the FIFO then the driver currently crashes because regmap_read (regmap_mmio_read in case of the meson-saradc driver to be precise) de-references the "value" pointer (the parameter which we're trying to clean up here) -> this leads to a NULL de-reference. this happens regardless of whether we are passing "0" or "NULL"

I posted a patch which fixes the crash - and as a bonus this should also fix the sparse warning reported by Paolo:
http://lists.infradead.org/pipermail/linux-amlogic/2017-June/003863.html

Quoted 25 lines

Jonathan

Quoted 23 lines
Quoted 14 lines

Jonathan

Quoted 12 lines
---
 drivers/iio/adc/meson_saradc.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/iio/adc/meson_saradc.c +0 -0
index 81cd39a57fe3..fb3f67a9ae1f 100644
@@ -481,7 +481,7 @@ static void meson_sar_adc_clear_fifo(struct iio_dev *indio_dev)
              if (!meson_sar_adc_get_fifo_count(indio_dev))
                      break;
 
Quoted 6 lines

drivers/iio/adc/meson_saradc.c static void meson_sar_adc_clear_fifo(struct iio_dev *indio_dev) · line 487

Quoted 5 lines
drivers/iio/adc/meson_saradc.c +1 -1
-             regmap_read(priv->regmap, MESON_SAR_ADC_FIFO_RD, 0);
+             regmap_read(priv->regmap, MESON_SAR_ADC_FIFO_RD, NULL);
      }
 }
 

Regards,
Martin

#6 lore raw

Il 04/06/2017 15:32, Martin Blumenstingl ha scritto:

Quoted 37 lines

Hi Paolo, Hi Jonathan,

Quoted 17 lines · Jonathan Cameron
Quoted 14 lines · On Sun, 28 May 2017 23:17:57 +0200 Martin Blumenstingl…

Hi Paolo, Hi Jonathan,

Quoted 11 lines · Jonathan Cameron
Quoted 3 lines · On Sun, 28 May 2017 13:24:38 +0200 Paolo Cretaro <[email protected]> wrote:

Fix sparse warning: Using plain integer as NULL pointer

This looks fine to me, but ideally you should always try to include the driver author - particularly in the case of patches to a recent driver such as this one.

To that end I've cc'd Martin.

Quoted 8 lines
Quoted 5 lines

thanks for spotting this (and providing a patch to fix it) this looks good to me, so:

if you can wait until next weekend then I can also test this on real hardware.

I've applied it to the togreg branch of iio.git but as that always goes out as testing for at least a few days first (which I will happily rebase) give me a shout if anything goes wrong!

I have tested this on actual hardware and it seems that there's a bug in the meson-saradc driver (before and after this patch):
if there are still "old" values in the FIFO then the driver currently crashes because regmap_read (regmap_mmio_read in case of the meson-saradc driver to be precise) de-references the "value" pointer (the parameter which we're trying to clean up here) -> this leads to a NULL de-reference. this happens regardless of whether we are passing "0" or "NULL"

Quoted 3 lines

I posted a patch which fixes the crash - and as a bonus this should also fix the sparse warning reported by Paolo:
http://lists.infradead.org/pipermail/linux-amlogic/2017-June/003863.html

Nice, thanks!

Paolo

Quoted 26 lines
Quoted 26 lines

Jonathan

Quoted 23 lines
Quoted 14 lines

Jonathan

Quoted 12 lines
---
  drivers/iio/adc/meson_saradc.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
drivers/iio/adc/meson_saradc.c +0 -0
index 81cd39a57fe3..fb3f67a9ae1f 100644
@@ -481,7 +481,7 @@ static void meson_sar_adc_clear_fifo(struct iio_dev *indio_dev)
               if (!meson_sar_adc_get_fifo_count(indio_dev))
                       break;
 
Quoted 6 lines

drivers/iio/adc/meson_saradc.c static void meson_sar_adc_clear_fifo(struct iio_dev *indio_dev) · line 487

Quoted 5 lines
drivers/iio/adc/meson_saradc.c +1 -1
-             regmap_read(priv->regmap, MESON_SAR_ADC_FIFO_RD, 0);
+             regmap_read(priv->regmap, MESON_SAR_ADC_FIFO_RD, NULL);
       }
  }
 

Regards,
Martin