net: pse-pd: pd692x0: Return fw_upload_err codes from firmware upload ops
Subsystems (3)
PATCH 1/1 net: pse-pd: pd692x0: Return fw_upload_err codes from firmware upload ops
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.
--- drivers/net/pse-pd/pd692x0.c | 81 ++++++++++++++++++------------------ 1 file changed, 40 insertions(+), 41 deletions(-)
drivers/net/pse-pd/pd692x0.c +40 -41
@@ -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 ) {
Signature · 1 line
2.56.1.708.g77570a6a1d-goog
Kory Maincent
maintainerQuoted 11 lines · Ian Rogers
pd692x0_fw_reset()andpd692x0_fw_write()return negative errno values fromi2c_master_send()directly as enumfw_upload_errinstead ofFW_UPLOAD_ERR_RW_ERROR, andpd692x0_fw_recv_resp()ignores negative errors from its trailingi2c_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_ERRORon I2C transfer failures and use enumfw_upload_errconsistently across the PD692x0 firmware upload helpers.
Please write a readable commit message with human hands.
Quoted 16 lines
Found via Clang -Wimplicit-int-enum-cast on an
x86_64allyesconfig build. Verified by buildingdrivers/net/pse-pd/pd692x0.owith 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 <[email protected]>--- drivers/net/pse-pd/pd692x0.c | 81 ++++++++++++++++++------------------ 1 file changed, 40 insertions(+), 41 deletions(-)drivers/net/pse-pd/pd692x0.c +0
-0
drivers/net/pse-pd/pd692x0.c pd692x0_fw_recv_resp(const struct i2c_client *client, unsigned long ms_timeout, · line 1460
Quoted 6 lines
drivers/net/pse-pd/pd692x0.c +2
-0@@ -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.
Quoted 28 lines
drivers/net/pse-pd/pd692x0.c +4
-11dev_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 );
drivers/net/pse-pd/pd692x0.c static int pd692x0_fw_write_line(const struct i2c_client *client, · line 1489
Quoted 10 lines
drivers/net/pse-pd/pd692x0.c +5
-4-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
Signature · 3 lines
Köry Maincent, Bootlin Embedded Linux and kernel engineering https://bootlin.com
Quoted 86 lines · Kory Maincent
Quoted 11 lines · Ian Rogers
pd692x0_fw_reset()andpd692x0_fw_write()return negative errno values fromi2c_master_send()directly as enumfw_upload_errinstead ofFW_UPLOAD_ERR_RW_ERROR, andpd692x0_fw_recv_resp()ignores negative errors from its trailingi2c_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_ERRORon I2C transfer failures and use enumfw_upload_errconsistently across the PD692x0 firmware upload helpers.Please write a readable commit message with human hands.
Quoted 16 lines
Found via Clang -Wimplicit-int-enum-cast on an
x86_64allyesconfig build. Verified by buildingdrivers/net/pse-pd/pd692x0.owith 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 <[email protected]>--- drivers/net/pse-pd/pd692x0.c | 81 ++++++++++++++++++------------------ 1 file changed, 40 insertions(+), 41 deletions(-)drivers/net/pse-pd/pd692x0.c +0
-0drivers/net/pse-pd/pd692x0.c pd692x0_fw_recv_resp(const struct i2c_client *client, unsigned long ms_timeout, · line 1460
Quoted 6 lines
drivers/net/pse-pd/pd692x0.c +2
-0@@ -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.Quoted 28 lines
drivers/net/pse-pd/pd692x0.c +4
-11dev_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 );drivers/net/pse-pd/pd692x0.c static int pd692x0_fw_write_line(const struct i2c_client *client, · line 1489
Quoted 10 lines
drivers/net/pse-pd/pd692x0.c +5
-4-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.
Quoted 3 lines
For the rest,
FW_UPLOAD_ERR_NONEis 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.
Sorry for the noisy diff and dense commit message - you are right that pd692x0_fw_recv_resp() (where fw_msg_buf is zero-initialized) and pd692x0_fw_write_line() didn't need touching, and all that type churn buried the actual change.
The only two lines that return a negative errno (-EIO) as an enum fw_upload_err instead of FW_UPLOAD_ERR_RW_ERROR are:
1. pd692x0_fw_reset(): 'return ret;' when sending "RST" fails
2. pd692x0_fw_write(): 'return ret;' when sending 'P' fails (whereas
sending 'E' right above it already returns FW_UPLOAD_ERR_RW_ERROR)
Would you welcome a minimal 2-line patch for net-next (without Fixes:) just changing those two returns to FW_UPLOAD_ERR_RW_ERROR, or would you prefer leaving it as-is?
Thanks,
Ian
Quoted 6 lines
Regards
--
Köry Maincent, Bootlin
Embedded Linux and kernel engineering
https://bootlin.com