Skip to content

Commit 9144379

Browse files
Dan Carpenterrobertfoss
authored andcommitted
drm/bridge: nxp-ptn3460: fix i2c_master_send() error checking
The i2c_master_send/recv() functions return negative error codes or the number of bytes that were able to be sent/received. This code has two problems. 1) Instead of checking if all the bytes were sent or received, it checks that at least one byte was sent or received. 2) If there was a partial send/receive then we should return a negative error code but this code returns success. Fixes: a9fe713 ("drm/bridge: Add PTN3460 bridge driver") Cc: [email protected] Signed-off-by: Dan Carpenter <[email protected]> Reviewed-by: Robert Foss <[email protected]> Signed-off-by: Robert Foss <[email protected]> Link: https://patchwork.freedesktop.org/patch/msgid/[email protected]
1 parent f6d8a80 commit 9144379

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

drivers/gpu/drm/bridge/nxp-ptn3460.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -56,13 +56,13 @@ static int ptn3460_read_bytes(struct ptn3460_bridge *ptn_bridge, char addr,
5656
ret = i2c_master_send(ptn_bridge->client, &addr, 1);
5757
if (ret <= 0) {
5858
DRM_ERROR("Failed to send i2c command, ret=%d\n", ret);
59-
return ret;
59+
return ret ?: -EIO;
6060
}
6161

6262
ret = i2c_master_recv(ptn_bridge->client, buf, len);
63-
if (ret <= 0) {
63+
if (ret != len) {
6464
DRM_ERROR("Failed to recv i2c data, ret=%d\n", ret);
65-
return ret;
65+
return ret < 0 ? ret : -EIO;
6666
}
6767

6868
return 0;
@@ -78,9 +78,9 @@ static int ptn3460_write_byte(struct ptn3460_bridge *ptn_bridge, char addr,
7878
buf[1] = val;
7979

8080
ret = i2c_master_send(ptn_bridge->client, buf, ARRAY_SIZE(buf));
81-
if (ret <= 0) {
81+
if (ret != ARRAY_SIZE(buf)) {
8282
DRM_ERROR("Failed to send i2c command, ret=%d\n", ret);
83-
return ret;
83+
return ret < 0 ? ret : -EIO;
8484
}
8585

8686
return 0;

0 commit comments

Comments
 (0)