[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <aUOpadPIsbYr-yI0@stanley.mountain>
Date: Thu, 18 Dec 2025 10:12:41 +0300
From: Dan Carpenter <dan.carpenter@...aro.org>
To: Samasth Norway Ananda <samasth.norway.ananda@...cle.com>
Cc: gregkh@...uxfoundation.org, linux-staging@...ts.linux.dev,
linux-kernel@...r.kernel.org
Subject: Re: [PATCH 4/4] staging: rtl8723bs: check return value of
rtw_wdev_alloc()
On Wed, Dec 17, 2025 at 05:14:14PM -0800, Samasth Norway Ananda wrote:
> Add missing error check for rtw_wdev_alloc() in rtw_sdio_if1_init().
>
> rtw_wdev_alloc() can fail with -ENOMEM when wiphy_new() or rtw_zmalloc()
> fails, or with other negative error codes when wiphy_register() fails.
> Without checking the return value, initialization continues even when
> wireless device allocation fails, potentially leaving the adapter in an
> inconsistent state.
>
> Jump to the error cleanup path when rtw_wdev_alloc() fails to ensure
> proper resource cleanup and prevent use of an incompletely initialized
> adapter.
>
> Signed-off-by: Samasth Norway Ananda <samasth.norway.ananda@...cle.com>
> ---
> drivers/staging/rtl8723bs/os_dep/sdio_intf.c | 3 ++-
> 1 file changed, 2 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/staging/rtl8723bs/os_dep/sdio_intf.c b/drivers/staging/rtl8723bs/os_dep/sdio_intf.c
> index 1d0239eef114..432bc6aa1d90 100644
> --- a/drivers/staging/rtl8723bs/os_dep/sdio_intf.c
> +++ b/drivers/staging/rtl8723bs/os_dep/sdio_intf.c
> @@ -296,7 +296,8 @@ static struct adapter *rtw_sdio_if1_init(struct dvobj_priv *dvobj, const struct
> if (rtw_init_drv_sw(padapter) == _FAIL)
This call to rtw_init_drv_sw() does a number of allocations.
> goto free_hal_data;
>
> - rtw_wdev_alloc(padapter, dvobj_to_dev(dvobj));
> + if (rtw_wdev_alloc(padapter, dvobj_to_dev(dvobj)))
> + goto free_hal_data;
So this goto should free them as well. I have a blog about how to
write cleanup code in a systematic way.
https://staticthinking.wordpress.com/2022/04/28/free-the-last-thing-style/
regards,
dan carpenter
Powered by blists - more mailing lists