Received: by 2002:ab2:6857:0:b0:1ef:ffd0:ce49 with SMTP id l23csp2558522lqp; Mon, 25 Mar 2024 02:32:55 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCULKF2Oz8N1EDhxPXhvMVVny1yzI0zznyIQMcL+kuEm9xq8Z9eZTh8rRhlwMaOOpRYLHDv/mNDCOoBOnNtIMtrCmu46od+TpZmX1T7Q1w== X-Google-Smtp-Source: AGHT+IExU3sSKwo6HS6ixgPffSa5Ho3hHFaHaKuJGI7BEc2h5kQqTMKjngHXTWiAe1qYkjQt/K6I X-Received: by 2002:a17:906:3b09:b0:a46:65fd:969d with SMTP id g9-20020a1709063b0900b00a4665fd969dmr3755591ejf.71.1711359174869; Mon, 25 Mar 2024 02:32:54 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1711359174; cv=pass; d=google.com; s=arc-20160816; b=roEIM90mjZ1DI/zI01qM/BaopTA8SWtQ5ZrWuviaBaUzErbm3KehJ8gk19UVhxl8Tt SLSWWHCgqeIq3gmzLdxYwFXqXu5qK/K8hXJtW8lXdZ290bgibQJcgryPv3eYmfqlEqeC eJ0gkmdGRq6SSnjKj+GcxWfcCJiAb6ny9kc1121qMYQ+ZF7+EFN+1bJBdlW1z272UgJi D/BdvrLX1dydLTTy/JEU2LsyOfncrH2ZiszjHFHCnJe/cZ+1YnDcFTb9kOb8nhqtFv2g SyRz+I9gFf5VtZVTDvHGJOQp3P6Joip+PE7hPe/4jEMUbb71ebnwVN6LJ+3MbrNiIr0x oLiQ== 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:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=2Pjvui83w/k73bK4wGcn98bItJtoDWHxXc5imrjM3rI=; fh=Ab0VlCWRW8TlBeQ/1jUHacsvDan5c16GcQxBciNogyE=; b=Rtc/I2Lfrz+uwN5GJ0aXUdBbEDfJjeu/r+kFjuG4ibX6uFr+0CuFkp8xGBVNvCEIzf wjuuENOlTqtH15MkLGrE1q3VjO/Egjs92dnCjdhvmXtgjj2AtBbkLwgET+yRjzp+nxPX afvHYT7UvBOb8+cMnkI1+Jd8uME45cjVb80PwMEa5UedcZiaDm0EncnumJXYWkl/7LLu rKOzG8rwdZL1SE8kCw//pMZD51WKAztR51on/onUffK00XleD5AiQTf9lOBn/W4Maw9g AARvdDM1z7RhE+gDl0fQrEkfiDsJcJNgKvkBFU3f9J0DTDCYgH1DWeBvx4qbqCi69/kB lenA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=PDHCLKzN; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-115798-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-115798-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id j16-20020a170906475000b00a4752013ea5si1251064ejs.133.2024.03.25.02.32.54 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 Mar 2024 02:32:54 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-115798-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=PDHCLKzN; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-115798-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-115798-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=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 am.mirrors.kernel.org (Postfix) with ESMTPS id 77B1F1F383C6 for ; Mon, 25 Mar 2024 09:24:45 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id AEC7313C3C8; Mon, 25 Mar 2024 03:01:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="PDHCLKzN" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C1B4A535C9; Sun, 24 Mar 2024 23:14:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711322053; cv=none; b=Re/UeIcolsVm76BanwpNJTaASiMCKrkznYgSit69e1iymKoNsIKyOrcZRQUefF5/d+iSspK5f6tkGUVlr8wV2vrPa1bdjtSWiqV0eIwSshRlKX2UZ4/PWUtSzTfg6v2MKM1XGuVu/RDloiYRtwoC71Hd+xqTFfvpTrQeCxHOPBw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711322053; c=relaxed/simple; bh=RQrolhc/4neGjp94YqluMsQFQZd5V1OjoECo2SmYWsM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=S1PGlt5e8Rs7yACtYba1hz9llABqXqfahtH/587aEJ42LC+NS+qZoJ3xE2P/ri9d94AhbGLot2/M2T/Yso92mIoO1sgyj//AEYU8yYZr1NrrxL17TBOozJyOFLprXihbd4ryj6qUTh/X5QZuDX1PwJbJdtS4jWDCn0eIjeB7Iu8= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=PDHCLKzN; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 05AA6C433C7; Sun, 24 Mar 2024 23:14:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1711322053; bh=RQrolhc/4neGjp94YqluMsQFQZd5V1OjoECo2SmYWsM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=PDHCLKzNam0XTkhdRL1OAp+DHraP3kaFOLqUggHrUB5Rp5nuaK6w2wDf8dnHHGT3p jY/oSEZYlKK8MLaozjSnvq9/QcmQqaUqLZTYE7LADDQQiVqEuFKgJFmENdqHc5lHYt sXHgvHSnlcZbIe6CI9cYgHrDUnmfdIp9pZEMxJVTwhrYnOCKqGYKXZX9i+oQXo9KrI MRmbc5GwIgtHidTBB70eBLGd0TS39Jh4VUnVrS4ln5VqBlu6szWFrsA+BMZ9FNQM/x D/oVKEw5uHzsLSkRGtNZzS/EHJiGtk2eSzORT5Lr16MRxl4PPtGvitmkTUdhXxdIgJ BBp4ZNFNdyJ1Q== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Zhipeng Lu , Kalle Valo , Sasha Levin Subject: [PATCH 6.1 126/451] wifi: libertas: fix some memleaks in lbs_allocate_cmd_buffer() Date: Sun, 24 Mar 2024 19:06:42 -0400 Message-ID: <20240324231207.1351418-127-sashal@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240324231207.1351418-1-sashal@kernel.org> References: <20240324231207.1351418-1-sashal@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit From: Zhipeng Lu [ Upstream commit 5f0e4aede01cb01fa633171f0533affd25328c3a ] 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 Signed-off-by: Kalle Valo Link: https://msgid.link/20240126075336.2825608-1-alexious@zju.edu.cn Signed-off-by: Sasha Levin --- 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 104d2b6dc9af6..5a525da434c28 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; } -- 2.43.0