From nobody Fri Dec 19 04:15:06 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9D714ECAAA1 for ; Mon, 24 Oct 2022 16:56:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231311AbiJXQ4L (ORCPT ); Mon, 24 Oct 2022 12:56:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35108 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235062AbiJXQs7 (ORCPT ); Mon, 24 Oct 2022 12:48:59 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8B02733A3E; Mon, 24 Oct 2022 08:31:52 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 5604FB8171A; Mon, 24 Oct 2022 12:56:27 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id A2832C433C1; Mon, 24 Oct 2022 12:56:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1666616186; bh=wOSjVS5ufd6jL4mvjWSRUAPxuM5WwHpWoGZeXiaNzDs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=HVEcwKbykBKJFojp4SdRaU2M6etEFbTB35vVoWm5AxdAahxOU/e4OqfvnBqJ65LDP OFL0c3vlxZtSr1Tn3tcJh0B0oJZlstUilw70TcHm7N3pRvkPk9+RGxPC/f/wujmZce B0LUPe+OksNSVCEfr0v3qNFRg3Gw87AfIx9KykLg= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Xiaoke Wang , Sasha Levin Subject: [PATCH 5.15 502/530] staging: rtl8723bs: fix a potential memory leak in rtw_init_cmd_priv() Date: Mon, 24 Oct 2022 13:34:06 +0200 Message-Id: <20221024113107.766651995@linuxfoundation.org> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221024113044.976326639@linuxfoundation.org> References: <20221024113044.976326639@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Xiaoke Wang [ Upstream commit 708056fba733a73d926772ea4ce9a42d240345da ] In rtw_init_cmd_priv(), if `pcmdpriv->rsp_allocated_buf` is allocated in failure, then `pcmdpriv->cmd_allocated_buf` will be not properly released. Besides, considering there are only two error paths and the first one can directly return, so we do not need implicitly jump to the `exit` tag to execute the error handler. So this patch added `kfree(pcmdpriv->cmd_allocated_buf);` on the error path to release the resource and simplified the return logic of rtw_init_cmd_priv(). As there is no proper device to test with, no runtime testing was performed. Signed-off-by: Xiaoke Wang Link: https://lore.kernel.org/r/tencent_2B7931B79BA38E22205C5A09EFDF11E4880= 5@qq.com Signed-off-by: Greg Kroah-Hartman Signed-off-by: Sasha Levin --- drivers/staging/rtl8723bs/core/rtw_cmd.c | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/drivers/staging/rtl8723bs/core/rtw_cmd.c b/drivers/staging/rtl= 8723bs/core/rtw_cmd.c index d494c06dab96..93e3a4c9e115 100644 --- a/drivers/staging/rtl8723bs/core/rtw_cmd.c +++ b/drivers/staging/rtl8723bs/core/rtw_cmd.c @@ -161,8 +161,6 @@ static struct cmd_hdl wlancmds[] =3D { =20 int rtw_init_cmd_priv(struct cmd_priv *pcmdpriv) { - int res =3D 0; - init_completion(&pcmdpriv->cmd_queue_comp); init_completion(&pcmdpriv->terminate_cmdthread_comp); =20 @@ -174,18 +172,16 @@ int rtw_init_cmd_priv(struct cmd_priv *pcmdpriv) =20 pcmdpriv->cmd_allocated_buf =3D rtw_zmalloc(MAX_CMDSZ + CMDBUFF_ALIGN_SZ); =20 - if (!pcmdpriv->cmd_allocated_buf) { - res =3D -ENOMEM; - goto exit; - } + if (!pcmdpriv->cmd_allocated_buf) + return -ENOMEM; =20 pcmdpriv->cmd_buf =3D pcmdpriv->cmd_allocated_buf + CMDBUFF_ALIGN_SZ - = ((SIZE_PTR)(pcmdpriv->cmd_allocated_buf) & (CMDBUFF_ALIGN_SZ-1)); =20 pcmdpriv->rsp_allocated_buf =3D rtw_zmalloc(MAX_RSPSZ + 4); =20 if (!pcmdpriv->rsp_allocated_buf) { - res =3D -ENOMEM; - goto exit; + kfree(pcmdpriv->cmd_allocated_buf); + return -ENOMEM; } =20 pcmdpriv->rsp_buf =3D pcmdpriv->rsp_allocated_buf + 4 - ((SIZE_PTR)(pcm= dpriv->rsp_allocated_buf) & 3); @@ -195,8 +191,8 @@ int rtw_init_cmd_priv(struct cmd_priv *pcmdpriv) pcmdpriv->rsp_cnt =3D 0; =20 mutex_init(&pcmdpriv->sctx_mutex); -exit: - return res; + + return 0; } =20 static void c2h_wk_callback(struct work_struct *work); --=20 2.35.1