Received: by 2002:a05:6358:1087:b0:cb:c9d3:cd90 with SMTP id j7csp166042rwi; Wed, 12 Oct 2022 17:58:17 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7eMO3rX5xqqBz/fqqOYDJLRnPWO7l2XXflBDSGP6U36SRRTiKVmzI0dlgIdjePZD/6CI79 X-Received: by 2002:aa7:cc8a:0:b0:45b:f851:2943 with SMTP id p10-20020aa7cc8a000000b0045bf8512943mr19805182edt.103.1665622697427; Wed, 12 Oct 2022 17:58:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1665622697; cv=none; d=google.com; s=arc-20160816; b=S6mlvEVKBeGvyFZy5qmrIgc9e2yNv1Etg0AGQm7surD/WJevla3BLK+lvjG2ngc0TJ 74aZqDMFx+GAwaiNu0C4+VjOQ2GSLgeL104OMFcI3GkAQcQzj6F6fTMmGPNEdVeZPBxp 3spYfWHfAjAw+y3ys8U1hRcYp+wzs4oR8F8gjcq8w2Y40cQZBswKntFS+we+Y6Fe1Nx3 iOrnz8SxUN1hDH3HucBSHzJTLRDLuyOHTKa8Yz7znHd06kA4N7DmCOCpTpEgTiyygKgB 7E/cT9K+mW2tfoeNKDtaHuXNp1LmruvNHHKP6TbML9cZqD3dWoqrkE7j3CXYtp60IwCb tpuw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=sWvH+VtmPoJG7mrgB6m66v6mI7zgSRonMny6Q5/Knok=; b=VoV5n2n5UyNeqxs6uZJSgrpr5/K6hPk1wFW7mVrGZmzUZk9uq9eLiGgzrJvPFC8ZcW Kh8637WcjDTNjgkPRnN6KIZ+xWIPskfB8rB/NZnoMf93PUjUU9i21p2TLZne7tpJ+D0E Wgjpd6tfLuCyOalpI9jyLNU8LMVfDS33EtmGIaPTpemu+MDx+MrVfaBksWF9n4SQIrvA jNG7O4lNgIrbCNivYh29OOAvPlgp1ZCjzS0GqUYn5Qm8Z+es59ibnYL6YGnBiLqVre0D AbK8yr+LNQTXxJxDLkGlmlMH4aVstDxlbzkUCKYV55+3Z8oxEn5lC4Lb4JS8UB0ezoph Jmeg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=susC5Eh3; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id b1-20020aa7c901000000b0044ecd80f257si14827421edt.603.2022.10.12.17.57.52; Wed, 12 Oct 2022 17:58:17 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=susC5Eh3; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229912AbiJMAUf (ORCPT + 99 others); Wed, 12 Oct 2022 20:20:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38384 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230109AbiJMATZ (ORCPT ); Wed, 12 Oct 2022 20:19:25 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 91FF4150481; Wed, 12 Oct 2022 17:17:48 -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 F1080B81CC6; Thu, 13 Oct 2022 00:17:43 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 851ECC433C1; Thu, 13 Oct 2022 00:17:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1665620262; bh=lDR61PbfI7H5eQX4Ti6CnNOBp3xkPZ74M3x0TE5CuNE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=susC5Eh3h+EK0DOVLM6pSm6071jesmvmuFKsR7MPN3mBxsoK3uqP0XlC9C0lIF/rT IO9NZ/UgfSnwdtPydEhjRocgx3jWCjSpIx0FBP8a9x59liIe4ubPt+JaEcHQgpooBC uz31mEQ1GAKWefpHVLiX7v5OhQmVnJtIXZDh7G9iP4AbxGQfgmRMmyW1Bve3jnFYVK lZmEhasAnuC1VhcdqGFu70UA3ln+Nq4VTLHKopKrSfvpFC+wvnl4M0HtjWFBp5Ui1Q sjGgRZFXLupvYpbHg3fskemASZRoiJwCM+DBui6+O1P3wimynQZWbaLT4An127TIGK Jn8lexKIs+yvg== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Xiaoke Wang , Greg Kroah-Hartman , Sasha Levin , kushalkothari285@gmail.com, namcaov@gmail.com, remckee0@gmail.com, jagathjog1996@gmail.com, saurav.girepunje@gmail.com, ebiederm@xmission.com, linux-staging@lists.linux.dev Subject: [PATCH AUTOSEL 6.0 46/67] staging: rtl8723bs: fix a potential memory leak in rtw_init_cmd_priv() Date: Wed, 12 Oct 2022 20:15:27 -0400 Message-Id: <20221013001554.1892206-46-sashal@kernel.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20221013001554.1892206-1-sashal@kernel.org> References: <20221013001554.1892206-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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_2B7931B79BA38E22205C5A09EFDF11E48805@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/rtl8723bs/core/rtw_cmd.c index b4170f64d118..03c2c66dbf66 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[] = { int rtw_init_cmd_priv(struct cmd_priv *pcmdpriv) { - int res = 0; - init_completion(&pcmdpriv->cmd_queue_comp); init_completion(&pcmdpriv->terminate_cmdthread_comp); @@ -175,18 +173,16 @@ int rtw_init_cmd_priv(struct cmd_priv *pcmdpriv) pcmdpriv->cmd_allocated_buf = rtw_zmalloc(MAX_CMDSZ + CMDBUFF_ALIGN_SZ); - if (!pcmdpriv->cmd_allocated_buf) { - res = -ENOMEM; - goto exit; - } + if (!pcmdpriv->cmd_allocated_buf) + return -ENOMEM; pcmdpriv->cmd_buf = pcmdpriv->cmd_allocated_buf + CMDBUFF_ALIGN_SZ - ((SIZE_PTR)(pcmdpriv->cmd_allocated_buf) & (CMDBUFF_ALIGN_SZ-1)); pcmdpriv->rsp_allocated_buf = rtw_zmalloc(MAX_RSPSZ + 4); if (!pcmdpriv->rsp_allocated_buf) { - res = -ENOMEM; - goto exit; + kfree(pcmdpriv->cmd_allocated_buf); + return -ENOMEM; } pcmdpriv->rsp_buf = pcmdpriv->rsp_allocated_buf + 4 - ((SIZE_PTR)(pcmdpriv->rsp_allocated_buf) & 3); @@ -196,8 +192,8 @@ int rtw_init_cmd_priv(struct cmd_priv *pcmdpriv) pcmdpriv->rsp_cnt = 0; mutex_init(&pcmdpriv->sctx_mutex); -exit: - return res; + + return 0; } static void c2h_wk_callback(struct work_struct *work); -- 2.35.1