From patchwork Mon Oct 24 11:30:37 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 9939 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp599836wru; Mon, 24 Oct 2022 11:46:56 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6dQnVeh3s1IeynnLPHzyM/aM60kpy0yJHWQO7LjwX/DImOTKZqWyzJpamtTyqQcUzW01B1 X-Received: by 2002:a17:90b:4d07:b0:1ef:521c:f051 with SMTP id mw7-20020a17090b4d0700b001ef521cf051mr77484050pjb.164.1666637216551; Mon, 24 Oct 2022 11:46:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666637216; cv=none; d=google.com; s=arc-20160816; b=VTyjCw+RL6KigJQbz100wLCxuKpHBeALiLsnlkd8PY+nNSwtQhNokIc0L4sLxRhoO5 LQVv5ii15tsH4gdUaqp9P+7s2bbLJ7p9RXLhHgJiurvQtBQmDme22+CTKpV+lKzIMyn5 kpXmNqmVU5ghmBYKjMHMLixWDbe3urm5pub6RgSjtbCpqLhOWZTIMcvvKuQ6udeBoP9h tyVRZ4mLyB1CfYTbQtWnK2skIFXqPv2a4h3ksGktPhWgtR6dsqFEsaxt1VBsBZuJwWW0 rRyAOhc4xnxU9EqPGm3W4v4+ZoBo3/rmYDkBveiwqQQIDNWtiih0g0IyIIcuknsvcrxF ZTOQ== 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=GFggShj68URmr7lwhelnM6VU8++hDizMeTgrZqJ1dCs=; b=h/AItpioomIXa4RRzBHZNOD71aQTTA8my3voJI+LdBOnj25yj2TFiloU3q4peFwiAW 9q5yOY5k00TK5ztLetEr6hFForb6IEKBvytybUNrHBiRmePLacJxnbdxNcrmpyBXrWRX 6SP57y7432ZhtBT+ascTSJXiODBK8GxZLabQHkWCMRVxtEf56dqyde4KSEPrNC7eYjHv JVt549DgC2LJFwus7x2Cp9MJqJ3/9qAsca4aUulXvdBeyY159YSQHaX33ECtVuFGfToS ASCAT9Vw7avs6TXxnma17dO27Zny/SEDw9bxJ5nJsC6F8YWHL1vSb4k0fhGVpbTCQfO6 3/yw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=lCblZg3g; 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 f8-20020a170902ce8800b0016ee19bc5f9si256662plg.553.2022.10.24.11.46.43; Mon, 24 Oct 2022 11:46:56 -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=lCblZg3g; 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 S232594AbiJXSpq (ORCPT + 99 others); Mon, 24 Oct 2022 14:45:46 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41876 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232543AbiJXSpS (ORCPT ); Mon, 24 Oct 2022 14:45:18 -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 A36BCAC498; Mon, 24 Oct 2022 10:27:02 -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 2F614CE13CF; Mon, 24 Oct 2022 12:26:26 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0B69FC433C1; Mon, 24 Oct 2022 12:26:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1666614384; bh=l3lOmvb8DxNeJCwa8Zo59caxbNTlaKKRdNSZFh4rEMY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=lCblZg3g/HaucYtS6HBQZ9tDgdjRqjNy+C3g27SJqrghLgghPnT14DH4Ts1NpRlcq BN1UkJtGbFuVC9RdN4KbmZiGTjgsgzcHvrRAiUdYANRlVVhfNL9sOM6ieKEJTwMTHv HAcwLfSkdoooTbnetCvzd/AoWIUbyLczT/zNWX18= 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 5.10 240/390] staging: vt6655: fix some erroneous memory clean-up loops Date: Mon, 24 Oct 2022 13:30:37 +0200 Message-Id: <20221024113033.029480414@linuxfoundation.org> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221024113022.510008560@linuxfoundation.org> References: <20221024113022.510008560@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 X-Spam-Status: No, score=-7.6 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?1747595785918694846?= X-GMAIL-MSGID: =?utf-8?q?1747595785918694846?= 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 09ab6d6f2429..0dd70173a754 100644 --- a/drivers/staging/vt6655/device_main.c +++ b/drivers/staging/vt6655/device_main.c @@ -564,7 +564,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); @@ -610,7 +610,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); @@ -715,7 +715,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); }