Skip to contentSkip to conversation

staging: iio: cdc: ad7746: initial effort to move out of staging

PATCH Superseded Lucas Stankus 5 participants 11 messages May 11, 2021 – May 18, 2021

Subsystems (4)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

cover staging: iio: cdc: ad7746: initial effort to move out of staging

Cleans up the driver by removing vague comments, fixing code alignment and refactoring the probe function return. This patch set also contains a small bug fix when setting the amount of iio channels in AD7745 devices.

These small patches are a starting point for improving the ad7746 driver, hopefully to a point where it's possible to get it out of staging. I'm looking up to feedback on what could be improved to accomplish that.

Lucas Stankus (2):
staging: iio: cdc: clean up driver comments and probe return
staging: iio: cdc: avoid overwrite of num_channels

 drivers/staging/iio/cdc/ad7746.c | 32 ++++++++++----------------------
 1 file changed, 10 insertions(+), 22 deletions(-)
Signature · 1 line
2.31.1
#1 lore raw

PATCH 1/2 staging: iio: cdc: ad7746: clean up driver comments and probe return

Remove vague comments, align temperature comment with indent block and simplify probe return on device register.

Also fix the following checkpatch warning:
CHECK: Alignment should match open parenthesis

---
 drivers/staging/iio/cdc/ad7746.c | 31 ++++++++++---------------------
 1 file changed, 10 insertions(+), 21 deletions(-)
drivers/staging/iio/cdc/ad7746.c +10 -21
index dfd71e99e872..e03d010b2f4c 100644
@@ -84,10 +84,6 @@
 #define AD7746_CAPDAC_DACEN		BIT(7)
 #define AD7746_CAPDAC_DACP(x)		((x) & 0x7F)
 
