Re: [PATCH] staging: rtl8712: check register_netdev() return value
From: Dan Carpenter
Date: Wed Dec 09 2020 - 12:47:28 EST
On Wed, Dec 09, 2020 at 11:01:24PM +0800, shaojie.dong@xxxxxxxxxxxxxxxx wrote:
> From: "shaojie.dong" <shaojie.dong@xxxxxxxxxxxxxxxx>
>
> Function register_netdev() can fail, so we should check it's return value
>
> Signed-off-by: shaojie.dong <shaojie.dong@xxxxxxxxxxxxxxxx>
> ---
> drivers/staging/rtl8712/hal_init.c | 5 ++++-
> 1 file changed, 4 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/staging/rtl8712/hal_init.c b/drivers/staging/rtl8712/hal_init.c
> index 715f1fe8b..38a3e3d44 100644
> --- a/drivers/staging/rtl8712/hal_init.c
> +++ b/drivers/staging/rtl8712/hal_init.c
> @@ -45,7 +45,10 @@ static void rtl871x_load_fw_cb(const struct firmware *firmware, void *context)
> }
> adapter->fw = firmware;
> /* firmware available - start netdev */
> - register_netdev(adapter->pnetdev);
> + if (register_netdev(adapter->pnetdev) != 0) {
> + netdev_err(adapter->pnetdev, "register_netdev() failed\n");
> + free_netdev(adapter->pnetdev);
> + }
This function should not be calling register_netdev(). What does that
have to do with firmware? It should also not free_netdev() because
that will just lead to a use after free in the caller.
regards,
dan carpenter
> complete(&adapter->rtl8712_fw_ready);
> }
>
> --
> 2.17.1
>
> _______________________________________________
> devel mailing list
> devel@xxxxxxxxxxxxxxxxxxxxxx
> http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel