From patchwork Sat Oct 22 07:25:30 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 7479 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4242:0:0:0:0:0 with SMTP id s2csp1101213wrr; Sat, 22 Oct 2022 01:20:05 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6gmylkJyap4JN53OeEtz7JNeYtC24AU6bSFBN/5faLJL84nJ8MTzyYJK1m3Qe1nuZHpXMz X-Received: by 2002:a17:90a:b103:b0:20d:69aa:a350 with SMTP id z3-20020a17090ab10300b0020d69aaa350mr60814076pjq.178.1666426805655; Sat, 22 Oct 2022 01:20:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666426805; cv=none; d=google.com; s=arc-20160816; b=ucqKPE53SFXwEaPaDRX+Wbb3WrTOENDj26Q4oTDTNzZYAN90nwW/cySdXWV5L3805I PDFVNbE7HeAXE/gww8R24wjyYclg8YJYZtU6Wtu8gz3kU4ZZ2vUidc9JFANb1H/wv4RA OIGLzpmit+MTaJIj5ZQO0/77C67gcX59FuQSIbtoVJEsg1z3Kui/8rbrrsThWyJtBBiV LTErGJW6xUFtj7YJm9c/jvJnpYIf6mDwhHDSY3ORoPJdhXv6HcAydJIEeEIFkyr1P6GE xDYvkx7MwQZ5VuCahCJNfQ4FbZQgZGzfLLlJCACvUt8XM5RnRs7bhbHfRGOSSVGcy+2H wvgQ== 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=AxXjufu2jhVkMJHSUHTXuKZQOjW6X0OlsWTmMnxRXvw=; b=Sy4Cyrod4LWhPR68Gq881fubCD7PkJHjo9Ax23XaWKnh9OOG6vm0JzxuZPF/DhKbKV NYRv4Ys7aStuz4CNM6rr44TzpYEqZQqBhWNikjGwBdy804W8OBsjA67kJbkhLvYWLsIm m8sbvrxOVz/iOpprOLs5K9RcHHfsoIA783Bb2m8X71GbdEcpfN5kzdwbmsYbSyZXTQWM pqUoamEkBdBn5R+kovu+wEWlO2znkxNKY3FmU3BZfpkCqQ/YyvA+rxOtftmFszR3VJsd V4Ikg3CK3Fvo6X/33Uemx4JOosDPrdsV4J+9KDwdt9YcdR3DsxwWSoHHYYd/Xh8OsRb/ oGHQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="JW/clmTH"; 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 e12-20020a65678c000000b0045afe1a8821si28145082pgr.128.2022.10.22.01.19.52; Sat, 22 Oct 2022 01:20:05 -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="JW/clmTH"; 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 S233330AbiJVIN0 (ORCPT + 99 others); Sat, 22 Oct 2022 04:13:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37152 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233300AbiJVILh (ORCPT ); Sat, 22 Oct 2022 04:11:37 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C4C374523D; Sat, 22 Oct 2022 00:54:47 -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 dfw.source.kernel.org (Postfix) with ESMTPS id 004D560B45; Sat, 22 Oct 2022 07:54:47 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id E6782C433D6; Sat, 22 Oct 2022 07:54:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1666425286; bh=MYLkHP5BSjJx3AY2DdM5hcJ68VoU5kZrCInx4VsyDTg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=JW/clmTH0Jb3O56MG67ptLrYtayilvv4AcKf1MHKm4JJ3SzqU03GwsgHcO/IuInTM leuk9KvadEqh8h9sd7lf1YcmIWJd08Q8s0UbTfgIwVsWlCzU/Tdxqdr6uly5aTtzFb PMjUi9rqanp/ptuGPJWJoLCFR0NEhZ4BSrRIzlcI= 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.19 451/717] staging: vt6655: fix some erroneous memory clean-up loops Date: Sat, 22 Oct 2022 09:25:30 +0200 Message-Id: <20221022072518.217101632@linuxfoundation.org> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221022072415.034382448@linuxfoundation.org> References: <20221022072415.034382448@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 X-Spam-Status: No, score=-7.3 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?1747375153759178361?= X-GMAIL-MSGID: =?utf-8?q?1747375153759178361?= 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 afaf331fe125..ecb8c3934bc6 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); }