From patchwork Mon Oct 24 11:31:02 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 8942 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp435241wru; Mon, 24 Oct 2022 05:53:56 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6/x+bqEZMitcXewZyS+fSNG6Gt8CKvJnCyQiePG48Sm1MK3FkeMlyidRU5ZyBxhltUpW2z X-Received: by 2002:a17:907:75e6:b0:7a1:848:20cb with SMTP id jz6-20020a17090775e600b007a1084820cbmr10037127ejc.745.1666616035886; Mon, 24 Oct 2022 05:53:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666616035; cv=none; d=google.com; s=arc-20160816; b=MvJNFOmGBVKbjbX1Rc2Q05Gvc2GgF/nkH/srxdUDILcJHC/UYMtEG5tjPq3nX1Vm9b nwSMYd6w/2YRxMRxWdR6ERfAgLTtYOdkaZz/sKKjO3LR4S+eVVtbRw2tvXgm8gkf0NLu i2OfkmOeZr2nhlfOjSFQoBl2nCBj+TheP32xyhGMurBzkfaJoZPw64OBJJapY0bQ5f5l 4HBTDc3G996QBvsDnunu+/zSBJHuPqeGUXC75WhabrRGn64+qJIHu8rVuLmQVTALwC8X Q4U/iGL/DzdPUpr7QLEmm7ePJHKdZFs6Wl7ktanm7y3L/IlwNXfp7wuv6sgnJf5zl9yC kBBA== 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=cyiouJ/lmUanYnMzeChA1KCdOYqsv5lnqmZqEDHaeaQ=; b=xFRGxOTD+x7ZytfuV3qkqpewtea9loPW4oip8cTebjI04qxwnHy/fTrU7INAEGVTwe 9Q+Kv5Lez/c4abJfOdsoGqJlnNRhom5Kr/IXqYXDQWxVFv018MwsS+4COgx38sLuhrQi mDQud/j17uYi+k3nYy08xNNcU8ewmKvOg/kqEh5ZOJzvtkqVk3i2pu6tj5UbprO+PuMR +FI21FmOCZxg7Cvq2YCPyOh2P2FF5se4BXUsdT2xMgTyUe60hqvD+Qrv5XL9sGl0TKG8 BCzYvgNfxWXQd2UryHLYyRY5KShUQyVCVM9jDQrok6jXzFTcpVUqrHdQCYS9rxIz6RqD NHxQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=d5M9xYr7; 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 t15-20020aa7d4cf000000b0045743696acbsi24160626edr.139.2022.10.24.05.53.31; Mon, 24 Oct 2022 05:53:55 -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=d5M9xYr7; 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 S234666AbiJXMwg (ORCPT + 99 others); Mon, 24 Oct 2022 08:52:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60256 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234428AbiJXMsp (ORCPT ); Mon, 24 Oct 2022 08:48:45 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6F042923C5; Mon, 24 Oct 2022 05:12:51 -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 B73DD612BB; Mon, 24 Oct 2022 12:11:22 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id C1692C433D6; Mon, 24 Oct 2022 12:11:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1666613482; bh=7BBawXnclGc7VD+m7l6mAXuY6gIVYHTlLGs2AC/M8g0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=d5M9xYr7hh/TZjwpuV/vsBo8+y0FfizhFHhPCfqu+s5IEXiEmALgRTvAIegtyEoh0 Iugr92MyI0QHofnfw9tP9mIUKpEI099XFe+/iGHj9jd8OIOhV9smxSYBxMxxJscvN3 TeLr7jtgfd+HGNJdJQMYGr7cpUzT6jRHdk4Kz2qI= 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.4 152/255] staging: vt6655: fix some erroneous memory clean-up loops Date: Mon, 24 Oct 2022 13:31:02 +0200 Message-Id: <20221024113007.691974379@linuxfoundation.org> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221024113002.471093005@linuxfoundation.org> References: <20221024113002.471093005@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?1747573576464552183?= X-GMAIL-MSGID: =?utf-8?q?1747573576464552183?= 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 082302944c37..c1f9b263129e 100644 --- a/drivers/staging/vt6655/device_main.c +++ b/drivers/staging/vt6655/device_main.c @@ -560,7 +560,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); @@ -606,7 +606,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); @@ -710,7 +710,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); }