Skip to contentSkip to conversation

gpu/drm/bridge/sii9234: Use common error handling code in sii9234_writebm()

PATCH Superseded SF Markus Elfring 2 participants 4 messages Oct 22, 2017 – Oct 23, 2017

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

PATCH 1/1 gpu/drm/bridge/sii9234: Use common error handling code in sii9234_writebm()

From: Markus Elfring <[email protected]>
Date: Sun, 22 Oct 2017 21:21:44 +0200

* Add a jump target so that a bit of exception handling can be better reused at the end of this function.

This issue was detected by using the Coccinelle software.

* Adjust condition checks.

---
 drivers/gpu/drm/bridge/sii9234.c | 28 ++++++++++------------------
 1 file changed, 10 insertions(+), 18 deletions(-)
drivers/gpu/drm/bridge/sii9234.c +10 -18
index c77000626c22..fbdacdaf485c 100644
@@ -231,30 +231,22 @@ static int sii9234_writebm(struct sii9234 *ctx, int id, int offset,
 		return ctx->i2c_error;
 
 	ret = i2c_smbus_write_byte(client, offset);
-	if (ret < 0) {
-		dev_err(ctx->dev, "writebm: %4s[0x%02x] <- 0x%02x\n",
-			sii9234_client_name[id], offset, value);
-		ctx->i2c_error = ret;
-		return ret;
-	}
+	if (ret)
+		goto report_failure;
 
 	ret = i2c_smbus_read_byte(client);
-	if (ret < 0) {
-		dev_err(ctx->dev, "writebm: %4s[0x%02x] <- 0x%02x\n",
-			sii9234_client_name[id], offset, value);
-		ctx->i2c_error = ret;
-		return ret;
-	}
+	if (ret)
+		goto report_failure;
 
 	value = (value & mask) | (ret & ~mask);
-
 	ret = i2c_smbus_write_byte_data(client, offset, value);
-	if (ret < 0) {
-		dev_err(ctx->dev, "writebm: %4s[0x%02x] <- 0x%02x\n",
-			sii9234_client_name[id], offset, value);
-		ctx->i2c_error = ret;
-	}
+	if (!ret)
+		return 0;
 
+report_failure:
+	dev_err(ctx->dev, "writebm: %4s[0x%02x] <- 0x%02x\n",
+		sii9234_client_name[id], offset, value);
+	ctx->i2c_error = ret;
 	return ret;
 }
 
Signature · 1 line
2.14.2
#1 lore raw

PATCH v2 1/1 gpu/drm/bridge/sii9234: Use common error handling code in sii9234_writebm()

From: Markus Elfring <[email protected]>
Date: Sun, 22 Oct 2017 21:50:51 +0200

* Add a jump target so that a bit of exception handling can be better reused at the end of this function.

This issue was detected by using the Coccinelle software.

* Adjust condition checks.

---

v2:
The check for a negative error code was preserved after a call of the function "i2c_smbus_read_byte".

 drivers/gpu/drm/bridge/sii9234.c | 28 ++++++++++------------------
 1 file changed, 10 insertions(+), 18 deletions(-)
drivers/gpu/drm/bridge/sii9234.c +10 -18
index c77000626c22..4d8b2cc29378 100644
@@ -231,30 +231,22 @@ static int sii9234_writebm(struct sii9234 *ctx, int id, int offset,
 		return ctx->i2c_error;
 
 	ret = i2c_smbus_write_byte(client, offset);
-	if (ret < 0) {
-		dev_err(ctx->dev, "writebm: %4s[0x%02x] <- 0x%02x\n",
-			sii9234_client_name[id], offset, value);
-		ctx->i2c_error = ret;
-		return ret;
-	}
+	if (ret)
+		goto report_failure;
 
 	ret = i2c_smbus_read_byte(client);
-	if (ret < 0) {
-		dev_err(ctx->dev, "writebm: %4s[0x%02x] <- 0x%02x\n",
-			sii9234_client_name[id], offset, value);
-		ctx->i2c_error = ret;
-		return ret;
-	}
+	if (ret < 0)
+		goto report_failure;
 
 	value = (value & mask) | (ret & ~mask);
-
 	ret = i2c_smbus_write_byte_data(client, offset, value);
-	if (ret < 0) {
-		dev_err(ctx->dev, "writebm: %4s[0x%02x] <- 0x%02x\n",
-			sii9234_client_name[id], offset, value);
-		ctx->i2c_error = ret;
-	}
+	if (!ret)
+		return 0;
 
+report_failure:
+	dev_err(ctx->dev, "writebm: %4s[0x%02x] <- 0x%02x\n",
+		sii9234_client_name[id], offset, value);
+	ctx->i2c_error = ret;
 	return ret;
 }
 
Signature · 1 line
2.14.2
#2 lore raw
In reply to SF Markus Elfring
Quoted 42 lines · SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Sun, 22 Oct 2017 21:21:44 +0200

