From patchwork Wed Oct 19 08:30:48 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 5295 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4ac7:0:0:0:0:0 with SMTP id y7csp282108wrs; Wed, 19 Oct 2022 05:02:51 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6tLT6/CUClgf+7MWQ/pwRn6JhAYBAoWoPsIh19X+8Q4/xoggTdb8DMYYBf6/SRIELKGpAq X-Received: by 2002:aa7:c58a:0:b0:459:1511:6cff with SMTP id g10-20020aa7c58a000000b0045915116cffmr7194933edq.27.1666180971728; Wed, 19 Oct 2022 05:02:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666180971; cv=none; d=google.com; s=arc-20160816; b=IP3vKOM9nhvxGymgNzZ6ILtlIbwFjoDAU0lj6/89TVu1cIOoolBUnsW8b+UTQNqcdm 4Tlau9V5BZRfKO4jqRWtXW0ou0buhpP+i2Z5Ht/eVmX3y4yhGp2r80lTulPmI51mAVSE lo9qLmc1jBq/mOAKPTzD2R7dA+ZnQNXYA0t3H3/Ae/3YVPd3yUhbHNCBq1Q5yk5Xj981 oHcBFeXXPiE3iVtwO7J+77qVUa9zPiP3d1b5eokKgx4WtOXnbdpDPpeEmpg0kjF2xxD6 ooZVITWbZOnNle01nYhtau8G0ecE32owd0cwokpze45lwl0XG+NBdDb3pnRReV8Wu9hS JoOw== 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 Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id xg14-20020a170907320e00b00780805b99ccsi15752343ejb.648.2022.10.19.05.02.23; Wed, 19 Oct 2022 05:02:51 -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 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1747117378816172501?= X-GMAIL-MSGID: =?utf-8?q?1747117378816172501?= 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); }