[PATCH] net: atlantic: fix overwritten return value in Aquantia driver

Tian posted 1 patch 2 months, 1 week ago
There is a newer version of this series
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(-)
[PATCH] net: atlantic: fix overwritten return value in Aquantia driver
Posted by Tian 2 months, 1 week ago
From: tian <27392025k@gmail.com>

In hw_atl_utils.c and hw_atl_utils_fw2x.c, a return value is set and then
immediately overwritten by another call, which causes the original result
to be lost. This may hide errors that should be returned to the caller.

This patch fixes the logic to preserve the intended return values.

Signed-off-by: tian <27392025k@gmail.com>
---
 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(-)

diff --git a/drivers/net/ethernet/aquantia/atlantic/hw_atl/hw_atl_utils.c b/drivers/net/ethernet/aquantia/atlantic/hw_atl/hw_atl_utils.c
index 7e88d7234b14..372f30e296ec 100644
--- a/drivers/net/ethernet/aquantia/atlantic/hw_atl/hw_atl_utils.c
+++ b/drivers/net/ethernet/aquantia/atlantic/hw_atl/hw_atl_utils.c
@@ -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);
diff --git a/drivers/net/ethernet/aquantia/atlantic/hw_atl/hw_atl_utils_fw2x.c b/drivers/net/ethernet/aquantia/atlantic/hw_atl/hw_atl_utils_fw2x.c
index 4d4cfbc91e19..45b7720fd49e 100644
--- a/drivers/net/ethernet/aquantia/atlantic/hw_atl/hw_atl_utils_fw2x.c
+++ b/drivers/net/ethernet/aquantia/atlantic/hw_atl/hw_atl_utils_fw2x.c
@@ -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;
 }
-- 
2.39.5 (Apple Git-154)
Re: [PATCH] net: atlantic: fix overwritten return value in Aquantia driver
Posted by Andrew Lunn 2 months, 1 week ago
On Sun, Jul 27, 2025 at 04:17:50PM -0700, Tian wrote:
> From: tian <27392025k@gmail.com>
> 
> In hw_atl_utils.c and hw_atl_utils_fw2x.c, a return value is set and then
> immediately overwritten by another call, which causes the original result
> to be lost. This may hide errors that should be returned to the caller.
> 
> This patch fixes the logic to preserve the intended return values.

Please include in the commit message why it is safe to OR together two
error codes.

	Andrew
Re: [PATCH] net: atlantic: fix overwritten return value in Aquantia driver
Posted by Jason Xing 2 months, 1 week ago
Hi Tian,

On Mon, Jul 28, 2025 at 7:18 AM Tian <27392025k@gmail.com> wrote:
>
> From: tian <27392025k@gmail.com>
>
> In hw_atl_utils.c and hw_atl_utils_fw2x.c, a return value is set and then
> immediately overwritten by another call, which causes the original result
> to be lost. This may hide errors that should be returned to the caller.
>
> This patch fixes the logic to preserve the intended return values.
>
> Signed-off-by: tian <27392025k@gmail.com>

A few suggestions as to the format and should be revised in the next revision:
1. add your full name (given name, surname) on the above signed-off-by line
2. update the title like [patch net] to show which branch you're
targeting. Next version should be [patch net v2]
3. add Fixes: tag so that reviewers can easily know what problem you're solving.

As to the patch itself, could you show us more about the potential
race details? Like how it can be triggered, how 'err' value has
adverse effect, what the call traces could be?

Thanks,
Jason

> ---
>  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(-)
>
> diff --git a/drivers/net/ethernet/aquantia/atlantic/hw_atl/hw_atl_utils.c b/drivers/net/ethernet/aquantia/atlantic/hw_atl/hw_atl_utils.c
> index 7e88d7234b14..372f30e296ec 100644
> --- a/drivers/net/ethernet/aquantia/atlantic/hw_atl/hw_atl_utils.c
> +++ b/drivers/net/ethernet/aquantia/atlantic/hw_atl/hw_atl_utils.c
> @@ -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);
> diff --git a/drivers/net/ethernet/aquantia/atlantic/hw_atl/hw_atl_utils_fw2x.c b/drivers/net/ethernet/aquantia/atlantic/hw_atl/hw_atl_utils_fw2x.c
> index 4d4cfbc91e19..45b7720fd49e 100644
> --- a/drivers/net/ethernet/aquantia/atlantic/hw_atl/hw_atl_utils_fw2x.c
> +++ b/drivers/net/ethernet/aquantia/atlantic/hw_atl/hw_atl_utils_fw2x.c
> @@ -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;
>  }
> --
> 2.39.5 (Apple Git-154)
>
>