From patchwork Mon Oct 24 11:32:31 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 9032 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp441857wru; Mon, 24 Oct 2022 06:06:31 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7wayXB5UX9td5/XG3El3e1Rqvhl3/BRGiQCH6J+P5zB4L1rGh0jWXlqXjuFjhpO7xpkSak X-Received: by 2002:a65:44c1:0:b0:428:ab8f:62dd with SMTP id g1-20020a6544c1000000b00428ab8f62ddmr28281093pgs.211.1666616790884; Mon, 24 Oct 2022 06:06:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666616790; cv=none; d=google.com; s=arc-20160816; b=Fo8NmnaAoS0XNfcN8DHUAJa+maz2K5UldmFiVZR0P3agWTdGIlH8s7HCHE/8+N3J6N i8j59C3SjxkQt0QrQXSWBgnubyqYqT5z8IoVX1uUhRbC2PjFJoWbKS953OE4MgLenTIe s72YIeowsPv4liYpnc37eB0OMSNsN3KnC16OTDqwNZyK9oYySU8g2oO3GVt+lvYpT4jx ePBehprFcOV6CcepLdXAeqjNyOrd6iE9KJMmwRAlGUMfvTenHr4KQRYdZjAOm4EwPeKk q9SIQZFGAPlukwF/tbTryVHUjspF/uwbU5Hbu/4RkhSLX+vzi3rLkuCeJu4QtIhajNxe CWlA== 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=8ixqPW9EUk5BAAOtyPHG+sfrscueF7CAqOROxLnjjuI=; b=vQM0S8xkHqpVY02Kts+4RqNEYCHeV3U/hzvhDwdthnVvKvWfEr9SqmM+F8NNplB/+s JEds0CrBrKiwQzR2aT8jm9iyv33TKA4UtdCO/ZY20w9mIdoWO/Q52UxRzL5XrWx3mkKC pKJiN30Jo4S26wtt6rLx0o4W+4Qw5xWeJ3GjnlTpTDKQt9U56KtqaxWQvqbynzbJfk11 ZnQ4GEBIir+OPT8SauV7ladyoz9EDY9Qv7zvBzvLmdiYVyZ3JFH/5THBA+6D7lemy5Rk qXZOgor+vobJ3e8zUrJPHXRjD7mAb0bkPGOxzfGnwcWhuDN8jt4Nh00B1N/hQSiT/RV7 zvhA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=Xdil3OZE; 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 d10-20020a170902ceca00b00186b766d4a0si858967plg.325.2022.10.24.06.06.12; Mon, 24 Oct 2022 06:06:30 -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=Xdil3OZE; 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 S235319AbiJXNFe (ORCPT + 99 others); Mon, 24 Oct 2022 09:05:34 -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 X-Spam-Status: No, score=-7.6 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?1747574367747173924?= X-GMAIL-MSGID: =?utf-8?q?1747574367747173924?= 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 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. int rtw_init_cmd_priv(struct cmd_priv *pcmdpriv) { - int res = 0; - init_completion(&pcmdpriv->cmd_queue_comp); init_completion(&pcmdpriv->terminate_cmdthread_comp); @@ -178,18 +176,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); @@ -197,8 +193,8 @@ int rtw_init_cmd_priv(struct cmd_priv *pcmdpriv) pcmdpriv->cmd_issued_cnt = pcmdpriv->cmd_done_cnt = pcmdpriv->rsp_cnt = 0; mutex_init(&pcmdpriv->sctx_mutex); -exit: - return res; + + return 0; } static void c2h_wk_callback(_workitem *work);