Received: by 2002:a25:8b12:0:0:0:0:0 with SMTP id i18csp3396189ybl; Sun, 11 Aug 2019 23:00:16 -0700 (PDT) X-Google-Smtp-Source: APXvYqy5Cm9bZRy+cp0YADBT5s0Du0sKMCoLgB5dXbwJIncHlByHuo64lATcKbIazMlOczcUMMYv X-Received: by 2002:a17:902:e30b:: with SMTP id cg11mr31898109plb.335.1565589616601; Sun, 11 Aug 2019 23:00:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1565589616; cv=none; d=google.com; s=arc-20160816; b=AI/Ildukx441y1zUfNf4DW2vKcv//2oewaY1+9lc3d+IywKiH9hFLcaoTjGOlACWT6 +OaqAqIRTgedixijsOEIgsYSFEIWfVdhnyaVhRrYd/c7z2qCIiD/s1J4kDGE2WFEbmuF 8RHKkpxSx+6Z9i5Tj93RArl6ph0Jj6xfUGiwWc3VAZIkhyAGaLHZHX7eMBVlS9nZ4RaY DQSAVy1ErY8vzyBS/tPgWywgRknTIWvA2J8QR4VBLo6iAQnYxIdrPt9xR1w7H3JIlNPD tfvqjVXHqY8+cYcO3oqz3YYa4PGJpWvFTU4DHsl0HPUDOqj2ZVfG9j5m7Nt8RxDXFjyA Aejw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from; bh=N6oSMRPpHGkQ7E+kK6e4vXB5ZZOBX+MrIVovGvsXigg=; b=Ni54zXN+G+uOWLwLpr7Ybd1ruq7zV9b5tAYr68nKk/ZTBCv3Abnl8bCrdldQne84Kl DGK4Tk7zyik89GVwb+yUVgXKLeMWqiJM2oQvC8inEVpvaer3pAJOCLedtEH7bqhKRP7p 2apLjzzT/qq9KHFqpDQAne6hz+bRZRc+TN2rQ3l2y98U/rSFSZbrLfFRPO2CzDUmjM6v HelGZ+rCmBt7A0LItuONTaaPXpQRL0+maTrjC7YREW2zBfQ+QafWVcSUegjjB0gErwpI Rz92Y5SXgl0gm6va7YorZqvzcXngtS50qFLwwvv/djUaPsw49F6QEuizTPkvvrIg/r6/ QhBw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id b10si9205737plx.415.2019.08.11.23.00.01; Sun, 11 Aug 2019 23:00:16 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726949AbfHLF73 (ORCPT + 99 others); Mon, 12 Aug 2019 01:59:29 -0400 Received: from mail-yb1-f195.google.com ([209.85.219.195]:45055 "EHLO mail-yb1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725819AbfHLF72 (ORCPT ); Mon, 12 Aug 2019 01:59:28 -0400 Received: by mail-yb1-f195.google.com with SMTP id y21so1760951ybi.11; Sun, 11 Aug 2019 22:59:28 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=N6oSMRPpHGkQ7E+kK6e4vXB5ZZOBX+MrIVovGvsXigg=; b=IzzNYvEb8kl4xf3lmvM5GQCAsQXvIFOWUmV/0R/Ox4sOR6YrMw7ZChyK9K4/WDfXEB YUAG1nsD+HGryy3UHFh5aq7/fNcgtUw3aMKMA9MiTW4+R8mvCipMSB7K9M3Va5cBjaYe Ls51oAq+5HwH/FlkqgqA+ZsEW7n0U6M0ZJrd3cHFYY3XMTb0d6u9l8/l5zL+0Ms+XFQ/ IYf5xEQ8+GHUFgwMGldjNgaOd4dAJ/MPK2SviD/xHMlqiBhwA+Ree4tBIYlwaMz8F3gA d+OEGX1x6xwqvqRhG3dftyei/pKopqLgKPzv2cFB9eO9wwXw/5EoeYeE1SGcnpCxxsjl oYyg== X-Gm-Message-State: APjAAAUlr1dhzUGanSgqmoLib8PRiqqs4tbfA8mqskWnxUz55yTbyH8Z GuXiZZQCPCOveHOFk/ekx9U= X-Received: by 2002:a25:d794:: with SMTP id o142mr9107179ybg.384.1565589567579; Sun, 11 Aug 2019 22:59:27 -0700 (PDT) Received: from localhost.localdomain (24-158-240-219.dhcp.smyr.ga.charter.com. [24.158.240.219]) by smtp.gmail.com with ESMTPSA id e12sm24721471ywe.85.2019.08.11.22.59.26 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sun, 11 Aug 2019 22:59:26 -0700 (PDT) From: Wenwen Wang To: Wenwen Wang Cc: Jeff Kirsher , "David S. Miller" , intel-wired-lan@lists.osuosl.org (moderated list:INTEL ETHERNET DRIVERS), netdev@vger.kernel.org (open list:NETWORKING DRIVERS), linux-kernel@vger.kernel.org (open list) Subject: [PATCH] e1000: fix memory leaks Date: Mon, 12 Aug 2019 00:59:21 -0500 Message-Id: <1565589561-5910-1-git-send-email-wenwen@cs.uga.edu> X-Mailer: git-send-email 2.7.4 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org In e1000_set_ringparam(), 'tx_old' and 'rx_old' are not deallocated if e1000_up() fails, leading to memory leaks. Refactor the code to fix this issue. Signed-off-by: Wenwen Wang --- drivers/net/ethernet/intel/e1000/e1000_ethtool.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/drivers/net/ethernet/intel/e1000/e1000_ethtool.c b/drivers/net/ethernet/intel/e1000/e1000_ethtool.c index a410085..2e07ffa 100644 --- a/drivers/net/ethernet/intel/e1000/e1000_ethtool.c +++ b/drivers/net/ethernet/intel/e1000/e1000_ethtool.c @@ -607,6 +607,7 @@ static int e1000_set_ringparam(struct net_device *netdev, for (i = 0; i < adapter->num_rx_queues; i++) rxdr[i].count = rxdr->count; + err = 0; if (netif_running(adapter->netdev)) { /* Try to get new resources before deleting old */ err = e1000_setup_all_rx_resources(adapter); @@ -627,14 +628,13 @@ static int e1000_set_ringparam(struct net_device *netdev, adapter->rx_ring = rxdr; adapter->tx_ring = txdr; err = e1000_up(adapter); - if (err) - goto err_setup; } kfree(tx_old); kfree(rx_old); clear_bit(__E1000_RESETTING, &adapter->flags); - return 0; + return err; + err_setup_tx: e1000_free_all_rx_resources(adapter); err_setup_rx: @@ -646,7 +646,6 @@ static int e1000_set_ringparam(struct net_device *netdev, err_alloc_tx: if (netif_running(adapter->netdev)) e1000_up(adapter); -err_setup: clear_bit(__E1000_RESETTING, &adapter->flags); return err; } -- 2.7.4