Received: by 2002:a05:6358:1087:b0:cb:c9d3:cd90 with SMTP id j7csp137939rwi; Wed, 12 Oct 2022 17:25:42 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5gqxMLH4Aba5MVhLH15xbtgFm3Ei1cYQZRx83eP/cy5KGDsF3dceWqeMRPwnpzpijDXmTk X-Received: by 2002:aa7:dbd2:0:b0:45c:97bb:4ae0 with SMTP id v18-20020aa7dbd2000000b0045c97bb4ae0mr7411885edt.417.1665620742740; Wed, 12 Oct 2022 17:25:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1665620742; cv=none; d=google.com; s=arc-20160816; b=gWPPZC5xWPRSc5cj8BXnkVV5lNdh1wvrvdrtEa1p6lRjPaWdSNZbJF/m/0t9wthnLS fXSthv9D3+5xTbAPYpGD4Qtyxp3L8oN2Fmlf09piaDY1WHjb63DQunP4iqVid/fODuny JGZR8jE9djraiyMuOm3tzGxGR4h6sdjFbx9GvG13ALlObr52Pcq+AqGEkFsdKkgeuojd JIFASSY5mEWc+Aq6zTPMHeJn5BdAHnQqjKyA8NOO48FHwanBLcG2RjEHfombZvaQzneW qaeNTNRhMas6bLJYWxBekA9mc9qFtHyqICanVimwTdHND3cxzrKF0ZLf2Xj2oVOqBvqZ ggzQ== 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=+m1MmEuKRQ5syAJJCiS3zwicx2Y3ox6mO7gFkMTUz4k=; b=bCdDkgaY4qtNI+wsm+Q0Qc5GxKj9cuM6jwdCBGqtB18aMnqZ77VjRLVa9tkxg64exy Q2+rxZwqSoLldUOv9DxTeNhP/qL1zo/cxABE2o5MQ4RovLPzpTL3klbib0YuckIPsdLG CMX4vdKitLgzFS9gl9Y7/L0/CSuT/rchM+GnTrIdM+9PazxDoJ8PWRaJa8dDvRJXKhq9 INFsHjho3OWb7Y9ghfw8fXno+B6/bCdjNpC3cy49+S3PsTnApMAF/qIKwEV3NbLkl/cP u/yV/a3cB63YH6dhPOmCTONOKBAEqhHBk9FGA5awzKrDRRnA5paLtSDqqAKNSpCSULjt ieFg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=AodJ2zsZ; 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 rn5-20020a170906d92500b0078ddff4b3absi4144088ejb.423.2022.10.12.17.25.16; Wed, 12 Oct 2022 17:25:42 -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=AodJ2zsZ; 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 S230328AbiJMAWo (ORCPT + 99 others); Wed, 12 Oct 2022 20:22:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39166 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230214AbiJMAV1 (ORCPT ); Wed, 12 Oct 2022 20:21:27 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8085B123458; Wed, 12 Oct 2022 17:18: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 5ECE8616B3; Thu, 13 Oct 2022 00:17:59 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 78D2BC433D6; Thu, 13 Oct 2022 00:17:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1665620278; bh=TZI+pygGR9VgAS6VCGq1EY8I+61HOj+ZEUc/tgiwZGI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=AodJ2zsZglDVLcKgEqPAolzGbVAchOKYYRQOnI+CBOi9kWm6bRWGjPd9YThurRAfo KLE7N3AJzmrDiSC6Mf96y5gbeykP/e4zbTlElLsbyDpPyGPvvZaFLbDBjG/2BNbu1O FdCwaXpO+iRtBYFCpr6X5uoFDs2kAa/DwgDegYZPu8xbmx5On6oeKXbnaAhwzS1DLQ ODTNNhxw8PeeNgA63mZcqn2rVvDrQChfDvkHH2JmVQ+T3xciDzhqxdPmt7r0lK6Klj DJSo0v/3A3quevdBKzaoS9qLMJegWCxxTl0uD5SgODTWEuKAdFfA3aplfVnlIJvr9V 3cAtZtGNVEo+w== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Xiaoke Wang , Philipp Hortmann , Greg Kroah-Hartman , Sasha Levin , Larry.Finger@lwfinger.net, phil@philpotter.co.uk, remckee0@gmail.com, martin@kaiser.cx, straube.linux@gmail.com, makvihas@gmail.com, linux-staging@lists.linux.dev Subject: [PATCH AUTOSEL 6.0 49/67] staging: r8188eu: fix a potential memory leak in rtw_init_cmd_priv() Date: Wed, 12 Oct 2022 20:15:30 -0400 Message-Id: <20221013001554.1892206-49-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 06bfdb6d889f57fe9ce7bd139ce278b68f3a59de ] In rtw_init_cmd_priv(), if `pcmdpriv->rsp_allocated_buf` is allocated in failure, then `pcmdpriv->cmd_allocated_buf` will not be properly released. Besides, considering there are only two error paths and the first one can directly return, we do not need to implicitly jump to the `exit` tag to execute the error handling code. 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. Tested-by: Philipp Hortmann # Edimax N150 Signed-off-by: Xiaoke Wang Link: https://lore.kernel.org/r/tencent_1B6AAE10471D4556788892F8FF3E4812F306@qq.com Signed-off-by: Greg Kroah-Hartman Signed-off-by: Sasha Levin --- drivers/staging/r8188eu/core/rtw_cmd.c | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/drivers/staging/r8188eu/core/rtw_cmd.c b/drivers/staging/r8188eu/core/rtw_cmd.c index 5b6a891b5d67..5eb1751a43ac 100644 --- a/drivers/staging/r8188eu/core/rtw_cmd.c +++ b/drivers/staging/r8188eu/core/rtw_cmd.c @@ -58,8 +58,6 @@ static int _rtw_enqueue_cmd(struct __queue *queue, struct cmd_obj *obj) u32 rtw_init_cmd_priv(struct cmd_priv *pcmdpriv) { - u32 res = _SUCCESS; - init_completion(&pcmdpriv->enqueue_cmd); /* sema_init(&(pcmdpriv->cmd_done_sema), 0); */ init_completion(&pcmdpriv->start_cmd_thread); @@ -74,27 +72,24 @@ u32 rtw_init_cmd_priv(struct cmd_priv *pcmdpriv) pcmdpriv->cmd_allocated_buf = kzalloc(MAX_CMDSZ + CMDBUFF_ALIGN_SZ, GFP_KERNEL); - if (!pcmdpriv->cmd_allocated_buf) { - res = _FAIL; - goto exit; - } + if (!pcmdpriv->cmd_allocated_buf) + return _FAIL; pcmdpriv->cmd_buf = pcmdpriv->cmd_allocated_buf + CMDBUFF_ALIGN_SZ - ((size_t)(pcmdpriv->cmd_allocated_buf) & (CMDBUFF_ALIGN_SZ - 1)); pcmdpriv->rsp_allocated_buf = kzalloc(MAX_RSPSZ + 4, GFP_KERNEL); if (!pcmdpriv->rsp_allocated_buf) { - res = _FAIL; - goto exit; + kfree(pcmdpriv->cmd_allocated_buf); + return _FAIL; } pcmdpriv->rsp_buf = pcmdpriv->rsp_allocated_buf + 4 - ((size_t)(pcmdpriv->rsp_allocated_buf) & 3); pcmdpriv->cmd_done_cnt = 0; pcmdpriv->rsp_cnt = 0; -exit: - return res; + return _SUCCESS; } u32 rtw_init_evt_priv(struct evt_priv *pevtpriv) -- 2.35.1