* Add a jump target so that a bit of exception handling can be better reused at the end of this function.

This issue was detected by using the Coccinelle software.

* Adjust condition checks.

---
 drivers/gpu/drm/bridge/sii9234.c | 28 ++++++++++------------------
 1 file changed, 10 insertions(+), 18 deletions(-)
drivers/gpu/drm/bridge/sii9234.c +4 -12
index c77000626c22..fbdacdaf485c 100644
@@ -231,30 +231,22 @@ static int sii9234_writebm(struct sii9234 *ctx, int id, int offset,
 		return ctx->i2c_error;
 
 	ret = i2c_smbus_write_byte(client, offset);
-	if (ret < 0) {
-		dev_err(ctx->dev, "writebm: %4s[0x%02x] <- 0x%02x\n",
-			sii9234_client_name[id], offset, value);
-		ctx->i2c_error = ret;
-		return ret;
-	}
+	if (ret)
+		goto report_failure;
 
 	ret = i2c_smbus_read_byte(client);
-	if (ret < 0) {
-		dev_err(ctx->dev, "writebm: %4s[0x%02x] <- 0x%02x\n",
-			sii9234_client_name[id], offset, value);
-		ctx->i2c_error = ret;
-		return ret;
-	}
+	if (ret)
+		goto report_failure;
 

drivers/gpu/drm/bridge/sii9234.c static int sii9234_writebm(struct sii9234 *ctx, int id, int offset, · line 244

Quoted 10 lines
drivers/gpu/drm/bridge/sii9234.c +2 -6
 	value = (value & mask) | (ret & ~mask);
-
 	ret = i2c_smbus_write_byte_data(client, offset, value);
-	if (ret < 0) {
-		dev_err(ctx->dev, "writebm: %4s[0x%02x] <- 0x%02x\n",
-			sii9234_client_name[id], offset, value);
-		ctx->i2c_error = ret;
-	}
+	if (!ret)
+		return 0;

Ugh. No. Don't do success handling on the last if statement. Also while I personally prefer testing for non-zero, the ALSA people got annoyed at you for changing tests for < 0 but you're doing it again. And it introduces a bug, although I see now that you fixed it in v2.

I can't get excited about these sort of risky low value patches.

drivers/gpu/drm/bridge/sii9234.c static int sii9234_writebm(struct sii9234 *ctx, int id, int offset, · line 251

Quoted 7 lines
drivers/gpu/drm/bridge/sii9234.c +4 -0
+report_failure:
+	dev_err(ctx->dev, "writebm: %4s[0x%02x] <- 0x%02x\n",
+		sii9234_client_name[id], offset, value);
+	ctx->i2c_error = ret;
 	return ret;
 }

regards,
dan carpenter

#3 lore raw
Quoted 10 lines

drivers/gpu/drm/bridge/sii9234.c static int sii9234_writebm(struct sii9234 *ctx, int id, int offset, · line 244

Quoted 8 lines
drivers/gpu/drm/bridge/sii9234.c +2 -5
 	ret = i2c_smbus_write_byte_data(client, offset, value);
-	if (ret < 0) {
-		dev_err(ctx->dev, "writebm: %4s[0x%02x] <- 0x%02x\n",
-			sii9234_client_name[id], offset, value);
-		ctx->i2c_error = ret;
-	}
+	if (!ret)
+		return 0;

Ugh. No. Don't do success handling on the last if statement.

I find my approach useful in this case.

Quoted 1 line

Also while I personally prefer testing for non-zero,

I got used to this checking style to some degree.

Quoted 1 line

the ALSA people got annoyed at you for changing tests for < 0

It seems that involved software developers have got special preferences there.

Quoted 1 line

but you're doing it again.

I dared to propose such an adjustment once more. Would you like discuss corresponding reasons any further?

Quoted 1 line

And it introduces a bug,

Unfortunately, a hiccup in my software development attention …

Quoted 1 line

although I see now that you fixed it in v2.

Thanks that you noticed also this small update.

https://patchwork.kernel.org/patch/10021767/
https://lkml.kernel.org/r/<[email protected]>

Quoted 1 line

I can't get excited about these sort of risky low value patches.

I try again to point special software improvement opportunities out.

Quoted 6 lines

drivers/gpu/drm/bridge/sii9234.c static int sii9234_writebm(struct sii9234 *ctx, int id, int offset, · line 251

Quoted 6 lines
drivers/gpu/drm/bridge/sii9234.c +4 -0
+report_failure:
+	dev_err(ctx->dev, "writebm: %4s[0x%02x] <- 0x%02x\n",
+		sii9234_client_name[id], offset, value);
+	ctx->i2c_error = ret;
 	return ret;
 }

How do you think about to move this source code to the end of this function implementation?

Regards,
Markus