From patchwork Fri Jan 26 07:53:34 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhipeng Lu X-Patchwork-Id: 192445 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:e09d:b0:103:945f:af90 with SMTP id gm29csp534246dyb; Fri, 26 Jan 2024 01:08:04 -0800 (PST) X-Google-Smtp-Source: AGHT+IGaAKsar24EJNi+cgO461i/J/CjKeJU95XnW7BxL23Htei9pDKWPAGcs4xaHumjQpQvrn23 X-Received: by 2002:ad4:4d4e:0:b0:681:78d4:6be8 with SMTP id m14-20020ad44d4e000000b0068178d46be8mr806634qvm.43.1706260084104; Fri, 26 Jan 2024 01:08:04 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706260084; cv=pass; d=google.com; s=arc-20160816; b=hwXjZ/h1e7HQ/3kFjzqzgmBJsB9Y3VeUXeSKa8qgCsFUrFbe5A9FLRv4FeObfXRes2 +hbQzTjVBwcj+1GVVm5wMi+gf400f4yeWksjPEZgfJo+B6gRUXm2j7jZAALCjqIghuMe XouJo8Th7/0LH+98vrtZv5bjRSLer6++esF33EN4jFxy/qWSOfy2XrSu/6U3BTlvlT+z VgP3K1UQPlLOS11REvwrkQXAWwo2TL7yUPm65CK51RraqtQl9iENnhDExJ0bgVzux0f5 uVXdMNZW+7lwmTB6Izp0gtcX5l+cM9K7DhtDLVQF2TudSipSpS+BH1WsWWvdAOXHejyi BUrg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:message-id:date:subject:cc:to :from; bh=45rYne3JcC5TAxy8xJjWn20FyHjZR2LtpWn06C1IWbo=; fh=1k8bJyYj1ZgoB0pu+4d8ciLpd4OYBPTn9gQVHpIuEos=; b=eqtFjHhGG0k/V2p7BsPghSBG6yVpLILwzh5QtJAqXDA9I5DwaH9c6XUENe9ZW7EBok QG9mevu04EhghCM0WXDstelN9gYioFtd1CmxXYDrQeZo7hCcoSF6m61zH3/IPc74wSyR xsZH4+0+1ifTL8qmQkKOqDu1UBPJVr7JTM4egXGkM7nE0p4ocPJg8CdFleWaN4DlIYDY U1DvRR8ZdrwYVx9hROA557Oaczk4i9Fu2h3qUBRPLCZbeMX7Aia3gTlJxYTpDStS09ZO uEuTwsGhPhjXXM5NHMNsroBYnmyf1A/IKauYaELMhuFcyPhVxF81xkWrlhk8lfRpmyuQ WPhA== ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=zju.edu.cn); spf=pass (google.com: domain of linux-kernel+bounces-39730-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-39730-ouuuleilei=gmail.com@vger.kernel.org" Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id p5-20020ad45f45000000b006819bb6daf1si873172qvg.303.2024.01.26.01.08.03 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 26 Jan 2024 01:08:04 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-39730-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=zju.edu.cn); spf=pass (google.com: domain of linux-kernel+bounces-39730-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-39730-ouuuleilei=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id DDA0C1C25D96 for ; Fri, 26 Jan 2024 09:08:03 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id C549064CEC; Fri, 26 Jan 2024 07:58:13 +0000 (UTC) Received: from azure-sdnproxy.icoremail.net (azure-sdnproxy.icoremail.net [20.231.56.155]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 349EB8820; Fri, 26 Jan 2024 07:58:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=20.231.56.155 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706255892; cv=none; b=uWwFQ+UHxKrICE6YpEFUM8hRN/OJ/suRpPdzxU1E0PYYbSB7WOaFWOLT5lgyDAi2MKpsucoJ0Gds42q8hR59bg/5CXjdJmtlXAIlGcKkJHxQMOoXdZzFjlv9urKaj1UiiwhL8ZWat3HDDi+D2jj6ze5jl4JWnL9fQj2GkeFJSvI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706255892; c=relaxed/simple; bh=SC15Rb/PFemCDAqfyzo2GcqUMQvpP3E+9WLV00xHdyU=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version; b=jyKSlZLphiL747Xiwqd+EjaRQEv7pl4wUNgQOSe3WRVLhjsnLPDD3VUCQAR2VW5lEPsuqjCZ/70Em07K2N8d5djC83HLW6tUelSoqdFyzg1VKICu84pp24dOcfcribcoOlzM2cbYdUBTRBafp3nr+ltHtZexI6a/iU008pggZCw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=zju.edu.cn; spf=pass smtp.mailfrom=zju.edu.cn; arc=none smtp.client-ip=20.231.56.155 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=zju.edu.cn Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=zju.edu.cn Received: from luzhipeng.223.5.5.5 (unknown [39.174.92.167]) by mail-app2 (Coremail) with SMTP id by_KCgDnKKjuZbNl12bZAA--.20178S2; Fri, 26 Jan 2024 15:57:36 +0800 (CST) From: Zhipeng Lu To: alexious@zju.edu.cn Cc: Kalle Valo , "John W. Linville" , Marcelo Tosatti , libertas-dev@lists.infradead.org, linux-wireless@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH] libertas: fix some memleaks in lbs_allocate_cmd_buffer Date: Fri, 26 Jan 2024 15:53:34 +0800 Message-Id: <20240126075336.2825608-1-alexious@zju.edu.cn> X-Mailer: git-send-email 2.34.1 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-CM-TRANSID: by_KCgDnKKjuZbNl12bZAA--.20178S2 X-Coremail-Antispam: 1UD129KBjvJXoW7uF43Zr4kGF18XrW8Cr4Durg_yoW8Gw4fpF 4Ygr18Cr15Zr4vya9xJaykGas0ga1Fq347Ka1F9w1rur98Ar1Fvr1rWF1xZrsY9FWxJaya vrW2yr1UuF1kt3JanT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUkl14x267AKxVW8JVW5JwAFc2x0x2IEx4CE42xK8VAvwI8IcIk0 rVWrJVCq3wAFIxvE14AKwVWUJVWUGwA2ocxC64kIII0Yj41l84x0c7CEw4AK67xGY2AK02 1l84ACjcxK6xIIjxv20xvE14v26w1j6s0DM28EF7xvwVC0I7IYx2IY6xkF7I0E14v26rxl 6s0DM28EF7xvwVC2z280aVAFwI0_GcCE3s1l84ACjcxK6I8E87Iv6xkF7I0E14v26rxl6s 0DM2AIxVAIcxkEcVAq07x20xvEncxIr21l5I8CrVACY4xI64kE6c02F40Ex7xfMcIj6xII jxv20xvE14v26r1j6r18McIj6I8E87Iv67AKxVWUJVW8JwAm72CE4IkC6x0Yz7v_Jr0_Gr 1lF7xvr2IYc2Ij64vIr41lF7I21c0EjII2zVCS5cI20VAGYxC7MxkF7I0En4kS14v26r12 6r1DMxAIw28IcxkI7VAKI48JMxC20s026xCaFVCjc4AY6r1j6r4UMI8I3I0E5I8CrVAFwI 0_Jr0_Jr4lx2IqxVCjr7xvwVAFwI0_JrI_JrWlx4CE17CEb7AF67AKxVWUAVWUtwCIc40Y 0x0EwIxGrwCI42IY6xIIjxv20xvE14v26r1j6r1xMIIF0xvE2Ix0cI8IcVCY1x0267AKxV W8JVWxJwCI42IY6xAIw20EY4v20xvaj40_Jr0_JF4lIxAIcVC2z280aVAFwI0_Jr0_Gr1l IxAIcVC2z280aVCY1x0267AKxVW8JVW8JrUvcSsGvfC2KfnxnUUI43ZEXa7VUbSfO7UUUU U== X-CM-SenderInfo: qrsrjiarszq6lmxovvfxof0/ X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1789143373761664902 X-GMAIL-MSGID: 1789143373761664902 In the for statement of lbs_allocate_cmd_buffer, if the allocation of cmdarray[i].cmdbuf fails, both cmdarray and cmdarray[i].cmdbuf needs to be freed. Otherwise, there will be memleaks in lbs_allocate_cmd_buffer. Fixes: 876c9d3aeb98 ("[PATCH] Marvell Libertas 8388 802.11b/g USB driver") Signed-off-by: Zhipeng Lu --- drivers/net/wireless/marvell/libertas/cmd.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/drivers/net/wireless/marvell/libertas/cmd.c b/drivers/net/wireless/marvell/libertas/cmd.c index 104d2b6dc9af..5a525da434c2 100644 --- a/drivers/net/wireless/marvell/libertas/cmd.c +++ b/drivers/net/wireless/marvell/libertas/cmd.c @@ -1132,7 +1132,7 @@ int lbs_allocate_cmd_buffer(struct lbs_private *priv) if (!cmdarray[i].cmdbuf) { lbs_deb_host("ALLOC_CMD_BUF: ptempvirtualaddr is NULL\n"); ret = -1; - goto done; + goto free_cmd_array; } } @@ -1140,8 +1140,17 @@ int lbs_allocate_cmd_buffer(struct lbs_private *priv) init_waitqueue_head(&cmdarray[i].cmdwait_q); lbs_cleanup_and_insert_cmd(priv, &cmdarray[i]); } - ret = 0; + return 0; +free_cmd_array: + for (i = 0; i < LBS_NUM_CMD_BUFFERS; i++) { + if (cmdarray[i].cmdbuf) { + kfree(cmdarray[i].cmdbuf); + cmdarray[i].cmdbuf = NULL; + } + } + kfree(priv->cmd_array); + priv->cmd_array = NULL; done: return ret; }