Skip to contentSkip to conversation

hwmon: (ads1015) Use of_property_read_u32 at appropriate places

PATCH Applied Axel Lin 2 participants 4 messages Aug 5, 2014 Hardware monitoring

lore
Share & tools
lore

Axel Lin

author
#0 lore raw

PATCH v3 2/2 hwmon: (ads1015) Use of_property_read_u32 at appropriate places

Simplify the code a bit and also improve readability.

---
 drivers/hwmon/ads1015.c | 21 ++++++++-------------
 1 file changed, 8 insertions(+), 13 deletions(-)
drivers/hwmon/ads1015.c +8 -13
index 55030bd..b6c9fb4d 100644
@@ -184,20 +184,18 @@ static int ads1015_get_channels_config_of(struct i2c_client *client)
 		return -EINVAL;
 
 	for_each_child_of_node(client->dev.of_node, node) {
-		const __be32 *property;
-		int len;
+		u32 pval;
 		unsigned int channel;
 		unsigned int pga = ADS1015_DEFAULT_PGA;
 		unsigned int data_rate = ADS1015_DEFAULT_DATA_RATE;
 
-		property = of_get_property(node, "reg", &len);
-		if (!property || len != sizeof(int)) {
+		if (of_property_read_u32(node, "reg", &pval)) {
 			dev_err(&client->dev, "invalid reg on %s\n",
 				node->full_name);
 			continue;
 		}
 
-		channel = be32_to_cpup(property);
+		channel = pval;
 		if (channel > ADS1015_CHANNELS) {
 			dev_err(&client->dev,
 				"invalid channel index %d on %s\n",
@@ -205,20 +203,17 @@ static int ads1015_get_channels_config_of(struct i2c_client *client)
 			continue;
 		}
 
-		property = of_get_property(node, "ti,gain", &len);
-		if (property && len = sizeof(int)) {
-			pga = be32_to_cpup(property);
+		if (!of_property_read_u32(node, "ti,gain", &pval)) {
+			pga = pval;
 			if (pga > 6) {
-				dev_err(&client->dev,
-					"invalid gain on %s\n",
+				dev_err(&client->dev, "invalid gain on %s\n",
 					node->full_name);
 				return -EINVAL;
 			}
 		}
 
-		property = of_get_property(node, "ti,datarate", &len);
-		if (property && len = sizeof(int)) {
-			data_rate = be32_to_cpup(property);
+		if (!of_property_read_u32(node, "ti,datarate", &pval)) {
+			data_rate = pval;
 			if (data_rate > 7) {
 				dev_err(&client->dev,
 					"invalid data_rate on %s\n",
Signature · 9 lines
1.9.1




_______________________________________________
lm-sensors mailing list
[email protected]
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors
maintainer
#1 lore raw
Quoted 3 lines · Axel Lin

Simplify the code a bit and also improve readability.

Hi Axel,

Unfortunately, this patch does not apply for me. Looks like your branch is missing commit 56de1377 (hwmon: (ads1015) Fix off-by-one for valid channel index checking). Can you rebase your branch to make sure it is included ? The above patch should hopefully be in mainline in a day or so, but you should have it already (after all, it is one of your patches ;-).

Thanks,
Guenter

Quoted 49 lines
---
  drivers/hwmon/ads1015.c | 21 ++++++++-------------
  1 file changed, 8 insertions(+), 13 deletions(-)
drivers/hwmon/ads1015.c +6 -10
index 55030bd..b6c9fb4d 100644
@@ -184,20 +184,18 @@ static int ads1015_get_channels_config_of(struct i2c_client *client)
  		return -EINVAL;
 
  	for_each_child_of_node(client->dev.of_node, node) {
-		const __be32 *property;
-		int len;
+		u32 pval;
  		unsigned int channel;
  		unsigned int pga = ADS1015_DEFAULT_PGA;
  		unsigned int data_rate = ADS1015_DEFAULT_DATA_RATE;
 
-		property = of_get_property(node, "reg", &len);
-		if (!property || len != sizeof(int)) {
+		if (of_property_read_u32(node, "reg", &pval)) {
  			dev_err(&client->dev, "invalid reg on %s\n",
  				node->full_name);
  			continue;
  		}
 
-		channel = be32_to_cpup(property);
+		channel = pval;
  		if (channel > ADS1015_CHANNELS) {
  			dev_err(&client->dev,
  				"invalid channel index %d on %s\n",
@@ -205,20 +203,17 @@ static int ads1015_get_channels_config_of(struct i2c_client *client)
  			continue;
  		}
 
-		property = of_get_property(node, "ti,gain", &len);
-		if (property && len = sizeof(int)) {
-			pga = be32_to_cpup(property);
+		if (!of_property_read_u32(node, "ti,gain", &pval)) {
+			pga = pval;
  			if (pga > 6) {
-				dev_err(&client->dev,
-					"invalid gain on %s\n",
+				dev_err(&client->dev, "invalid gain on %s\n",
  					node->full_name);
  				return -EINVAL;
  			}

drivers/hwmon/ads1015.c static int ads1015_get_channels_config_of(struct i2c_client *client) · line 219

Quoted 10 lines
drivers/hwmon/ads1015.c +2 -3
  		}
 
-		property = of_get_property(node, "ti,datarate", &len);
-		if (property && len = sizeof(int)) {
-			data_rate = be32_to_cpup(property);
+		if (!of_property_read_u32(node, "ti,datarate", &pval)) {
+			data_rate = pval;
  			if (data_rate > 7) {
  				dev_err(&client->dev,
  					"invalid data_rate on %s\n",

_______________________________________________
lm-sensors mailing list
[email protected]
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors

author
#2 lore raw
In reply to Axel Lin

2014-08-05 10:49 GMT+08:00 Guenter Roeck <[email protected]>:

Quoted 9 lines · Axel Lin
Quoted 4 lines

Simplify the code a bit and also improve readability.

Hi Axel,

Quoted 9 lines

Unfortunately, this patch does not apply for me. Looks like your branch is missing
commit 56de1377 (hwmon: (ads1015) Fix off-by-one for valid channel index checking).
Can you rebase your branch to make sure it is included ? The above patch should
hopefully be in mainline in a day or so, but you should have it already (after all,
it is one of your patches ;-).

It's because I use linux-next tree.
And the commit 56de1377 (hwmon: (ads1015) Fix off-by-one for valid channel index checking is still
not in linux-next (20140804).

I'll resend this patch soon.

(Obviously, I need more coffee this morning..)
Thanks,
Axel

_______________________________________________
lm-sensors mailing list
[email protected]
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors

maintainer
#3 lore raw
In reply to Axel Lin
Quoted 19 lines · Axel Lin

2014-08-05 10:49 GMT+08:00 Guenter Roeck <[email protected]>:

Quoted 9 lines · Axel Lin
Quoted 4 lines

Simplify the code a bit and also improve readability.

Hi Axel,

Quoted 9 lines

Unfortunately, this patch does not apply for me. Looks like your branch is missing
commit 56de1377 (hwmon: (ads1015) Fix off-by-one for valid channel index checking).
Can you rebase your branch to make sure it is included ? The above patch should
hopefully be in mainline in a day or so, but you should have it already (after all,
it is one of your patches ;-).

Quoted 5 lines

It's because I use linux-next tree.
And the commit 56de1377 (hwmon: (ads1015) Fix off-by-one for valid channel index checking is still
not in linux-next (20140804).

Yeah, sorry. I missed to rebase my -next branch to my bug-fix branch last week, and only noticed this morning when I prepared my pull request. Vacation does that for you. I already got a ding on my head for it from Stephen, with copy to Linus :-(.

Guenter

_______________________________________________
lm-sensors mailing list
[email protected]
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors