From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-3.8 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 73E17C3A589 for ; Thu, 15 Aug 2019 20:51:14 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 49C7321721 for ; Thu, 15 Aug 2019 20:51:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732768AbfHOUvN (ORCPT ); Thu, 15 Aug 2019 16:51:13 -0400 Received: from shards.monkeyblade.net ([23.128.96.9]:50078 "EHLO shards.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730540AbfHOUvM (ORCPT ); Thu, 15 Aug 2019 16:51:12 -0400 Received: from localhost (unknown [IPv6:2601:601:9f80:35cd::d71]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) (Authenticated sender: davem-davemloft) by shards.monkeyblade.net (Postfix) with ESMTPSA id D40871401D397; Thu, 15 Aug 2019 13:51:11 -0700 (PDT) Date: Thu, 15 Aug 2019 13:51:11 -0700 (PDT) Message-Id: <20190815.135111.1048854967874803531.davem@davemloft.net> To: wenwen@cs.uga.edu Cc: rfontana@redhat.com, allison@lohutok.net, alexios.zavras@intel.com, gregkh@linuxfoundation.org, tglx@linutronix.de, netdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] net: pch_gbe: Fix memory leaks From: David Miller In-Reply-To: References: <20190815.134230.1028411309377288636.davem@davemloft.net> X-Mailer: Mew version 6.8 on Emacs 26.1 Mime-Version: 1.0 Content-Type: Text/Plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Greylist: Sender succeeded SMTP AUTH, not delayed by milter-greylist-4.5.12 (shards.monkeyblade.net [149.20.54.216]); Thu, 15 Aug 2019 13:51:12 -0700 (PDT) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Wenwen Wang Date: Thu, 15 Aug 2019 16:46:05 -0400 > On Thu, Aug 15, 2019 at 4:42 PM David Miller wrote: >> >> From: Wenwen Wang >> Date: Thu, 15 Aug 2019 16:03:39 -0400 >> >> > On Thu, Aug 15, 2019 at 3:34 PM David Miller wrote: >> >> >> >> From: Wenwen Wang >> >> Date: Tue, 13 Aug 2019 20:33:45 -0500 >> >> >> >> > In pch_gbe_set_ringparam(), if netif_running() returns false, 'tx_old' and >> >> > 'rx_old' are not deallocated, leading to memory leaks. To fix this issue, >> >> > move the free statements after the if branch. >> >> > >> >> > Signed-off-by: Wenwen Wang >> >> >> >> Why would they be "deallocated"? They are still assigned to >> >> adapter->tx_ring and adapter->rx_ring. >> > >> > 'adapter->tx_ring' and 'adapter->rx_ring' has been covered by newly >> > allocated 'txdr' and 'rxdr' respectively before this if statement. >> >> That only happens inside of the if() statement, that's why rx_old and >> tx_old are only freed in that code path. > > That happens not only inside of the if statement, but also before the > if statement, just after 'txdr' and 'rxdr' are allocated. Then the assignments inside of the if() statement are redundant. Something doesn't add up here, please make the code consistent.