From patchwork Mon Oct 24 11:32:48 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 9175 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp458107wru; Mon, 24 Oct 2022 06:37:03 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4Z4+j8+W28tVtbWV6mMUOG+rYBcxNVWW/5Nk1zpa6b8oCqKHFVtaB1aVxingUyhP2x2LzM X-Received: by 2002:a17:90a:8048:b0:212:c605:522c with SMTP id e8-20020a17090a804800b00212c605522cmr23009784pjw.230.1666618623546; Mon, 24 Oct 2022 06:37:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666618623; cv=none; d=google.com; s=arc-20160816; b=QJpKfw2/sZ6IJe1A5amaTd7XB6ef8iCKV/kTEtnvISl4eujy/ahOCIbrDgKSIqv7y+ XhCsXMhUkJutufAv0G6cN1LASnvrX/bTv8YIc3Pm8cgcXfGChRQWRjsHaF990SXy8cd6 plFlxBqhuLzrxCxBKWkmaniliTS3949Omv9cp4wQHuT6BfIQIY3Q11loXHy7+gONigRg BJ8t3Me4i/KdNYTEDQWli2iTH2gUwS8tQE7iInNoRhhiCI5f4bdpLDYIbgxOHCj75a1z DKA0vRM9s3GedpxWC6DL+OQTSs0AH94aP5ZGQxajQp6afhUtM9wgQ00ZUlR9px2og3dl PAmw== 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=i7otV6XHcwHblpEht23/RIJ9EytwuxU6X/iWwn++BzE=; b=Tpz+vXYpY3FTgOE0TpAk0KDfxpS6tSrRdo01i0AXbksgZHVRDnT4l/RTyvLjeIg/u+ OgeL3aL/cnDJQ7YjCnFbTrXzd7eHPVd7h7wSQvjqx31EfgbXlJBx9shQmQK74BT7y2ky SDPtd7jqqkL9r6KThIN0mxdUzeaVh7Dq4HEQ3lRc2ZK++h/Vi31u1ptmqa42QGL4kNSE rWzWGxrnLh7RuSdcKRexVZ99Ve1fLV9wPNw7tODkFNb9lYCBIKxJkBFv68W2bcmpOVXA RJtZGOXlvqUnlsCdGq9NEEzdvnWL0nryfBm60ebB9fL6s5Zl3NqwXT9snrDmBXaPiZdW LjcQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=dI6qICXF; 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 k18-20020a170902ce1200b0017cca111726si36074432plg.432.2022.10.24.06.36.43; Mon, 24 Oct 2022 06:37:03 -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=dI6qICXF; 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 S232523AbiJXNcB (ORCPT + 99 others); Mon, 24 Oct 2022 09:32:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49936 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232727AbiJXN2x (ORCPT ); Mon, 24 Oct 2022 09:28:53 -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 0BEBFABD7A; Mon, 24 Oct 2022 05:32:23 -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 9D4C361330; Mon, 24 Oct 2022 12:32:08 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id B13A4C433D6; Mon, 24 Oct 2022 12:32:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1666614728; bh=AkOcEHZmdaA81I6y7tbCcNTRyBxYzqfv88yAdxAyoJ8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=dI6qICXFkzJKTaSQG0aFj5GUsculEWYO+g6X4mJuShMifMczjFBzfBe4Szb6zl5+Q BpEzW3aAc9Pw10Q9Y6UHwmpHRyNJFu53Ag7Yv7B04rFYoSdVZsMkxzOw5+xbQG10ev O1Vr75zesvztqhX5HG/p+zBCP36OWC5DLwiM5yDI= 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.10 371/390] staging: rtl8723bs: fix a potential memory leak in rtw_init_cmd_priv() Date: Mon, 24 Oct 2022 13:32:48 +0200 Message-Id: <20221024113038.819163549@linuxfoundation.org> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221024113022.510008560@linuxfoundation.org> References: <20221024113022.510008560@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?1747576290242232417?= X-GMAIL-MSGID: =?utf-8?q?1747576290242232417?= 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 2abe205e3453..cee05385f872 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); @@ -199,8 +195,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(_workitem * work);