From: Dan Carpenter <dan.carpenter@linaro.org>
To: Samasth Norway Ananda <samasth.norway.ananda@oracle.com>
Cc: gregkh@linuxfoundation.org, linux-staging@lists.linux.dev,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH 4/4] staging: rtl8723bs: check return value of rtw_wdev_alloc()
Date: Thu, 18 Dec 2025 10:12:41 +0300 [thread overview]
Message-ID: <aUOpadPIsbYr-yI0@stanley.mountain> (raw)
In-Reply-To: <20251218011414.1781294-5-samasth.norway.ananda@oracle.com>
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@oracle.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
next prev parent reply other threads:[~2025-12-18 7:12 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-12-18 1:14 [PATCH 0/4] staging: rtl8723bs: Fix error handling and memory Samasth Norway Ananda
2025-12-18 1:14 ` [PATCH 1/4] staging: rtl8723bs: fix firmware memory leak on error path Samasth Norway Ananda
2025-12-18 7:14 ` Dan Carpenter
2025-12-18 17:00 ` [External] : " samasth.norway.ananda
2025-12-18 1:14 ` [PATCH 2/4] staging: rtl8723bs: fix memory leak in rtw_cfg80211_inform_bss() Samasth Norway Ananda
2025-12-18 1:14 ` [PATCH 3/4] staging: rtl8723bs: add IS_ERR() check for kthread_run() Samasth Norway Ananda
2025-12-18 1:14 ` [PATCH 4/4] staging: rtl8723bs: check return value of rtw_wdev_alloc() Samasth Norway Ananda
2025-12-18 7:12 ` Dan Carpenter [this message]
2025-12-18 16:31 ` [External] : " samasth.norway.ananda
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=aUOpadPIsbYr-yI0@stanley.mountain \
--to=dan.carpenter@linaro.org \
--cc=gregkh@linuxfoundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-staging@lists.linux.dev \
--cc=samasth.norway.ananda@oracle.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.