-/*
- * struct ad7746_chip_info - chip specific information
- */
-
 struct ad7746_chip_info {
 	struct i2c_client *client;
 	struct mutex lock; /* protect sensor state */
@@ -232,13 +228,14 @@ static int ad7746_select_channel(struct iio_dev *indio_dev,
 
 		if (chip->capdac_set != chan->channel) {
 			ret = i2c_smbus_write_byte_data(chip->client,
-				AD7746_REG_CAPDACA,
-				chip->capdac[chan->channel][0]);
+							AD7746_REG_CAPDACA,
+							chip->capdac[chan->channel][0]);
 			if (ret < 0)
 				return ret;
+
 			ret = i2c_smbus_write_byte_data(chip->client,
-				AD7746_REG_CAPDACB,
-				chip->capdac[chan->channel][1]);
+							AD7746_REG_CAPDACB,
+							chip->capdac[chan->channel][1]);
 			if (ret < 0)
 				return ret;
 
@@ -564,10 +561,10 @@ static int ad7746_read_raw(struct iio_dev *indio_dev,
 
 		switch (chan->type) {
 		case IIO_TEMP:
-		/*
-		 * temperature in milli degrees Celsius
-		 * T = ((*val / 2048) - 4096) * 1000
-		 */
+			/*
+			 * temperature in milli degrees Celsius
+			 * T = ((*val / 2048) - 4096) * 1000
+			 */
 			*val = (*val * 125) / 256;
 			break;
 		case IIO_VOLTAGE:
@@ -669,10 +666,6 @@ static const struct iio_info ad7746_info = {
 	.write_raw = ad7746_write_raw,
 };
 
-/*
- * device probe and remove
- */
-
 static int ad7746_probe(struct i2c_client *client,
 			const struct i2c_device_id *id)
 {
@@ -730,11 +723,7 @@ static int ad7746_probe(struct i2c_client *client,
 	if (ret < 0)
 		return ret;
 
-	ret = devm_iio_device_register(indio_dev->dev.parent, indio_dev);
-	if (ret)
-		return ret;
-
-	return 0;
+	return devm_iio_device_register(indio_dev->dev.parent, indio_dev);
 }
 
 static const struct i2c_device_id ad7746_id[] = {
Signature · 1 line
2.31.1
#5 lore raw

PATCH 2/2 staging: iio: cdc: ad7746: avoid overwrite of num_channels

In reply to Lucas Stankus

AD7745 devices don't have the CIN2 pins and therefore can't handle related channels. Forcing the number of AD7746 channels may lead to enabling more channels than what the hardware actually supports.
Avoid num_channels being overwritten after first assignment.

---
 drivers/staging/iio/cdc/ad7746.c | 1 -
 1 file changed, 1 deletion(-)
drivers/staging/iio/cdc/ad7746.c +0 -1
index e03d010b2f4c..9e0da43b2871 100644
@@ -693,7 +693,6 @@ static int ad7746_probe(struct i2c_client *client,
 		indio_dev->num_channels = ARRAY_SIZE(ad7746_channels);
 	else
 		indio_dev->num_channels =  ARRAY_SIZE(ad7746_channels) - 2;
-	indio_dev->num_channels = ARRAY_SIZE(ad7746_channels);
 	indio_dev->modes = INDIO_DIRECT_MODE;
 
 	if (pdata) {
Signature · 1 line
2.31.1
#2 lore raw

Re: [PATCH 1/2] staging: iio: cdc: ad7746: clean up driver comments and probe return

In reply to Lucas Stankus

Hi Lucas,

Quoted 16 lines · Lucas Stankus

Remove vague comments, align temperature comment with indent block and simplify probe return on device register.

Also fix the following checkpatch warning:
CHECK: Alignment should match open parenthesis

---
 drivers/staging/iio/cdc/ad7746.c | 31 ++++++++++---------------------
 1 file changed, 10 insertions(+), 21 deletions(-)
drivers/staging/iio/cdc/ad7746.c +0 -0
index dfd71e99e872..e03d010b2f4c 100644

drivers/staging/iio/cdc/ad7746.c line 90

Quoted 7 lines
drivers/staging/iio/cdc/ad7746.c +0 -4
@@ -84,10 +84,6 @@
 #define AD7746_CAPDAC_DACEN		BIT(7)
 #define AD7746_CAPDAC_DACP(x)		((x) & 0x7F)
 
-/*
- * struct ad7746_chip_info - chip specific information
- */
-

Comment deletions should go in a separate patch

Quoted 11 lines
drivers/staging/iio/cdc/ad7746.c +2 -2
 struct ad7746_chip_info {
 	struct i2c_client *client;
 	struct mutex lock; /* protect sensor state */
@@ -232,13 +228,14 @@ static int ad7746_select_channel(struct iio_dev *indio_dev,
 
 		if (chip->capdac_set != chan->channel) {
 			ret = i2c_smbus_write_byte_data(chip->client,
-				AD7746_REG_CAPDACA,
-				chip->capdac[chan->channel][0]);
+							AD7746_REG_CAPDACA,
+							chip->capdac[chan->channel][0]);

drivers/staging/iio/cdc/ad7746.c static int ad7746_select_channel(struct iio_dev *indio_dev, · line 240

Quoted 10 lines
drivers/staging/iio/cdc/ad7746.c +3 -2
 			if (ret < 0)
 				return ret;
+
 			ret = i2c_smbus_write_byte_data(chip->client,
-				AD7746_REG_CAPDACB,
-				chip->capdac[chan->channel][1]);
+							AD7746_REG_CAPDACB,
+							chip->capdac[chan->channel][1]);
 			if (ret < 0)
 				return ret;

Alignments of function argument form a different logical change and should go on a separate patch...

Quoted 28 lines
drivers/staging/iio/cdc/ad7746.c +4 -8
@@ -564,10 +561,10 @@ static int ad7746_read_raw(struct iio_dev *indio_dev,
 
 		switch (chan->type) {
 		case IIO_TEMP:
-		/*
-		 * temperature in milli degrees Celsius
-		 * T = ((*val / 2048) - 4096) * 1000
-		 */
+			/*
+			 * temperature in milli degrees Celsius
+			 * T = ((*val / 2048) - 4096) * 1000
+			 */
 			*val = (*val * 125) / 256;
 			break;
 		case IIO_VOLTAGE:
@@ -669,10 +666,6 @@ static const struct iio_info ad7746_info = {
 	.write_raw = ad7746_write_raw,
 };
 
-/*
- * device probe and remove
- */
-
 static int ad7746_probe(struct i2c_client *client,
 			const struct i2c_device_id *id)
 {

drivers/staging/iio/cdc/ad7746.c static int ad7746_probe(struct i2c_client *client, · line 727

Quoted 10 lines
drivers/staging/iio/cdc/ad7746.c +1 -5
@@ -730,11 +723,7 @@ static int ad7746_probe(struct i2c_client *client,
 	if (ret < 0)
 		return ret;
 
-	ret = devm_iio_device_register(indio_dev->dev.parent, indio_dev);
-	if (ret)
-		return ret;
-
-	return 0;
+	return devm_iio_device_register(indio_dev->dev.parent, indio_dev);
 }

this return value fix should go in a separate patch

Quoted 6 lines
drivers/staging/iio/cdc/ad7746.c +0 -0
 static const struct i2c_device_id ad7746_id[] = {
Signature · 1 line
2.31.1

so, in my opinion, this patch could be split
in three different patches.

Thank you,

fabio

#6 lore raw

Re: [PATCH 2/2] staging: iio: cdc: ad7746: avoid overwrite of num_channels

In reply to Lucas Stankus
Quoted 16 lines · Lucas Stankus

AD7745 devices don't have the CIN2 pins and therefore can't handle related channels. Forcing the number of AD7746 channels may lead to enabling more channels than what the hardware actually supports.
Avoid num_channels being overwritten after first assignment.

---
 drivers/staging/iio/cdc/ad7746.c | 1 -
 1 file changed, 1 deletion(-)
drivers/staging/iio/cdc/ad7746.c +0 -0
index e03d010b2f4c..9e0da43b2871 100644

drivers/staging/iio/cdc/ad7746.c static int ad7746_probe(struct i2c_client *client, · line 696

Quoted 4 lines
drivers/staging/iio/cdc/ad7746.c +0 -1
@@ -693,7 +693,6 @@ static int ad7746_probe(struct i2c_client *client,
                indio_dev->num_channels = ARRAY_SIZE(ad7746_channels);
        else
                indio_dev->num_channels =  ARRAY_SIZE(ad7746_channels) - 2;
-       indio_dev->num_channels = ARRAY_SIZE(ad7746_channels);

ohh; good catch

this falls into the category of a fix, so a Fixes tag is required; this looks so old, that i did not bother tracking it before 83e416f458d53 [which is 2011]

so, maybe something like:

Fixes 83e416f458d53 ("staging: iio: adc: Replace, rewrite ad7745 from

scratch.")

Quoted 6 lines
drivers/staging/iio/cdc/ad7746.c +0 -1
        indio_dev->modes = INDIO_DIRECT_MODE;
 
        if (pdata) {
--

2.31.1

maintainer
#7 lore raw

Re: [PATCH 2/2] staging: iio: cdc: ad7746: avoid overwrite of num_channels

Quoted 25 lines · On Wed, 12 May 2021 20:20:02 +0300 Alexandru Ardelean <[email protected]>…
Quoted 16 lines · Lucas Stankus

AD7745 devices don't have the CIN2 pins and therefore can't handle related channels. Forcing the number of AD7746 channels may lead to enabling more channels than what the hardware actually supports.
Avoid num_channels being overwritten after first assignment.

---
 drivers/staging/iio/cdc/ad7746.c | 1 -
 1 file changed, 1 deletion(-)
drivers/staging/iio/cdc/ad7746.c +0 -0
index e03d010b2f4c..9e0da43b2871 100644

drivers/staging/iio/cdc/ad7746.c static int ad7746_probe(struct i2c_client *client, · line 696

Quoted 4 lines
drivers/staging/iio/cdc/ad7746.c +0 -1
@@ -693,7 +693,6 @@ static int ad7746_probe(struct i2c_client *client,
                indio_dev->num_channels = ARRAY_SIZE(ad7746_channels);
        else
                indio_dev->num_channels =  ARRAY_SIZE(ad7746_channels) - 2;
-       indio_dev->num_channels = ARRAY_SIZE(ad7746_channels);  

ohh; good catch

Quoted 8 lines

this falls into the category of a fix, so a Fixes tag is required; this looks so old, that i did not bother tracking it before 83e416f458d53 [which is 2011]

so, maybe something like:

Fixes 83e416f458d53 ("staging: iio: adc: Replace, rewrite ad7745 from

scratch.")

ouch. Given I was queuing up some fixes I've added this one to the fixes-togreg branch of iio.git and marked it for stable.

So drop this one from your v2 series with the changes requested in patch 1.

Thanks,

Jonathan

Quoted 7 lines
Quoted 7 lines
drivers/staging/iio/cdc/ad7746.c +0 -1
        indio_dev->modes = INDIO_DIRECT_MODE;
 
        if (pdata) {
--

2.31.1

maintainer
#3 lore raw

Re: [PATCH 1/2] staging: iio: cdc: ad7746: clean up driver comments and probe return

In reply to Lucas Stankus
Quoted 7 lines · On Tue, 11 May 2021 17:54:01 -0300 Lucas Stankus <[email protected]>…

Remove vague comments, align temperature comment with indent block and simplify probe return on device register.

Also fix the following checkpatch warning:
CHECK: Alignment should match open parenthesis

As Fabio pointed out, finer grained patches with one type of change per patch would be good.

Quoted 27 lines
---
 drivers/staging/iio/cdc/ad7746.c | 31 ++++++++++---------------------
 1 file changed, 10 insertions(+), 21 deletions(-)
drivers/staging/iio/cdc/ad7746.c +2 -6
index dfd71e99e872..e03d010b2f4c 100644
@@ -84,10 +84,6 @@
 #define AD7746_CAPDAC_DACEN		BIT(7)
 #define AD7746_CAPDAC_DACP(x)		((x) & 0x7F)
 
-/*
- * struct ad7746_chip_info - chip specific information
- */
-
 struct ad7746_chip_info {
 	struct i2c_client *client;
 	struct mutex lock; /* protect sensor state */
@@ -232,13 +228,14 @@ static int ad7746_select_channel(struct iio_dev *indio_dev,
 
 		if (chip->capdac_set != chan->channel) {
 			ret = i2c_smbus_write_byte_data(chip->client,
-				AD7746_REG_CAPDACA,
-				chip->capdac[chan->channel][0]);
+							AD7746_REG_CAPDACA,
+							chip->capdac[chan->channel][0]);

drivers/staging/iio/cdc/ad7746.c static int ad7746_select_channel(struct iio_dev *indio_dev, · line 240

Quoted 10 lines
drivers/staging/iio/cdc/ad7746.c +3 -2
 			if (ret < 0)
 				return ret;
+
 			ret = i2c_smbus_write_byte_data(chip->client,
-				AD7746_REG_CAPDACB,
-				chip->capdac[chan->channel][1]);
+							AD7746_REG_CAPDACB,
+							chip->capdac[chan->channel][1]);
 			if (ret < 0)
 				return ret;

I wondered if it might be sensible to factor this code out to reduce the indent and make things more readable. Having taken a look it seems there is another place with exactly the same call sequence. From how it's used there, I'm assuming this is updating the offsets. As such, I would introduce an

ad7746_offsets_set(struct iio_dev *indio_dev, int channel)

or similar.

Quoted 40 lines
drivers/staging/iio/cdc/ad7746.c +5 -13
@@ -564,10 +561,10 @@ static int ad7746_read_raw(struct iio_dev *indio_dev,
 
 		switch (chan->type) {
 		case IIO_TEMP:
-		/*
-		 * temperature in milli degrees Celsius
-		 * T = ((*val / 2048) - 4096) * 1000
-		 */
+			/*
+			 * temperature in milli degrees Celsius
+			 * T = ((*val / 2048) - 4096) * 1000
+			 */
 			*val = (*val * 125) / 256;
 			break;
 		case IIO_VOLTAGE:
@@ -669,10 +666,6 @@ static const struct iio_info ad7746_info = {
 	.write_raw = ad7746_write_raw,
 };
 
-/*
- * device probe and remove
- */
-
 static int ad7746_probe(struct i2c_client *client,
 			const struct i2c_device_id *id)
 {
@@ -730,11 +723,7 @@ static int ad7746_probe(struct i2c_client *client,
 	if (ret < 0)
 		return ret;
 
-	ret = devm_iio_device_register(indio_dev->dev.parent, indio_dev);
-	if (ret)
-		return ret;
-
-	return 0;
+	return devm_iio_device_register(indio_dev->dev.parent, indio_dev);
 }
 
 static const struct i2c_device_id ad7746_id[] = {
#4 lore raw

Re: [PATCH 1/2] staging: iio: cdc: ad7746: clean up driver comments and probe return

Quoted 7 lines · Jonathan Cameron
Quoted 3 lines · On Tue, 11 May 2021 17:54:01 -0300 Lucas Stankus <[email protected]>…

Remove vague comments, align temperature comment with indent block and simplify probe return on device register.

Quoted 7 lines
Quoted 4 lines

Also fix the following checkpatch warning:
CHECK: Alignment should match open parenthesis

As Fabio pointed out, finer grained patches with one type of change per patch would be good.

Thank you both for the review and sorry for the radio silence, I'll split the patch in the v2.

Quoted 43 lines
Quoted 27 lines

---
 drivers/staging/iio/cdc/ad7746.c | 31 ++++++++++---------------------

 1 file changed, 10 insertions(+), 21 deletions(-)
drivers/staging/iio/cdc/ad7746.c +0 -4
index dfd71e99e872..e03d010b2f4c 100644
@@ -84,10 +84,6 @@
  #define AD7746_CAPDAC_DACEN          BIT(7)
  #define AD7746_CAPDAC_DACP(x)                ((x) & 0x7F)
 
-/*
- * struct ad7746_chip_info - chip specific information
- */
-
  struct ad7746_chip_info {
       struct i2c_client *client;

      struct mutex lock; /* protect sensor state */

drivers/staging/iio/cdc/ad7746.c +1 -2
@@ -232,13 +228,14 @@ static int ad7746_select_channel(struct iio_dev *indio_dev,
 
               if (chip->capdac_set != chan->channel) {
                       ret = i2c_smbus_write_byte_data(chip->client,
-                             AD7746_REG_CAPDACA,
-                             chip->capdac[chan->channel][0]);
+                                                     AD7746_REG_CAPDACA,

drivers/staging/iio/cdc/ad7746.c static int ad7746_select_channel(struct iio_dev *indio_dev, · line 239

Quoted 10 lines
drivers/staging/iio/cdc/ad7746.c +4 -2
+                                                     chip->capdac[chan->channel][0]);
                       if (ret < 0)
                               return ret;
+                       ret = i2c_smbus_write_byte_data(chip->client,
-                             AD7746_REG_CAPDACB,
-                             chip->capdac[chan->channel][1]);
+                                                     AD7746_REG_CAPDACB,
+                                                     chip->capdac[chan->channel][1]);
                       if (ret < 0)
                               return ret;

I wondered if it might be sensible to factor this code out to reduce the indent and make things more readable.  Having taken a look it seems there is another place with exactly the same call sequence.  From how it's used there, I'm assuming this is updating the offsets.  As such, I would introduce an

Quoted 4 lines

ad7746_offsets_set(struct iio_dev *indio_dev, int channel)

or similar.

Makes sense, I'll do that in the v2 as well.

Quoted 42 lines
Quoted 41 lines
drivers/staging/iio/cdc/ad7746.c +0 -0
@@ -564,10 +561,10 @@ static int ad7746_read_raw(struct iio_dev *indio_dev,
 
               switch (chan->type) {

              case IIO_TEMP:
-             /*
-              * temperature in milli degrees Celsius
-              * T = ((*val / 2048) - 4096) * 1000
-              */
+                     /*
+                      * temperature in milli degrees Celsius
+                      * T = ((*val / 2048) - 4096) * 1000
+                      */
                      *val = (*val * 125) / 256; break;
              case IIO_VOLTAGE:

drivers/staging/iio/cdc/ad7746.c +1 -9
@@ -669,10 +666,6 @@ static const struct iio_info ad7746_info = {
       .write_raw = ad7746_write_raw,
  };
 
-/*
- * device probe and remove
- */
-
  static int ad7746_probe(struct i2c_client *client,
                       const struct i2c_device_id *id)
  {
@@ -730,11 +723,7 @@ static int ad7746_probe(struct i2c_client *client,
       if (ret < 0)
               return ret;
 
-     ret = devm_iio_device_register(indio_dev->dev.parent, indio_dev);
-     if (ret)
-             return ret;
-
-     return 0;
+     return devm_iio_device_register(indio_dev->dev.parent, indio_dev);
  }
 
  static const struct i2c_device_id ad7746_id[] = {
#8 lore raw

Re: [PATCH 2/2] staging: iio: cdc: ad7746: avoid overwrite of num_channels

In reply to Jonathan Cameron
Quoted 38 lines · Jonathan Cameron
Quoted 25 lines · On Wed, 12 May 2021 20:20:02 +0300 Alexandru Ardelean <[email protected]>…
Quoted 16 lines · Lucas Stankus

AD7745 devices don't have the CIN2 pins and therefore can't handle related channels. Forcing the number of AD7746 channels may lead to enabling more channels than what the hardware actually supports.
Avoid num_channels being overwritten after first assignment.

---
 drivers/staging/iio/cdc/ad7746.c | 1 -
 1 file changed, 1 deletion(-)
drivers/staging/iio/cdc/ad7746.c +0 -0
index e03d010b2f4c..9e0da43b2871 100644

drivers/staging/iio/cdc/ad7746.c static int ad7746_probe(struct i2c_client *client, · line 696

Quoted 4 lines
drivers/staging/iio/cdc/ad7746.c +0 -1
@@ -693,7 +693,6 @@ static int ad7746_probe(struct i2c_client *client,
                indio_dev->num_channels = ARRAY_SIZE(ad7746_channels);
        else
                indio_dev->num_channels =  ARRAY_SIZE(ad7746_channels) - 2;
-       indio_dev->num_channels = ARRAY_SIZE(ad7746_channels);

ohh; good catch

Quoted 8 lines

this falls into the category of a fix, so a Fixes tag is required; this looks so old, that i did not bother tracking it before 83e416f458d53 [which is 2011]

so, maybe something like:

Fixes 83e416f458d53 ("staging: iio: adc: Replace, rewrite ad7745 from

scratch.")

Quoted 8 lines

ouch. Given I was queuing up some fixes I've added this one to the fixes-togreg branch of iio.git and marked it for stable.

So drop this one from your v2 series with the changes requested in patch 1.

Thanks,

Jonathan

No problems, but I think I should've better checked the mailing list before sending the patch, it would have avoided the noise.

Anyway, thanks for the review :)

Quoted 9 lines
Quoted 8 lines
Quoted 8 lines
drivers/staging/iio/cdc/ad7746.c +0 -1
        indio_dev->modes = INDIO_DIRECT_MODE;
 
        if (pdata) {
--

2.31.1

#9 lore raw

Re: [PATCH 2/2] staging: iio: cdc: ad7746: avoid overwrite of num_channels

In reply to Alexandru Ardelean
Quoted 26 lines · Alexandru Ardelean
Quoted 16 lines · Lucas Stankus

AD7745 devices don't have the CIN2 pins and therefore can't handle related channels. Forcing the number of AD7746 channels may lead to enabling more channels than what the hardware actually supports.
Avoid num_channels being overwritten after first assignment.

---
 drivers/staging/iio/cdc/ad7746.c | 1 -
 1 file changed, 1 deletion(-)
drivers/staging/iio/cdc/ad7746.c +0 -0
index e03d010b2f4c..9e0da43b2871 100644

drivers/staging/iio/cdc/ad7746.c static int ad7746_probe(struct i2c_client *client, · line 696

Quoted 4 lines
drivers/staging/iio/cdc/ad7746.c +0 -1
@@ -693,7 +693,6 @@ static int ad7746_probe(struct i2c_client *client,
                indio_dev->num_channels = ARRAY_SIZE(ad7746_channels);
        else
                indio_dev->num_channels =  ARRAY_SIZE(ad7746_channels) - 2;
-       indio_dev->num_channels = ARRAY_SIZE(ad7746_channels);

ohh; good catch

Quoted 3 lines

this falls into the category of a fix, so a Fixes tag is required; this looks so old, that i did not bother tracking it before 83e416f458d53 [which is 2011]

As Jonathan said, this bug was already fixed and the patch will be dropped, but thank you for the review.

This was my first bug fix in the kernel, so sorry for the absence of a Fixes tag, I'll make sure to add one next time.

Quoted 12 lines

so, maybe something like:

Fixes 83e416f458d53 ("staging: iio: adc: Replace, rewrite ad7745 from

scratch.")

Quoted 6 lines
drivers/staging/iio/cdc/ad7746.c +0 -1
        indio_dev->modes = INDIO_DIRECT_MODE;
 
        if (pdata) {
--

2.31.1

#10 lore raw

Re: [PATCH 2/2] staging: iio: cdc: ad7746: avoid overwrite of num_channels

Quoted 32 lines · On Mon, 17 May 2021 21:55:20 -0300 Lucas Stankus <[email protected]>…
Quoted 26 lines · Alexandru Ardelean
Quoted 16 lines · Lucas Stankus

AD7745 devices don't have the CIN2 pins and therefore can't handle related channels. Forcing the number of AD7746 channels may lead to enabling more channels than what the hardware actually supports.
Avoid num_channels being overwritten after first assignment.

---
 drivers/staging/iio/cdc/ad7746.c | 1 -
 1 file changed, 1 deletion(-)
drivers/staging/iio/cdc/ad7746.c +0 -0
index e03d010b2f4c..9e0da43b2871 100644

drivers/staging/iio/cdc/ad7746.c static int ad7746_probe(struct i2c_client *client, · line 696

Quoted 4 lines
drivers/staging/iio/cdc/ad7746.c +0 -1
@@ -693,7 +693,6 @@ static int ad7746_probe(struct i2c_client *client,
                indio_dev->num_channels = ARRAY_SIZE(ad7746_channels);
        else
                indio_dev->num_channels =  ARRAY_SIZE(ad7746_channels) - 2;
-       indio_dev->num_channels = ARRAY_SIZE(ad7746_channels);  

ohh; good catch

Quoted 3 lines

this falls into the category of a fix, so a Fixes tag is required; this looks so old, that i did not bother tracking it before 83e416f458d53 [which is 2011]

Quoted 6 lines

As Jonathan said, this bug was already fixed and the patch will be dropped, but thank you for the review.

This was my first bug fix in the kernel, so sorry for the absence of a Fixes tag, I'll make sure to add one next time.

Wasn't already fixed - I just applied this patch without PATCH 1/2 so now it is ;)

Jonathan

Quoted 13 lines
Quoted 13 lines

so, maybe something like:

Fixes 83e416f458d53 ("staging: iio: adc: Replace, rewrite ad7745 from

scratch.")

Quoted 6 lines
drivers/staging/iio/cdc/ad7746.c +0 -1
        indio_dev->modes = INDIO_DIRECT_MODE;
 
        if (pdata) {
--

2.31.1