Skip to contentSkip to conversation

lm90.c: fix checkpatch error

PATCH Applied Frans Meulenbroeks 3 participants 4 messages Jan 4, 2012 – Jan 5, 2012

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

PATCH 2/2 lm90.c: fix checkpatch error

---
 drivers/hwmon/lm90.c |   11 ++++++++---
 1 files changed, 8 insertions(+), 3 deletions(-)
drivers/hwmon/lm90.c +8 -3
index 615bc4f..36dcbc9 100644
@@ -388,9 +388,14 @@ static int lm90_read16(struct i2c_client *client, u8 regh, u8 regl, u16 *value)
 	 * we have to read the low byte again, and now we believe we have a
 	 * correct reading.
 	 */
-	if ((err = lm90_read_reg(client, regh, &oldh))
-	 || (err = lm90_read_reg(client, regl, &l))
-	 || (err = lm90_read_reg(client, regh, &newh)))
+	err = lm90_read_reg(client, regh, &oldh);
+	if (err)
+		return err;
+	err = lm90_read_reg(client, regl, &l);
+	if (err)
+		return err;
+	err = lm90_read_reg(client, regh, &newh);
+	if (err)
 		return err;
 	if (oldh != newh) {
 		err = lm90_read_reg(client, regl, &l);
Signature · 7 lines
1.7.8.1


_______________________________________________
lm-sensors mailing list
[email protected]
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors
#1 lore raw
Quoted 17 lines · Frans Meulenbroeks
---
 drivers/hwmon/lm90.c |   11 ++++++++---
 1 files changed, 8 insertions(+), 3 deletions(-)
drivers/hwmon/lm90.c +1 -3
index 615bc4f..36dcbc9 100644
@@ -388,9 +388,14 @@ static int lm90_read16(struct i2c_client *client, u8 regh, u8 regl, u16 *value)
 	 * we have to read the low byte again, and now we believe we have a
 	 * correct reading.
 	 */
-	if ((err = lm90_read_reg(client, regh, &oldh))
-	 || (err = lm90_read_reg(client, regl, &l))
-	 || (err = lm90_read_reg(client, regh, &newh)))
+	err = lm90_read_reg(client, regh, &oldh);

drivers/hwmon/lm90.c static int lm90_read16(struct i2c_client *client, u8 regh, u8 regl, u16 *value) · line 401

Quoted 10 lines
drivers/hwmon/lm90.c +7 -0
+	if (err)
+		return err;
+	err = lm90_read_reg(client, regl, &l);
+	if (err)
+		return err;
+	err = lm90_read_reg(client, regh, &newh);
+	if (err)
 		return err;
 	if (oldh != newh) {
 		err = lm90_read_reg(client, regl, &l);

Ah, we left those in for readability.

Guenter

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

#2 lore raw
In reply to Frans Meulenbroeks
Quoted 22 lines · Guenter Roeck
Quoted 21 lines · Frans Meulenbroeks
---
 drivers/hwmon/lm90.c |   11 ++++++++---
 1 files changed, 8 insertions(+), 3 deletions(-)
drivers/hwmon/lm90.c +5 -3
index 615bc4f..36dcbc9 100644
@@ -388,9 +388,14 @@ static int lm90_read16(struct i2c_client *client, u8 regh, u8 regl, u16 *value)
 	 * we have to read the low byte again, and now we believe we have a
 	 * correct reading.
 	 */
-	if ((err = lm90_read_reg(client, regh, &oldh))
-	 || (err = lm90_read_reg(client, regl, &l))
-	 || (err = lm90_read_reg(client, regh, &newh)))
+	err = lm90_read_reg(client, regh, &oldh);
+	if (err)
+		return err;
+	err = lm90_read_reg(client, regl, &l);
+	if (err)
Quoted 8 lines

drivers/hwmon/lm90.c static int lm90_read16(struct i2c_client *client, u8 regh, u8 regl, u16 *value) · line 401

Quoted 6 lines
drivers/hwmon/lm90.c +3 -0
+		return err;
+	err = lm90_read_reg(client, regh, &newh);
+	if (err)
 		return err;
 	if (oldh != newh) {
 		err = lm90_read_reg(client, regl, &l);

Ah, we left those in for readability.

Actually this is one of the things checkpatch complains about which I consider a false positive. There is really nothing wrong with the code above, it does the right thing with no risk of error. Its replacement, OTOH, is harder to read, and less efficient.

The check should either be improved to only complain in cases which are really wrong, or should be plain discarded if fixing it is not possible.

Signature · 6 lines
Jean Delvare

_______________________________________________
lm-sensors mailing list
[email protected]
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors
#3 lore raw
In reply to Frans Meulenbroeks
Quoted 32 lines · Jean Delvare
Quoted 22 lines · Guenter Roeck
Quoted 21 lines · Frans Meulenbroeks
---
 drivers/hwmon/lm90.c |   11 ++++++++---
 1 files changed, 8 insertions(+), 3 deletions(-)
drivers/hwmon/lm90.c +5 -3
index 615bc4f..36dcbc9 100644
@@ -388,9 +388,14 @@ static int lm90_read16(struct i2c_client *client, u8 regh, u8 regl, u16 *value)
 	 * we have to read the low byte again, and now we believe we have a
 	 * correct reading.
 	 */
-	if ((err = lm90_read_reg(client, regh, &oldh))
-	 || (err = lm90_read_reg(client, regl, &l))
-	 || (err = lm90_read_reg(client, regh, &newh)))
+	err = lm90_read_reg(client, regh, &oldh);
+	if (err)
+		return err;
+	err = lm90_read_reg(client, regl, &l);
+	if (err)
Quoted 8 lines

drivers/hwmon/lm90.c static int lm90_read16(struct i2c_client *client, u8 regh, u8 regl, u16 *value) · line 401

Quoted 6 lines
drivers/hwmon/lm90.c +3 -0
+		return err;
+	err = lm90_read_reg(client, regh, &newh);
+	if (err)
 		return err;
 	if (oldh != newh) {
 		err = lm90_read_reg(client, regl, &l);

Ah, we left those in for readability.

Quoted 8 lines

Actually this is one of the things checkpatch complains about which I consider a false positive. There is really nothing wrong with the code above, it does the right thing with no risk of error. Its replacement, OTOH, is harder to read, and less efficient.

The check should either be improved to only complain in cases which are really wrong, or should be plain discarded if fixing it is not possible.

Strictly speaking, it violates "Don't put multiple statements on a single line", at least for the first line, so I guess that would be arguable. But I agree, in the above case the "correct" way hurts readability.

Sad but true, while I personally like to use assignments in if statements outside the kernel, I have often seen people make a mess of it, so I can understand why it is frowned upon in the kernel.

Guenter

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