From mboxrd@z Thu Jan 1 00:00:00 1970 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 0876D7B for ; Thu, 13 Oct 2022 00:22:15 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 00F56C433D6; Thu, 13 Oct 2022 00:22:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1665620534; bh=PvMNHfj+xOpKajWvSAMJbsgU6pcBuW1U4TElzx+IlaE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=kR6/UFFXyMm1LsHGiGOO6rMrKj8jz9I2RpYXLw5DfLz2NV4nxHqDe0dT87eXzEwjp 96DAWIooxiRXftHRRbvsn+DDL8PeAf3gtt0CIufCQ5wnT1XzCrAx/rrAwKb6Yt8WPt EvqkfENbHgq7Xzo2/gDEP7S2uSEZ5zmTw7FqAFVlL0U0oQBZEr/FOQk27v+TnNp0ac 6tqLCmNFhB7bnx3pxO0eYr/tJ3BH5cJcurGKhRv1fEh3xd0o59YD7EL4xT5xmlO8r6 YgygQqMuUbkq0TsQhDfkrSvizR6uGcbUmoCUGuJ/K1rwoU8KSBPNVIJ9dbR4ZlIVBf 2+/77jF7YoJVg== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Nam Cao , Philipp Hortmann , Greg Kroah-Hartman , Sasha Levin , forest@alittletooquiet.net, tomm.merciai@gmail.com, linux-staging@lists.linux.dev Subject: [PATCH AUTOSEL 5.15 14/47] staging: vt6655: fix potential memory leak Date: Wed, 12 Oct 2022 20:20:49 -0400 Message-Id: <20221013002124.1894077-14-sashal@kernel.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20221013002124.1894077-1-sashal@kernel.org> References: <20221013002124.1894077-1-sashal@kernel.org> Precedence: bulk X-Mailing-List: linux-staging@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit From: Nam Cao [ Upstream commit c8ff91535880d41b49699b3829fb6151942de29e ] In function device_init_td0_ring, memory is allocated for member td_info of priv->apTD0Rings[i], with i increasing from 0. In case of allocation failure, the memory is freed in reversed order, with i decreasing to 0. However, the case i=0 is left out and thus memory is leaked. Modify the memory freeing loop to include the case i=0. Tested-by: Philipp Hortmann Signed-off-by: Nam Cao Link: https://lore.kernel.org/r/20220909141338.19343-1-namcaov@gmail.com Signed-off-by: Greg Kroah-Hartman Signed-off-by: Sasha Levin --- drivers/staging/vt6655/device_main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/staging/vt6655/device_main.c b/drivers/staging/vt6655/device_main.c index d40c2ac14928..f6cd1971bcdb 100644 --- a/drivers/staging/vt6655/device_main.c +++ b/drivers/staging/vt6655/device_main.c @@ -676,7 +676,7 @@ static int device_init_td0_ring(struct vnt_private *priv) return 0; err_free_desc: - while (--i) { + while (i--) { desc = &priv->apTD0Rings[i]; kfree(desc->td_info); } -- 2.35.1