Received: by 2002:ab2:6857:0:b0:1ef:ffd0:ce49 with SMTP id l23csp2369263lqp; Sun, 24 Mar 2024 16:10:42 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVy+0RPDEJ70ZOA3HUhdXIDpF5OqO6wpAXA85ik1Nv9WKoenjoxUz0hTJF6rH2kykaiPp0Qfu2jt8mQ0m/Ljl594IssV3lEn32oplXKaQ== X-Google-Smtp-Source: AGHT+IGYhHRvthl1z/t52dnZcVOIJ0eFP5oh7LcZ85FGB1D+Z6j0UH2UxljjeCx3wGlBzyawDyFf X-Received: by 2002:a17:906:a3ca:b0:a47:2011:11bb with SMTP id ca10-20020a170906a3ca00b00a47201111bbmr3641339ejb.27.1711321842469; Sun, 24 Mar 2024 16:10:42 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1711321842; cv=pass; d=google.com; s=arc-20160816; b=YgW77vpxoag9stB96kVsroF0rqWNwnjPiyJywkCJJPbMFMiPLKpwvhqgcxqRzMoYsn kov0W2DDiyylWjGOBCI5FCRNDmHt4isWi2nTkJ9Q4FjVC5tTSDxBB82cIYcUdp5T5+kI bBUxscy+fq98HH5SiwtSdIaq8o+JSrDo7cpkxOUi1cwVSHkDa0sPMfKJbVgmzAH4C0Bh vrlWyRPSpkXGXOY+ZzQ1SmRhO+VopApdX0N8y6FN5Vo33UDI2X7+kVwU6c5w7fISgEHh IiSGKVVAZDeEEWLWoRG74WPhf+k/DLBRLFsK7Zc2Vaz7F1mi8wCd99FwhLRdQzm8BR/p uoPQ== 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=S1wkW3xhfaEiVhGC7fBAnsvqKluVDPZ0H7RIyNh8iOVLsFX+lFwphLqjbxWzPVZsx0 oYhPO0AFnzNH8EcsGkIvqaL8V4JoWxISBlHI4wiN8tsrGbxge1ZUbsO5nl4M9WAU5yIx dqTp7FJ1A8HJlsqMIl2NSeLQBtf3AvVI7S8r+Lnm+uhZytrp/8aUHWJeuALB1V+Xs5dk 5hK75VhtNffWOaoIJAZvXRNzzbzE466VGRAYgXON2cJIOMPebeiDT5mqsidoK9q1Wvzn hb4SLEaRaVAMmATpd2W6s5Osim/Xco/wlR8FctgRoOswSBQRat2H90YrSiPzYsP0mjdB Q2Cw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=oa9nLK38; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-113034-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-113034-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. [147.75.80.249]) by mx.google.com with ESMTPS id me22-20020a170906aed600b00a469671a2eesi2084456ejb.515.2024.03.24.16.10.42 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 24 Mar 2024 16:10:42 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-113034-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=oa9nLK38; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-113034-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-113034-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 0F8B41F226F5 for ; Sun, 24 Mar 2024 23:09:06 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 25B3A50A6D; Sun, 24 Mar 2024 22:37:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="oa9nLK38" 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 33E3E13B789; Sun, 24 Mar 2024 22:37:24 +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=1711319844; cv=none; b=GFLgRTzPg3NORZXmpWW8xlz6BE4SLwZzYgAx7Ku13XwW17YdBjJDvTTlgYE/+fe4ChK2vLNQTWngFN7uW03iBIgYf7Y7u9xr2RnOLbZE5OBCR64KxHw6ZAcGpZoKlYLLCSdUthHvsIjkotNATCwLdBGvdn1VdkEmMEDO242noo0= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711319844; c=relaxed/simple; bh=RQrolhc/4neGjp94YqluMsQFQZd5V1OjoECo2SmYWsM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=RhZRJhFclxVlr+IcdsP1qAEYmfN44y6YPuYYYKyt78HNr/QvgGQvGkqbOSp46O1w1cFlSHc00ryXe0070vF7sV8XhEsvzZDzCXejEMhiw2nS5zK6bNK98XKn92/vMIe7lfUNtJM2BjBdigqp0ntq34TtuM4I1oGCt05TOJ7XQR0= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=oa9nLK38; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 73A0AC43399; Sun, 24 Mar 2024 22:37:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1711319844; bh=RQrolhc/4neGjp94YqluMsQFQZd5V1OjoECo2SmYWsM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=oa9nLK38Zy6K6uNyruhiS1s6AozBrf2ryei3juou4B+vNfJ1Ut9DQJX+14rAjHi4/ p1QUTKrrT+udefM6G3IYgBAqTeGuTUkt7uv1Brb5t+fjaZlbBU8fss5m/mvXN3sP6K dC8X71TcW9YO8cgJBF3nmr3/HQRDXkDVRrGiv+bDU2OuhuZPKDFKy3/liQrkNZ/cYJ yraEwaAYJKJ9pADpIGYL6wU9jz+Kpi/86cOVyfMAfRmQNdOOJjwHudcjHOxrLAst5x Oe9OJXbR1uJHWk5+8BuAlfdbLJ+DsS57VSOrWhdSbKxPgmIZrOUgX74Zj+gvu7UeUC lnh9FXdQQr7/A== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Zhipeng Lu , Kalle Valo , Sasha Levin Subject: [PATCH 6.8 147/715] wifi: libertas: fix some memleaks in lbs_allocate_cmd_buffer() Date: Sun, 24 Mar 2024 18:25:26 -0400 Message-ID: <20240324223455.1342824-148-sashal@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240324223455.1342824-1-sashal@kernel.org> References: <20240324223455.1342824-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