From patchwork Mon Oct 24 11:31:04 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 8810 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp431004wru; Mon, 24 Oct 2022 05:42:43 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6lx1ih4dQiVonO4gyec3TMwZsQsGNvmudSgadYwzqppIMb0uO8+6LAk/QPldOsDZAJAZsP X-Received: by 2002:a05:6402:1947:b0:461:a47d:274 with SMTP id f7-20020a056402194700b00461a47d0274mr7350217edz.165.1666615363615; Mon, 24 Oct 2022 05:42:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666615363; cv=none; d=google.com; s=arc-20160816; b=ARE0uapSyNztrGnH3wN5h8Af7zsh4TWnd8AXrycTW8jtz3vcNE92FUeBmEZ5jcVwbQ flM6p0/GAQ9eta3fPZ3c2gUbY/77mmI4RChrC5hh/36/LN/ZiRhie6f9doYTXafoP4Oi 4hRIo8FhOo+Jnz3QEmbKxv63HAVvXLwJ/dA4xWarOykibFcRNIz6nEfOHXgf0werz/0i DIr0Bwv4Q7jPiAffiHPkkKs3fqzzRPlHRwA42m0ciykoYwWB9pV4mUPBrZMxCAMuBR40 FMU+wkxxwC6HsRaE0ZXM4fRYMd0ILvZhUAByqvckaUMvIYPpcpkdPRdiwk6Ckk6SsELq Oqkw== 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=on2Mg0ifTQsirRnYi4bN2rWD/WLsfEqrb8M2DOT3cKM=; b=l1YyqHh4Q+YxOJdX59WFDlrNN6Xmusi2g67aRVoBzL772ZOdj7UQzU6/hnMTJ0BjOe vvff5+zK0GrqWTusjA+1vcBtyxNBC3ozAiagGCAycFemtUtR7cchS+eFuEU3egvRCv4Q 9jTullDI9tA7rg+QuKl6BrKaWG5AqFLoZHuqLYPlZoLSqknkap7OKHK2R5Si0RofQjUo caXo4i0Z8vivMdve/VI31RIAv73GW6kbS1YnI4tMbnK2TuopXOvpkKTgg19Rgf1fpK2R 7RrsTLGCGrrxyvByzlKfTI4eff1e6fLF30XIWcGsmt+KjToWw4sqkTHbAUXfR59IU3Mh gkGQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=VGPwWUoc; 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 o8-20020a170906974800b0073db512d918si27903135ejy.765.2022.10.24.05.42.18; Mon, 24 Oct 2022 05:42:43 -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=VGPwWUoc; 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 S234361AbiJXMey (ORCPT + 99 others); Mon, 24 Oct 2022 08:34:54 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50796 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234223AbiJXM3k (ORCPT ); Mon, 24 Oct 2022 08:29:40 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 697CE85A8A; Mon, 24 Oct 2022 05:03:41 -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 ams.source.kernel.org (Postfix) with ESMTPS id DC718B81202; Mon, 24 Oct 2022 12:01:00 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3F594C433C1; Mon, 24 Oct 2022 12:00:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1666612859; bh=X4ILSxOO+PtPkQ3PRZOz5fy7LXio65AbI2CUs50rEmA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=VGPwWUoc0/ZCSY6d4c2w2Dux0ctz1BVcD6DJ6BffVT4JPNCu9UIRHl8EfuiZg5PS1 WyvCM81apAvRGvoQveGIAHf2s6kEi4DLbwKzU6XVf2d40Pc8fTkZocIL3Gp5pTlNOP TI7vJS0VLtdIJu2k5A1aaC7llwbRAyXeQ9wZGmcI= 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 4.19 145/229] staging: vt6655: fix some erroneous memory clean-up loops Date: Mon, 24 Oct 2022 13:31:04 +0200 Message-Id: <20221024113003.706003076@linuxfoundation.org> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221024112959.085534368@linuxfoundation.org> References: <20221024112959.085534368@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?1747572871862793041?= X-GMAIL-MSGID: =?utf-8?q?1747572871862793041?= 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 76f434c1c088..cf86b1efa821 100644 --- a/drivers/staging/vt6655/device_main.c +++ b/drivers/staging/vt6655/device_main.c @@ -567,7 +567,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); @@ -613,7 +613,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); @@ -717,7 +717,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); }