From nobody Wed Sep 3 05:54:09 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5C132FA3747 for ; Mon, 24 Oct 2022 12:35:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234366AbiJXMez (ORCPT ); Mon, 24 Oct 2022 08:34:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50796 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234223AbiJXM3k (ORCPT ); Mon, 24 Oct 2022 08:29:40 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 697CE85A8A; Mon, 24 Oct 2022 05:03:41 -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 ams.source.kernel.org (Postfix) with ESMTPS id DC718B81202; Mon, 24 Oct 2022 12:01:00 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3F594C433C1; Mon, 24 Oct 2022 12:00:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1666612859; bh=X4ILSxOO+PtPkQ3PRZOz5fy7LXio65AbI2CUs50rEmA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=VGPwWUoc0/ZCSY6d4c2w2Dux0ctz1BVcD6DJ6BffVT4JPNCu9UIRHl8EfuiZg5PS1 WyvCM81apAvRGvoQveGIAHf2s6kEi4DLbwKzU6XVf2d40Pc8fTkZocIL3Gp5pTlNOP TI7vJS0VLtdIJu2k5A1aaC7llwbRAyXeQ9wZGmcI= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Dan Carpenter , Philipp Hortmann , Nam Cao , Sasha Levin Subject: [PATCH 4.19 145/229] staging: vt6655: fix some erroneous memory clean-up loops Date: Mon, 24 Oct 2022 13:31:04 +0200 Message-Id: <20221024113003.706003076@linuxfoundation.org> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221024112959.085534368@linuxfoundation.org> References: <20221024112959.085534368@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Nam Cao [ Upstream commit 2a2db520e3ca5aafba7c211abfd397666c9b5f9d ] In some initialization functions of this driver, memory is allocated with 'i' acting as an index variable and increasing from 0. The commit in "Fixes" introduces some clean-up codes in case of allocation failure, which free memory in reverse order with 'i' decreasing to 0. However, there are some problems: - The case i=3D0 is left out. Thus memory is leaked. - In case memory allocation fails right from the start, the memory freeing loops will start with i=3D-1 and invalid memory locations will be accessed. One of these loops has been fixed in commit c8ff91535880 ("staging: vt6655: fix potential memory leak"). Fix the remaining erroneous loops. Link: https://lore.kernel.org/linux-staging/Yx9H1zSpxmNqx6Xc@kadam/ Fixes: 5341ee0adb17 ("staging: vt6655: check for memory allocation failures= ") Reported-by: Dan Carpenter Tested-by: Philipp Hortmann Signed-off-by: Nam Cao Link: https://lore.kernel.org/r/20220912170429.29852-1-namcaov@gmail.com Signed-off-by: Greg Kroah-Hartman Signed-off-by: Sasha Levin --- drivers/staging/vt6655/device_main.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/drivers/staging/vt6655/device_main.c b/drivers/staging/vt6655/= device_main.c index 76f434c1c088..cf86b1efa821 100644 --- a/drivers/staging/vt6655/device_main.c +++ b/drivers/staging/vt6655/device_main.c @@ -567,7 +567,7 @@ static int device_init_rd0_ring(struct vnt_private *pri= v) kfree(desc->rd_info); =20 err_free_desc: - while (--i) { + while (i--) { desc =3D &priv->aRD0Ring[i]; device_free_rx_buf(priv, desc); kfree(desc->rd_info); @@ -613,7 +613,7 @@ static int device_init_rd1_ring(struct vnt_private *pri= v) kfree(desc->rd_info); =20 err_free_desc: - while (--i) { + while (i--) { desc =3D &priv->aRD1Ring[i]; device_free_rx_buf(priv, desc); kfree(desc->rd_info); @@ -717,7 +717,7 @@ static int device_init_td1_ring(struct vnt_private *pri= v) return 0; =20 err_free_desc: - while (--i) { + while (i--) { desc =3D &priv->apTD1Rings[i]; kfree(desc->td_info); } --=20 2.35.1