From nobody Fri Dec 19 16:01:07 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 A54A2ECAAA1 for ; Mon, 24 Oct 2022 13:05:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235287AbiJXNFf (ORCPT ); Mon, 24 Oct 2022 09:05:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34800 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235039AbiJXNCo (ORCPT ); Mon, 24 Oct 2022 09:02:44 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 04F34402D0; Mon, 24 Oct 2022 05:20:12 -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 dfw.source.kernel.org (Postfix) with ESMTPS id 16F456121A; Mon, 24 Oct 2022 12:15:14 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 28E8BC433D6; Mon, 24 Oct 2022 12:15:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1666613713; bh=J5oKMssIsjmrgJfuo2UOL4CSllU/7RRHIsy23aCN6dg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Xdil3OZEiK12nJUFWcFmiKF5Z0PR0Iqnqx+cbkwmxKdWE0+J1LIRCATSHq393HtGB hJJZi8AHKjuLFle0qujFGaNi2OcOHPV2wkghT9SxQnsLtKdzdloC8ZWJXew5n0dCBv X4rJ9jVnL6kIa3f48X1/1mqWC+n7SqvBBRzZ4og4= 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.4 241/255] staging: rtl8723bs: fix a potential memory leak in rtw_init_cmd_priv() Date: Mon, 24 Oct 2022 13:32:31 +0200 Message-Id: <20221024113011.243886897@linuxfoundation.org> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221024113002.471093005@linuxfoundation.org> References: <20221024113002.471093005@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 8d93c2f26890..a82114de21a7 100644 --- a/drivers/staging/rtl8723bs/core/rtw_cmd.c +++ b/drivers/staging/rtl8723bs/core/rtw_cmd.c @@ -165,8 +165,6 @@ No irqsave is necessary. =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 @@ -178,18 +176,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); @@ -197,8 +193,8 @@ int rtw_init_cmd_priv(struct cmd_priv *pcmdpriv) pcmdpriv->cmd_issued_cnt =3D pcmdpriv->cmd_done_cnt =3D pcmdpriv->rsp_cnt= =3D 0; =20 mutex_init(&pcmdpriv->sctx_mutex); -exit: - return res; + + return 0; } =20 static void c2h_wk_callback(_workitem *work); --=20 2.35.1