Skip to contentSkip to conversation

iio: adc: viperboard: Call platform_set_drvdata before devm_iio_device_register

PATCH In review Johannes Thumshirn 2 participants 3 messages Feb 1, 2014 IIO

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 iio: adc: viperboard: Call platform_set_drvdata before devm_iio_device_register

Call platform_set_drvdata before devm_iio_device_register to avoid possible race condition when accessing driver data.

---
 drivers/iio/adc/viperboard_adc.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/iio/adc/viperboard_adc.c +2 -2
index d0add8f..7d9bd05 100644
@@ -133,14 +133,14 @@ static int vprbrd_adc_probe(struct platform_device *pdev)
 	indio_dev->channels = vprbrd_adc_iio_channels;
 	indio_dev->num_channels = ARRAY_SIZE(vprbrd_adc_iio_channels);
 
+	platform_set_drvdata(pdev, indio_dev);
+
 	ret = devm_iio_device_register(&pdev->dev, indio_dev);
 	if (ret) {
 		dev_err(&pdev->dev, "could not register iio (adc)");
 		return ret;
 	}
 
-	platform_set_drvdata(pdev, indio_dev);
-
 	return 0;
 }
 
Signature · 1 line
1.8.5.3
#1 lore raw
Quoted 2 lines · Johannes Thumshirn

Call platform_set_drvdata before devm_iio_device_register to avoid possible race condition when accessing driver data.

I don't think the driver data is accessed from within any of the IIO device callbacks. In fact I don't think it is accessed at all with the latest conversion to devm_iio_device_register(). So I think the call to platform_set_drvdata can just be removed.

Quoted 28 lines
---
 drivers/iio/adc/viperboard_adc.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/iio/adc/viperboard_adc.c +2 -2
index d0add8f..7d9bd05 100644
@@ -133,14 +133,14 @@ static int vprbrd_adc_probe(struct platform_device *pdev)
 	indio_dev->channels = vprbrd_adc_iio_channels;
 	indio_dev->num_channels = ARRAY_SIZE(vprbrd_adc_iio_channels);
 
+	platform_set_drvdata(pdev, indio_dev);
+
 	ret = devm_iio_device_register(&pdev->dev, indio_dev);
 	if (ret) {
 		dev_err(&pdev->dev, "could not register iio (adc)");
 		return ret;
 	}
 
-	platform_set_drvdata(pdev, indio_dev);
-
 	return 0;
 }
 
#2 lore raw
Quoted 31 lines · Lars-Peter Clausen
Quoted 2 lines · Johannes Thumshirn

Call platform_set_drvdata before devm_iio_device_register to avoid possible race condition when accessing driver data.

I don't think the driver data is accessed from within any of the IIO device callbacks. In fact I don't think it is accessed at all with the latest conversion to devm_iio_device_register(). So I think the call to platform_set_drvdata can just be removed.

Quoted 22 lines
---
 drivers/iio/adc/viperboard_adc.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/iio/adc/viperboard_adc.c +2 -0
index d0add8f..7d9bd05 100644
@@ -133,14 +133,14 @@ static int vprbrd_adc_probe(struct platform_device *pdev)
 	indio_dev->channels = vprbrd_adc_iio_channels;
 	indio_dev->num_channels = ARRAY_SIZE(vprbrd_adc_iio_channels);
 
+	platform_set_drvdata(pdev, indio_dev);
+
 	ret = devm_iio_device_register(&pdev->dev, indio_dev);
 	if (ret) {
 		dev_err(&pdev->dev, "could not register iio (adc)");
 		return ret;
 	}
 
Quoted 7 lines

drivers/iio/adc/viperboard_adc.c static int vprbrd_adc_probe(struct platform_device *pdev) · line 146

Quoted 6 lines
drivers/iio/adc/viperboard_adc.c +0 -2
-	platform_set_drvdata(pdev, indio_dev);
-
 	return 0;
 }
 

Looks like you're right. So we can drop this patch and I'll make a remove version.