net: atlantic: fix overwritten return value in Aquantia driver
Subsystems (3)
PATCH v2 1/1 net: atlantic: fix overwritten return value in Aquantia driver
From: Tian Liu <[email protected]>
In hw_atl_utils.c and hw_atl_utils_fw2x.c, a return value is first assigned to err, but then later calls overwrite it unconditionally. As a result, any earlier failure is lost if the later call succeeds. This may cause the driver to proceed when it should have stopped.
This patch uses err |= instead of assignment, so that any earlier error is preserved even if later calls succeed. This is safe because all involved functions return standard negative error codes (e.g. -EIO, -ETIMEDOUT, etc). OR-ing such values does not convert them into success, and preserves the indication that an error occurred.
Changes in v2:
- Add full name in Signed-off-by
- Update subject to include [PATCH net v2]
- Add Fixes: tag
- Expand commit message to explain why OR-ing errors is safe
--- drivers/net/ethernet/aquantia/atlantic/hw_atl/hw_atl_utils.c | 2 +- .../net/ethernet/aquantia/atlantic/hw_atl/hw_atl_utils_fw2x.c | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-)
drivers/net/ethernet/aquantia/atlantic/hw_atl/hw_atl_utils.c +1 -1
@@ -492,7 +492,7 @@ static int hw_atl_utils_init_ucp(struct aq_hw_s *self, self, self->mbox_addr, self->mbox_addr !=0U , 1000U, 10000U); - err =readx_poll_timeout_atomic (aq_fw1x_rpc_get, self, + err |=readx_poll_timeout_atomic (aq_fw1x_rpc_get, self, self->rpc_addr, self->rpc_addr !=0U ,1000U ,100000U );
drivers/net/ethernet/aquantia/atlantic/hw_atl/hw_atl_utils_fw2x.c +2 -2
@@ -102,12 +102,12 @@ static int aq_fw2x_init(struct aq_hw_s *self) self->mbox_addr !=0U , 1000U, 10000U); - err =readx_poll_timeout_atomic (aq_fw2x_rpc_get, + err |=readx_poll_timeout_atomic (aq_fw2x_rpc_get, self, self->rpc_addr, self->rpc_addr !=0U ,1000U ,100000U ); - err =aq_fw2x_settings_get (self, &self->settings_addr); + err |=aq_fw2x_settings_get (self, &self->settings_addr);return err; }
Signature · 1 line
2.39.5 (Apple Git-154)
Quoted 5 lines
This patch uses
err |=instead of assignment, so that any earlier error is preserved even if later calls succeed. This is safe because all involved functions return standard negative error codes (e.g.-EIO,-ETIMEDOUT, etc). OR-ing such values does not convert them into success, and preserves the indication that an error occurred.
22 | 110 = 132 = ERFKILL
How easy will it be for somebody to debug that?
Andrew
Simon Horman
reviewerQuoted 9 lines · Andrew Lunn
Quoted 5 lines
This patch uses
err |=instead of assignment, so that any earlier error is preserved even if later calls succeed. This is safe because all involved functions return standard negative error codes (e.g.-EIO,-ETIMEDOUT, etc). OR-ing such values does not convert them into success, and preserves the indication that an error occurred.22 | 110 = 132 = ERFKILL
How easy will it be for somebody to debug that?
Hi Andrew and Tian,
I agree that this does not seem to be a good approach.
Looking over the code, it seems that we can just bail out if an error occurs. Returning error codes as they arise.
Does this seem reasonable to you?
drivers/net/ethernet/aquantia/atlantic/hw_atl/hw_atl_utils.c +3 -0
@@ -492,6 +492,9 @@ static int hw_atl_utils_init_ucp(struct aq_hw_s *self, self, self->mbox_addr, self->mbox_addr !=0U , 1000U, 10000U); +if (err) +return err; + err = readx_poll_timeout_atomic(aq_fw1x_rpc_get, self, self->rpc_addr, self->rpc_addr != 0U,
drivers/net/ethernet/aquantia/atlantic/hw_atl/hw_atl_utils_fw2x.c +4 -0
@@ -101,11 +101,15 @@ static int aq_fw2x_init(struct aq_hw_s *self) self, self->mbox_addr, self->mbox_addr !=0U , 1000U, 10000U); +if (err) +return err; err =readx_poll_timeout_atomic (aq_fw2x_rpc_get, self, self->rpc_addr, self->rpc_addr !=0U ,1000U ,100000U ); +if (err) +return err; err =aq_fw2x_settings_get (self, &self->settings_addr);
Simon Horman
reviewerQuoted 7 lines · Tian
From: Tian Liu <[email protected]>
In
hw_atl_utils.candhw_atl_utils_fw2x.c, a return value is first assigned toerr, but then later calls overwrite it unconditionally. As a result, any earlier failure is lost if the later call succeeds. This may cause the driver to proceed when it should have stopped.
Quoted 7 lines
This patch uses
err |=instead of assignment, so that any earlier error is preserved even if later calls succeed. This is safe because all involved functions return standard negative error codes (e.g.-EIO,-ETIMEDOUT, etc). OR-ing such values does not convert them into success, and preserves the indication that an error occurred.Fixes 6a7f2277313b4 ("net: aquantia: replace AQ_HW_WAIT_FOR with readx_poll_timeout_atomic")
nit: No blank line here
I do agree that the Fixes tag is correct in the case of hw_atl_utils_fw2x.c
But, in the case of hw_atl_utils.c, it seems to me that the correct Fixes tag would be as follows, because prior to this commit the value of err was not overwritten:
Given the different commits that are being fixed I would suggest splitting the patch into two, one per file that is being updated.
Quoted 2 lines
Signed-off-by Tian Liu <[email protected]>
...
Signature · 1 line
pw-bot: changes-requested
…
Quoted 1 line
This patch uses …
…
Quoted 3 lines
Signed-off-by Tian Liu <[email protected]>Changes in v2:
…
Quoted 1 line
---
Please move the marker line.
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/process/submitting-patches.rst?h=v6.16#n784
Regards,
Markus