From patchwork Sat Oct 22 07:29:21 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 7769 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4242:0:0:0:0:0 with SMTP id s2csp1121046wrr; Sat, 22 Oct 2022 02:27:19 -0700 (PDT) X-Google-Smtp-Source: AMsMyM61kd3ksQagxbjb1zqUFMBMsLSGqUdU3zXjPWmw5jsyggclHDzhA8/bwJv85FTm5Yon8EDL X-Received: by 2002:a17:902:e5c9:b0:186:4f8a:d6a with SMTP id u9-20020a170902e5c900b001864f8a0d6amr20975254plf.150.1666430838852; Sat, 22 Oct 2022 02:27:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666430838; cv=none; d=google.com; s=arc-20160816; b=XpyyM3FFCf84Id8rxdovO6Mt8wFoAnyDFbupW14UaEXtpabuKSRhobOGW5s+YU3xLN UTGQq4ByZ2XoKgWG4eJpdQJ/ciP8lyBZYjcn2UdnHQrripmKvqsMMyPfwd/D5SGn+SKh zxSyCxFbtb2UYt/f0uzQ+CbeLMRwBKNYQGk0gDvewGGvLlDfj5eqAy1RutxP0Oxl/QLy SOeMD0stQaE+dJxvz2yZHyQmiKvx39mUjVZo5CaF2IMwBmlenijPk0k39RyuYGYO3LG2 h3r8x3TjwEP/Y/W6ZaFI6vqOmPp7+i862YqruJhjgeLClbcqr7NZx/HxqOTAFHZ4feuS jpKw== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=sWvH+VtmPoJG7mrgB6m66v6mI7zgSRonMny6Q5/Knok=; b=yHzG5R0WXbj1i4QvjAY9TBMDdPL6rsIFjoTJKd6SIQCym37MSeZQ6p38ZrkRMHW9r0 ZoiddSIc9Ptl1NogGAXahV8JH7YBa3q9TWyeknI5GNzLu1lyRc68uNLyE7gZPvM/Qgze g//QMuJKZ39q//RIDeLE7HCAoWx3lc1NNt5qlKeQmKzpVtwmWXC8c2RAdsIdVAq3BQec NUtA8xml/G/hJoOVWy6Bd2ZW9J//VrbJRpr+e7sbe/dKtvzyZjIUrcK0Um71IHCJJkrs dsqKaxO2x3xJ5k/nsNHKlAEtVaoKuSGdiGl9YpUMWiW8E8poNqH/hI22BiToa/miQ5KV Yp6Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=Y9KaCJvp; 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=linuxfoundation.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id j70-20020a638b49000000b0046ebcc1c65bsi4607536pge.739.2022.10.22.02.27.06; Sat, 22 Oct 2022 02:27:18 -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=@linuxfoundation.org header.s=korg header.b=Y9KaCJvp; 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=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235106AbiJVJDr (ORCPT + 99 others); Sat, 22 Oct 2022 05:03:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55652 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235133AbiJVJCx (ORCPT ); Sat, 22 Oct 2022 05:02:53 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 47B822F92A7; Sat, 22 Oct 2022 01:17:59 -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 BCBA0B82E46; Sat, 22 Oct 2022 08:06:35 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0AEDFC433C1; Sat, 22 Oct 2022 08:06:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1666425994; bh=lDR61PbfI7H5eQX4Ti6CnNOBp3xkPZ74M3x0TE5CuNE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Y9KaCJvpcKC9gVt6+b9W4cpRPq1pA+aoUmN6grNW75TJpBLWV80/EV7pWk6PK2Yhj 9WlV+ezBNj8mRcVoSUyxXWDvFYco+BWJk8hmsEvfwXZR7kVRLXCNuTLQSIazX0yNzQ f3C2r04zQXUs1AfxWb0v9OVU54bfvCF4bvzPUyuI= 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.19 682/717] staging: rtl8723bs: fix a potential memory leak in rtw_init_cmd_priv() Date: Sat, 22 Oct 2022 09:29:21 +0200 Message-Id: <20221022072528.637631891@linuxfoundation.org> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221022072415.034382448@linuxfoundation.org> References: <20221022072415.034382448@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 X-Spam-Status: No, score=-7.3 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1747379383254877641?= X-GMAIL-MSGID: =?utf-8?q?1747379383254877641?= 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);