Received: by 2002:a05:6358:1087:b0:cb:c9d3:cd90 with SMTP id j7csp1010717rwi; Wed, 19 Oct 2022 05:48:26 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5cahY29L/hIcC8mt1Cu3/zbSWIgBqLRLCgRrHtLevQQcXYZ6LbgnHri/7EYBR1i+WdacNT X-Received: by 2002:a63:83c7:0:b0:46b:2a7b:a65 with SMTP id h190-20020a6383c7000000b0046b2a7b0a65mr7052748pge.169.1666183706246; Wed, 19 Oct 2022 05:48:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666183706; cv=none; d=google.com; s=arc-20160816; b=APYGQkTaofn9HxP0hWZPi9j+zC9ozkRhwnzd+av16wAg0pWlAL5dJQ73CTECfiKzwE cwDIY6NmsldWc/mg+3yLH9ooUxl+mGqiza2d7xpjk4cOJ+iekiEHvQnLUmqWOTWepv0W 84O3GGEEaOMJ3+Vs61KHccFQg77IA2O9jLyXVgp3Rm6ECR8/csz8RPxO7CNDEN4vmooL TGtLKKQ1LDQi0sV/bYvWH/Xke+A2AGfaegU0hCJRHBx+bhym8grLnthNGsbdT4sGiJjY hp4CiA4Ujmbweln4/cdwTw7bocEV3DQxxBlJX5s+IvUGYfXqS6Kxm4d25XvVgqRNDzUd g/UQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=smgLWoVtM1UFVmtSp0lHC2kS9rtCxUNPtq0eYjXq2wQ=; b=wMV0XedyMSEqmKIzXzoQDdEmUtlPg1iw3Gsi7RwukAyjlUUGAp0s8MdYEdb5wp6viY l4JlgJXb8Tu9zpvg8rEtRa9F9zV/+uGPyJNL/961vtLaPFfbC15ki8fkAfzo0wdQqOvx /VdqwU6zF1YQKA/F4C5EN20CxWqolE74xrJ+zTAQtCjlr13u2P6AdjseMsWNrO7xRBdq 3Fh7qQBe/AZGbjGm/ZqUjF2PLJ+QWmnhG7Z5HYjNnooc8L1KwxM4Urx0SMNYQNy3DnHZ Cq+zhcPB5/3c4UMQ2wG8UsNuevHoTPHRW+vGSEmnP/IHfmDJRXSkMtz3/iYvaEXcSbeB 0Mcw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=urwMgium; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id b22-20020a63d316000000b0046aabd03ce5si17124117pgg.796.2022.10.19.05.48.13; Wed, 19 Oct 2022 05:48:26 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=urwMgium; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231205AbiJSL7Q (ORCPT + 99 others); Wed, 19 Oct 2022 07:59:16 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44146 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232224AbiJSL6m (ORCPT ); Wed, 19 Oct 2022 07:58:42 -0400 Received: from sin.source.kernel.org (sin.source.kernel.org [IPv6:2604:1380:40e1:4800::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6BB843B9AF; Wed, 19 Oct 2022 04:36:53 -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 sin.source.kernel.org (Postfix) with ESMTPS id A7D5ACE215A; Wed, 19 Oct 2022 09:04:23 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8A134C433D6; Wed, 19 Oct 2022 09:04:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1666170261; bh=aG1VmPiSOMKW2hCxcFGQZpli/fWumh5/A/cWuJlqu4w=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=urwMgiumImtwKnLLjZSeTCtHje+FFMtdJRfxY720kIwBbiKmDbso00KM0wy1rRfFd hmR6mlFEolerOooTMABhl9qf+AawHFNCJt3+zgHtAkpzXAJEXZiWEIb5C+7EVcf+r4 CUN4h1fWtTcv6h2rVzoxdcLlasMLzO27bSpQyaCE= 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 6.0 561/862] staging: vt6655: fix some erroneous memory clean-up loops Date: Wed, 19 Oct 2022 10:30:48 +0200 Message-Id: <20221019083314.776142674@linuxfoundation.org> X-Mailer: git-send-email 2.38.0 In-Reply-To: <20221019083249.951566199@linuxfoundation.org> References: <20221019083249.951566199@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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=0 is left out. Thus memory is leaked. - In case memory allocation fails right from the start, the memory freeing loops will start with i=-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 bab08a40fe66..d76f65756db8 100644 --- a/drivers/staging/vt6655/device_main.c +++ b/drivers/staging/vt6655/device_main.c @@ -583,7 +583,7 @@ static int device_init_rd0_ring(struct vnt_private *priv) kfree(desc->rd_info); err_free_desc: - while (--i) { + while (i--) { desc = &priv->aRD0Ring[i]; device_free_rx_buf(priv, desc); kfree(desc->rd_info); @@ -629,7 +629,7 @@ static int device_init_rd1_ring(struct vnt_private *priv) kfree(desc->rd_info); err_free_desc: - while (--i) { + while (i--) { desc = &priv->aRD1Ring[i]; device_free_rx_buf(priv, desc); kfree(desc->rd_info); @@ -734,7 +734,7 @@ static int device_init_td1_ring(struct vnt_private *priv) return 0; err_free_desc: - while (--i) { + while (i--) { desc = &priv->apTD1Rings[i]; kfree(desc->td_info); } -- 2.35.1