* [PATCH net] net: pse-pd: pd692x0: Return fw_upload_err codes from firmware upload ops
@ 2026-11-19 17:10 Ian Rogers
2026-11-19 17:26 ` Kory Maincent
0 siblings, 1 reply; 2+ messages in thread
From: Ian Rogers @ 2026-11-19 17:10 UTC (permalink / raw)
To: Oleksij Rempel, Kory Maincent, Andrew Lunn, David S. Miller,
Eric Dumazet, Jakub Kicinski, Paolo Abeni
Cc: netdev, linux-kernel, llvm, Elkin Cruz, Ian Rogers
pd692x0_fw_reset() and pd692x0_fw_write() return negative errno values
from i2c_master_send() directly as enum fw_upload_err instead of
FW_UPLOAD_ERR_RW_ERROR, and pd692x0_fw_recv_resp() ignores negative
errors from its trailing i2c_master_recv(). When a negative errno is
propagated to the firmware upload core, fw_upload_error() rejects it
as >= FW_UPLOAD_ERR_MAX, logs an invalid error code message, and
reports "unknown-error" instead of "read-write-error" via sysfs.
Return FW_UPLOAD_ERR_RW_ERROR on I2C transfer failures and use
enum fw_upload_err consistently across the PD692x0 firmware upload
helpers.
Found via Clang -Wimplicit-int-enum-cast on an x86_64 allyesconfig
build. Verified by building drivers/net/pse-pd/pd692x0.o with LLVM=1
W=1 (-Werror) and -Wimplicit-int-enum-cast, and with a standalone C
reproducer; not runtime-tested on PD692x0 hardware.
Fixes: 9a9938451890 ("net: pse-pd: Add PD692x0 PSE controller driver")
Signed-off-by: Ian Rogers <irogers@google.com>
---
drivers/net/pse-pd/pd692x0.c | 81 ++++++++++++++++++------------------
1 file changed, 40 insertions(+), 41 deletions(-)
diff --git a/drivers/net/pse-pd/pd692x0.c b/drivers/net/pse-pd/pd692x0.c
index 7958f5741463..94a857eaa3de 100644
--- a/drivers/net/pse-pd/pd692x0.c
+++ b/drivers/net/pse-pd/pd692x0.c
@@ -1455,6 +1455,8 @@ pd692x0_fw_recv_resp(const struct i2c_client *client, unsigned long ms_timeout,
/* Read remaining characters */
ret = i2c_master_recv(client, fw_msg_buf + 1, msg_size - 1);
+ if (ret < 0)
+ return FW_UPLOAD_ERR_RW_ERROR;
if (strncmp(fw_msg_buf, msg_ok, msg_size)) {
dev_err(&client->dev,
"Wrong FW download process answer (%*pE)\n",
@@ -1465,9 +1467,10 @@ pd692x0_fw_recv_resp(const struct i2c_client *client, unsigned long ms_timeout,
return FW_UPLOAD_ERR_NONE;
}
-static int pd692x0_fw_write_line(const struct i2c_client *client,
- const char line[PD692X0_FW_LINE_MAX_SZ],
- const bool last_line)
+static enum fw_upload_err
+pd692x0_fw_write_line(const struct i2c_client *client,
+ const char line[PD692X0_FW_LINE_MAX_SZ],
+ const bool last_line)
{
int ret;
@@ -1478,19 +1481,12 @@ static int pd692x0_fw_write_line(const struct i2c_client *client,
line++;
}
- if (last_line) {
- ret = pd692x0_fw_recv_resp(client, 100, "TP\r\n",
- sizeof("TP\r\n") - 1);
- if (ret)
- return ret;
- } else {
- ret = pd692x0_fw_recv_resp(client, 100, "T*\r\n",
- sizeof("T*\r\n") - 1);
- if (ret)
- return ret;
- }
+ if (last_line)
+ return pd692x0_fw_recv_resp(client, 100, "TP\r\n",
+ sizeof("TP\r\n") - 1);
- return FW_UPLOAD_ERR_NONE;
+ return pd692x0_fw_recv_resp(client, 100, "T*\r\n",
+ sizeof("T*\r\n") - 1);
}
static enum fw_upload_err pd692x0_fw_reset(const struct i2c_client *client)
@@ -1506,7 +1502,7 @@ static enum fw_upload_err pd692x0_fw_reset(const struct i2c_client *client)
dev_err(&client->dev,
"Failed to reset the controller (%pe)\n",
ERR_PTR(ret));
- return ret;
+ return FW_UPLOAD_ERR_RW_ERROR;
}
timeout = msecs_to_jiffies(10000) + jiffies;
@@ -1545,6 +1541,7 @@ static enum fw_upload_err pd692x0_fw_prepare(struct fw_upload *fwl,
struct pd692x0_priv *priv = fwl->dd_handle;
const struct i2c_client *client = priv->client;
enum pd692x0_fw_state last_fw_state;
+ enum fw_upload_err err;
int ret;
priv->cancel_request = false;
@@ -1578,12 +1575,12 @@ static enum fw_upload_err pd692x0_fw_prepare(struct fw_upload *fwl,
}
}
- ret = pd692x0_fw_recv_resp(client, 100, "TPE\r\n", sizeof("TPE\r\n") - 1);
- if (ret)
+ err = pd692x0_fw_recv_resp(client, 100, "TPE\r\n", sizeof("TPE\r\n") - 1);
+ if (err)
goto err_out;
if (priv->cancel_request) {
- ret = FW_UPLOAD_ERR_CANCELED;
+ err = FW_UPLOAD_ERR_CANCELED;
goto err_out;
}
@@ -1592,7 +1589,7 @@ static enum fw_upload_err pd692x0_fw_prepare(struct fw_upload *fwl,
err_out:
pd692x0_fw_reset(priv->client);
priv->fw_state = last_fw_state;
- return ret;
+ return err;
}
static enum fw_upload_err pd692x0_fw_write(struct fw_upload *fwl,
@@ -1602,6 +1599,7 @@ static enum fw_upload_err pd692x0_fw_write(struct fw_upload *fwl,
struct pd692x0_priv *priv = fwl->dd_handle;
char line[PD692X0_FW_LINE_MAX_SZ];
const struct i2c_client *client;
+ enum fw_upload_err err;
int ret, i;
char cmd;
@@ -1618,17 +1616,17 @@ static enum fw_upload_err pd692x0_fw_write(struct fw_upload *fwl,
return FW_UPLOAD_ERR_RW_ERROR;
}
- ret = pd692x0_fw_recv_resp(client, 100, "TOE\r\n", sizeof("TOE\r\n") - 1);
- if (ret)
- return ret;
+ err = pd692x0_fw_recv_resp(client, 100, "TOE\r\n", sizeof("TOE\r\n") - 1);
+ if (err)
+ return err;
- ret = pd692x0_fw_recv_resp(client, 5000, "TE\r\n", sizeof("TE\r\n") - 1);
- if (ret)
+ err = pd692x0_fw_recv_resp(client, 5000, "TE\r\n", sizeof("TE\r\n") - 1);
+ if (err)
dev_warn(&client->dev,
"Failed to erase internal memory, however still try to write Firmware\n");
- ret = pd692x0_fw_recv_resp(client, 100, "TPE\r\n", sizeof("TPE\r\n") - 1);
- if (ret)
+ err = pd692x0_fw_recv_resp(client, 100, "TPE\r\n", sizeof("TPE\r\n") - 1);
+ if (err)
dev_warn(&client->dev,
"Failed to erase internal memory, however still try to write Firmware\n");
@@ -1642,18 +1640,18 @@ static enum fw_upload_err pd692x0_fw_write(struct fw_upload *fwl,
dev_err(&client->dev,
"Failed to boot programming mode (%pe)\n",
ERR_PTR(ret));
- return ret;
+ return FW_UPLOAD_ERR_RW_ERROR;
}
- ret = pd692x0_fw_recv_resp(client, 100, "TOP\r\n", sizeof("TOP\r\n") - 1);
- if (ret)
- return ret;
+ err = pd692x0_fw_recv_resp(client, 100, "TOP\r\n", sizeof("TOP\r\n") - 1);
+ if (err)
+ return err;
i = 0;
while (i < size) {
ret = pd692x0_fw_get_next_line(data, line, size - i);
if (ret < 0) {
- ret = FW_UPLOAD_ERR_FW_INVALID;
+ err = FW_UPLOAD_ERR_FW_INVALID;
goto err;
}
@@ -1662,17 +1660,17 @@ static enum fw_upload_err pd692x0_fw_write(struct fw_upload *fwl,
if (line[0] == 'S' && line[1] == '0') {
continue;
} else if (line[0] == 'S' && line[1] == '7') {
- ret = pd692x0_fw_write_line(client, line, true);
- if (ret)
+ err = pd692x0_fw_write_line(client, line, true);
+ if (err)
goto err;
} else {
- ret = pd692x0_fw_write_line(client, line, false);
- if (ret)
+ err = pd692x0_fw_write_line(client, line, false);
+ if (err)
goto err;
}
if (priv->cancel_request) {
- ret = FW_UPLOAD_ERR_CANCELED;
+ err = FW_UPLOAD_ERR_CANCELED;
goto err;
}
}
@@ -1685,7 +1683,7 @@ static enum fw_upload_err pd692x0_fw_write(struct fw_upload *fwl,
err:
strscpy_pad(line, "S7\r\n", sizeof(line));
pd692x0_fw_write_line(client, line, true);
- return ret;
+ return err;
}
static enum fw_upload_err pd692x0_fw_poll_complete(struct fw_upload *fwl)
@@ -1693,13 +1691,14 @@ static enum fw_upload_err pd692x0_fw_poll_complete(struct fw_upload *fwl)
struct pd692x0_priv *priv = fwl->dd_handle;
const struct i2c_client *client = priv->client;
struct pd692x0_msg_ver ver;
+ enum fw_upload_err err;
int ret;
priv->fw_state = PD692X0_FW_COMPLETE;
- ret = pd692x0_fw_reset(client);
- if (ret)
- return ret;
+ err = pd692x0_fw_reset(client);
+ if (err)
+ return err;
ver = pd692x0_get_sw_version(priv);
if (ver.maj_sw_ver < PD692X0_FW_MAJ_VER) {
--
2.56.1.708.g77570a6a1d-goog
^ permalink raw reply related [flat|nested] 2+ messages in thread* Re: [PATCH net] net: pse-pd: pd692x0: Return fw_upload_err codes from firmware upload ops
2026-11-19 17:10 [PATCH net] net: pse-pd: pd692x0: Return fw_upload_err codes from firmware upload ops Ian Rogers
@ 2026-11-19 17:26 ` Kory Maincent
0 siblings, 0 replies; 2+ messages in thread
From: Kory Maincent @ 2026-11-19 17:26 UTC (permalink / raw)
To: Ian Rogers, Oleksij Rempel, Andrew Lunn, David S. Miller,
Eric Dumazet, Jakub Kicinski, Paolo Abeni
Cc: netdev, linux-kernel, llvm, Elkin Cruz
On 11/19/26 18:10, Ian Rogers wrote:
> pd692x0_fw_reset() and pd692x0_fw_write() return negative errno values
> from i2c_master_send() directly as enum fw_upload_err instead of
> FW_UPLOAD_ERR_RW_ERROR, and pd692x0_fw_recv_resp() ignores negative
> errors from its trailing i2c_master_recv(). When a negative errno is
> propagated to the firmware upload core, fw_upload_error() rejects it
> as >= FW_UPLOAD_ERR_MAX, logs an invalid error code message, and
> reports "unknown-error" instead of "read-write-error" via sysfs.
>
> Return FW_UPLOAD_ERR_RW_ERROR on I2C transfer failures and use
> enum fw_upload_err consistently across the PD692x0 firmware upload
> helpers.
Please write a readable commit message with human hands.
> Found via Clang -Wimplicit-int-enum-cast on an x86_64 allyesconfig
> build. Verified by building drivers/net/pse-pd/pd692x0.o with LLVM=1
> W=1 (-Werror) and -Wimplicit-int-enum-cast, and with a standalone C
> reproducer; not runtime-tested on PD692x0 hardware.
>
> Fixes: 9a9938451890 ("net: pse-pd: Add PD692x0 PSE controller driver")
> Signed-off-by: Ian Rogers <irogers@google.com>
> ---
> drivers/net/pse-pd/pd692x0.c | 81 ++++++++++++++++++------------------
> 1 file changed, 40 insertions(+), 41 deletions(-)
>
> diff --git a/drivers/net/pse-pd/pd692x0.c b/drivers/net/pse-pd/pd692x0.c
> index 7958f5741463..94a857eaa3de 100644
> --- a/drivers/net/pse-pd/pd692x0.c
> +++ b/drivers/net/pse-pd/pd692x0.c
> @@ -1455,6 +1455,8 @@ pd692x0_fw_recv_resp(const struct i2c_client *client, unsigned long ms_timeout,
>
> /* Read remaining characters */
> ret = i2c_master_recv(client, fw_msg_buf + 1, msg_size - 1);
> + if (ret < 0)
> + return FW_UPLOAD_ERR_RW_ERROR;
> if (strncmp(fw_msg_buf, msg_ok, msg_size)) {
The error will be catch anyway by the string comparison. If you want to
add a check on ret then add another error message.
This is not a fix.
> dev_err(&client->dev,
> "Wrong FW download process answer (%*pE)\n",
> @@ -1465,9 +1467,10 @@ pd692x0_fw_recv_resp(const struct i2c_client *client, unsigned long ms_timeout,
> return FW_UPLOAD_ERR_NONE;
> }
>
> -static int pd692x0_fw_write_line(const struct i2c_client *client,
> - const char line[PD692X0_FW_LINE_MAX_SZ],
> - const bool last_line)
> +static enum fw_upload_err
> +pd692x0_fw_write_line(const struct i2c_client *client,
> + const char line[PD692X0_FW_LINE_MAX_SZ],
> + const bool last_line)
> {
> int ret;
>
> @@ -1478,19 +1481,12 @@ static int pd692x0_fw_write_line(const struct i2c_client *client,
> line++;
> }
>
> - if (last_line) {
> - ret = pd692x0_fw_recv_resp(client, 100, "TP\r\n",
> - sizeof("TP\r\n") - 1);
> - if (ret)
> - return ret;
> - } else {
> - ret = pd692x0_fw_recv_resp(client, 100, "T*\r\n",
> - sizeof("T*\r\n") - 1);
> - if (ret)
> - return ret;
> - }
> + if (last_line)
> + return pd692x0_fw_recv_resp(client, 100, "TP\r\n",
> + sizeof("TP\r\n") - 1);
>
> - return FW_UPLOAD_ERR_NONE;
> + return pd692x0_fw_recv_resp(client, 100, "T*\r\n",
> + sizeof("T*\r\n") - 1);
This is not a fix, just moving code around.
For the rest, FW_UPLOAD_ERR_NONE is similar to ret = 0 so there is no
real issue, only some type mismatch and I am not sure these changes
should land as a fix.
Regards
--
Köry Maincent, Bootlin
Embedded Linux and kernel engineering
https://bootlin.com
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-11-19 17:26 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-19 17:10 [PATCH net] net: pse-pd: pd692x0: Return fw_upload_err codes from firmware upload ops Ian Rogers
2026-11-19 17:26 ` Kory Maincent
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox