Skip to contentSkip to conversation

platform/chrome: cros_ec_uart: fix negative type promoted to high

PATCH Applied Tzung-Bi Shih 5 participants 8 messages Jan 9, 2023 – Jan 18, 2023

Subsystems (3)
lore
Share & tools
lore

Tzung-Bi Shih

author maintainer
#0 lore raw

PATCH 1/1 platform/chrome: cros_ec_uart: fix negative type promoted to high

serdev_device_write_buf() returns negative numbers on errors. When the return value compares to unsigned integer len, it promotes to quite large positive number.

Fix it.

Fixes 04a8bdd135cc ("platform/chrome: cros_ec_uart: Add transport layer")

---
Reported in https://lore.kernel.org/chrome-platform/Y7fhw4S7Tb0GcHMF@kili/T/#u.

 drivers/platform/chrome/cros_ec_uart.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/platform/chrome/cros_ec_uart.c +3 -2
index 6916069f1599..788246559bbb 100644
@@ -149,9 +149,10 @@ static int cros_ec_uart_pkt_xfer(struct cros_ec_device *ec_dev,
 	resp->status = 0;
 
 	ret = serdev_device_write_buf(serdev, ec_dev->dout, len);
-	if (ret < len) {
+	if (ret < 0 || ret < len) {
 		dev_err(ec_dev->dev, "Unable to write data\n");
-		ret = -EIO;
+		if (ret >= 0)
+			ret = -EIO;
 		goto exit;
 	}
 
Signature · 1 line
2.39.0.314.g84b9a713c41-goog
#1 lore raw
Quoted 9 lines
    175         if (host_response->data_len > ec_msg->insize) {
    176                 dev_err(ec_dev->dev, "Resp too long (%d bytes, expected %d)\n",
    177                         host_response->data_len, ec_msg->insize);
    178                 ret = -ENOSPC;

ret = -EINVAL; (Unless you are discussing harddrives).

    179                 goto exit;
    180         }

The report also suggested modifying the return value if a response packet is too long.

author maintainer
#2 lore raw
Quoted 11 lines · Mark Hasemeyer
Quoted 9 lines
    175         if (host_response->data_len > ec_msg->insize) {
    176                 dev_err(ec_dev->dev, "Resp too long (%d bytes, expected %d)\n",
    177                         host_response->data_len, ec_msg->insize);
    178                 ret = -ENOSPC;

ret = -EINVAL; (Unless you are discussing harddrives).

    179                 goto exit;
    180         }

The report also suggested modifying the return value if a response packet is too long.

Replied on the original mail. Let's discuss the case there if possible.

author maintainer
#3 lore raw
In reply to Tzung-Bi Shih
Quoted 21 lines · Tzung-Bi Shih

serdev_device_write_buf() returns negative numbers on errors. When the return value compares to unsigned integer len, it promotes to quite large positive number.

Fix it.

Fixes 04a8bdd135cc ("platform/chrome: cros_ec_uart: Add transport layer")

---
Reported in https://lore.kernel.org/chrome-platform/Y7fhw4S7Tb0GcHMF@kili/T/#u.

 drivers/platform/chrome/cros_ec_uart.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/platform/chrome/cros_ec_uart.c +0 -0
index 6916069f1599..788246559bbb 100644
@@ -149,9 +149,10 @@ static int cros_ec_uart_pkt_xfer(struct cros_ec_device *ec_dev,
 	resp->status = 0;

drivers/platform/chrome/cros_ec_uart.c static int cros_ec_uart_pkt_xfer(struct cros_ec_device *ec_dev, · line 157

Quoted 10 lines
drivers/platform/chrome/cros_ec_uart.c +3 -2
 
 	ret = serdev_device_write_buf(serdev, ec_dev->dout, len);
-	if (ret < len) {
+	if (ret < 0 || ret < len) {
 		dev_err(ec_dev->dev, "Unable to write data\n");
-		ret = -EIO;
+		if (ret >= 0)
+			ret = -EIO;
 		goto exit;
 	}

Does this patch make sense to someone in the mailing list?

Reviewed-by
#4 lore raw
Quoted 23 lines · Tzung-Bi Shih
Quoted 22 lines · Tzung-Bi Shih

serdev_device_write_buf() returns negative numbers on errors. When the return value compares to unsigned integer len, it promotes to quite large positive number.

Fix it.

Fixes 04a8bdd135cc ("platform/chrome: cros_ec_uart: Add transport layer")

---
Reported in https://lore.kernel.org/chrome-platform/Y7fhw4S7Tb0GcHMF@kili/T/#u.

 drivers/platform/chrome/cros_ec_uart.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/platform/chrome/cros_ec_uart.c +0 -0
index 6916069f1599..788246559bbb 100644
@@ -149,9 +149,10 @@ static int cros_ec_uart_pkt_xfer(struct cros_ec_device *ec_dev,
 	resp->status = 0;
 
Quoted 11 lines

drivers/platform/chrome/cros_ec_uart.c static int cros_ec_uart_pkt_xfer(struct cros_ec_device *ec_dev, · line 157

Quoted 9 lines
drivers/platform/chrome/cros_ec_uart.c +3 -2
 	ret = serdev_device_write_buf(serdev, ec_dev->dout, len);
-	if (ret < len) {
+	if (ret < 0 || ret < len) {
 		dev_err(ec_dev->dev, "Unable to write data\n");
-		ret = -EIO;
+		if (ret >= 0)
+			ret = -EIO;
 		goto exit;
 	}

Does this patch make sense to someone in the mailing list?

Yeah. It looks fine.

regards,
dan carpenter

maintainer Reviewed-by on v1 1/1
#5 lore raw
In reply to Tzung-Bi Shih

Hi Tzung-Bi,

Quoted 10 lines · Tzung-Bi Shih

serdev_device_write_buf() returns negative numbers on errors. When the return value compares to unsigned integer len, it promotes to quite large positive number.

Fix it.

Fixes 04a8bdd135cc ("platform/chrome: cros_ec_uart: Add transport layer")
Quoted 26 lines

---
Reported in https://lore.kernel.org/chrome-platform/Y7fhw4S7Tb0GcHMF@kili/T/#u.

 drivers/platform/chrome/cros_ec_uart.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/platform/chrome/cros_ec_uart.c +3 -3
index 6916069f1599..788246559bbb 100644
@@ -149,9 +149,10 @@ static int cros_ec_uart_pkt_xfer(struct cros_ec_device *ec_dev,
        resp->status = 0;
 
        ret = serdev_device_write_buf(serdev, ec_dev->dout, len);
-       if (ret < len) {
+       if (ret < 0 || ret < len) {
                dev_err(ec_dev->dev, "Unable to write data\n");
-               ret = -EIO;
+               if (ret >= 0)
+                       ret = -EIO;
                goto exit;
        }
 
--

2.39.0.314.g84b9a713c41-goog

Signature · 7 lines
Benson Leung
Staff Software Engineer
Chrome OS Kernel
Google Inc.
[email protected]
Chromium OS Project
[email protected]
#6 lore raw
In reply to Tzung-Bi Shih
This patch was applied to chrome-platform/linux.git (for-kernelci) by Tzung-Bi Shih <[email protected]>:

Hello:

This patch was applied to chrome-platform/linux.git (for-kernelci) by Tzung-Bi Shih <[email protected]>:

Quoted 11 lines · On Mon, 9 Jan 2023 16:15:54 +0800 you wrote:

serdev_device_write_buf() returns negative numbers on errors. When the return value compares to unsigned integer len, it promotes to quite large positive number.

Fix it.

Fixes 04a8bdd135cc ("platform/chrome: cros_ec_uart: Add transport layer")

[...]

Here is the summary with links:
- platform/chrome: cros_ec_uart: fix negative type promoted to high

    https://git.kernel.org/chrome-platform/c/8bb233b27fb7

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html
#7 lore raw
In reply to Tzung-Bi Shih
This patch was applied to chrome-platform/linux.git (for-next) by Tzung-Bi Shih <[email protected]>:

Hello:

This patch was applied to chrome-platform/linux.git (for-next) by Tzung-Bi Shih <[email protected]>:

Quoted 11 lines · On Mon, 9 Jan 2023 16:15:54 +0800 you wrote:

serdev_device_write_buf() returns negative numbers on errors. When the return value compares to unsigned integer len, it promotes to quite large positive number.

Fix it.

Fixes 04a8bdd135cc ("platform/chrome: cros_ec_uart: Add transport layer")

[...]

Here is the summary with links:
- platform/chrome: cros_ec_uart: fix negative type promoted to high

    https://git.kernel.org/chrome-platform/c/8bb233b27fb7

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html