* [PATCH] drm/bridge: nxp-ptn3460: simplify some error checking
@ 2023-12-06 15:05 Dan Carpenter
2023-12-06 15:49 ` Robert Foss
0 siblings, 1 reply; 2+ messages in thread
From: Dan Carpenter @ 2023-12-06 15:05 UTC (permalink / raw)
To: Dan Carpenter
Cc: Maxime Ripard, Neil Armstrong, Robert Foss, Thomas Zimmermann,
Jonas Karlman, kernel-janitors, dri-devel, linux-kernel,
Jernej Skrabec, Laurent Pinchart, Andrzej Hajda
The i2c_master_send/recv() functions return negative error codes or
they return "len" on success. So the error handling here can be written
as just normal checks for "if (ret < 0) return ret;". No need to
complicate things.
Btw, in this code the "len" parameter can never be zero, but even if
it were, then I feel like this would still be the best way to write it.
Fixes: 914437992876 ("drm/bridge: nxp-ptn3460: fix i2c_master_send() error checking")
Signed-off-by: Dan Carpenter <dan.carpenter@linaro.org>
---
This is not really a bug fix but I added a Fixes tag because I don't
want people to pull my other commit without also applying this.
drivers/gpu/drm/bridge/nxp-ptn3460.c | 12 ++++++------
1 file changed, 6 insertions(+), 6 deletions(-)
diff --git a/drivers/gpu/drm/bridge/nxp-ptn3460.c b/drivers/gpu/drm/bridge/nxp-ptn3460.c
index 9b7eb8c669c1..7c0076e49953 100644
--- a/drivers/gpu/drm/bridge/nxp-ptn3460.c
+++ b/drivers/gpu/drm/bridge/nxp-ptn3460.c
@@ -54,15 +54,15 @@ static int ptn3460_read_bytes(struct ptn3460_bridge *ptn_bridge, char addr,
int ret;
ret = i2c_master_send(ptn_bridge->client, &addr, 1);
- if (ret <= 0) {
+ if (ret < 0) {
DRM_ERROR("Failed to send i2c command, ret=%d\n", ret);
- return ret ?: -EIO;
+ return ret;
}
ret = i2c_master_recv(ptn_bridge->client, buf, len);
- if (ret != len) {
+ if (ret < 0) {
DRM_ERROR("Failed to recv i2c data, ret=%d\n", ret);
- return ret < 0 ? ret : -EIO;
+ return ret;
}
return 0;
@@ -78,9 +78,9 @@ static int ptn3460_write_byte(struct ptn3460_bridge *ptn_bridge, char addr,
buf[1] = val;
ret = i2c_master_send(ptn_bridge->client, buf, ARRAY_SIZE(buf));
- if (ret != ARRAY_SIZE(buf)) {
+ if (ret < 0) {
DRM_ERROR("Failed to send i2c command, ret=%d\n", ret);
- return ret < 0 ? ret : -EIO;
+ return ret;
}
return 0;
--
2.42.0
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] drm/bridge: nxp-ptn3460: simplify some error checking
2023-12-06 15:05 [PATCH] drm/bridge: nxp-ptn3460: simplify some error checking Dan Carpenter
@ 2023-12-06 15:49 ` Robert Foss
0 siblings, 0 replies; 2+ messages in thread
From: Robert Foss @ 2023-12-06 15:49 UTC (permalink / raw)
To: Dan Carpenter
Cc: Neil Armstrong, Robert Foss, Jonas Karlman, kernel-janitors,
dri-devel, linux-kernel, Jernej Skrabec, Andrzej Hajda,
Maxime Ripard, Thomas Zimmermann, Laurent Pinchart
On Wed, 6 Dec 2023 18:05:15 +0300, Dan Carpenter wrote:
> The i2c_master_send/recv() functions return negative error codes or
> they return "len" on success. So the error handling here can be written
> as just normal checks for "if (ret < 0) return ret;". No need to
> complicate things.
>
> Btw, in this code the "len" parameter can never be zero, but even if
> it were, then I feel like this would still be the best way to write it.
>
> [...]
Added suggested by tag, to reflect Neils feedback.
Applied, thanks!
[1/1] drm/bridge: nxp-ptn3460: simplify some error checking
https://cgit.freedesktop.org/drm/drm-misc/commit/?id=28d3d0696688
Rob
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2023-12-06 15:49 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-12-06 15:05 [PATCH] drm/bridge: nxp-ptn3460: simplify some error checking Dan Carpenter
2023-12-06 15:49 ` Robert Foss
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).