Re: [PATCH] tg3: Check return value of tg3_nvram_lock before resetting lock
From: Michael Chan
Date: Tue Feb 11 2025 - 16:50:50 EST
On Tue, Feb 11, 2025 at 7:27 AM Wentao Liang <vulab@xxxxxxxxxxx> wrote:
>
> The current code does not check the return value of tg3_nvram_lock before
> resetting the lock count (tp->nvram_lock_cnt = 0). This is dangerous
> because if tg3_nvram_lock fails, the lock state may be inconsistent,
> leading to potential race conditions or undefined behavior.
>
> This patch adds a check for the return value of tg3_nvram_lock. If the
> function fails, the error is propagated to the caller, ensuring that
> the lock state remains consistent.
>
> Signed-off-by: Wentao Liang <vulab@xxxxxxxxxxx>
> ---
> drivers/net/ethernet/broadcom/tg3.c | 4 +++-
> 1 file changed, 3 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/net/ethernet/broadcom/tg3.c b/drivers/net/ethernet/broadcom/tg3.c
> index 9cc8db10a8d6..851d19b3f43c 100644
> --- a/drivers/net/ethernet/broadcom/tg3.c
> +++ b/drivers/net/ethernet/broadcom/tg3.c
> @@ -9160,7 +9160,9 @@ static int tg3_chip_reset(struct tg3 *tp)
> if (!pci_device_is_present(tp->pdev))
> return -ENODEV;
>
> - tg3_nvram_lock(tp);
> + err = tg3_nvram_lock(tp);
> + if (err)
> + return err;
It is correct not to check the return value here since we are about to
reset the chip. The nvram lock is a hardware arbitration lock that is
granted by the hardware. If the hardware is in a bad state, we may
not get the lock but we should still proceed to reset. A few lines
below this we reset the tp->nvram_lock_cnt to 0 so it is safe.
Attachment:
smime.p7s
Description: S/MIME Cryptographic Signature