Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp1922971pxa; Sun, 23 Aug 2020 22:51:49 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwgng/WnM1g+2+vympw2hdBo1Z/Jfk9COgQuJwZXB51r/eDzf05dZGCvGTUUhYes2Z87Yer X-Received: by 2002:a17:906:386:: with SMTP id b6mr3941852eja.538.1598248309658; Sun, 23 Aug 2020 22:51:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1598248309; cv=none; d=google.com; s=arc-20160816; b=o7cOGAT6tOPExIbbGSllt/ALrK3XMZzgUmkgsypPRAsm4FU1ExfwWh93o99XC9deMu JC7QNj+2i42RQkL9ld9q5RnraVyfuBxEK5l7HfRqL8vur3zLUqafwS6if5PaO0z95hVl u0z5mUuKa77791mslQ6swZZULzrFd6wBPpzl4cYcgJEn2bwsTk3YGNW9ldhn7AwEyrQ6 MzCpPN8ZkVtFC+gX2atMB3if9lG4k23rKj0VwX7UVqpIxB3XAKOKbFasKfHg9H0Pavi8 dzn662LLTAxpQAReWEklBLsrm4ztJHB7T0wrl9GeoKTaBkvL4Dn0Zx5yLV9vtEfN7cJY yE+Q== 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=+nx2RH6/2cS3c9vvJuPuwEQGIK0JypLu9oMh+0EfYbM=; b=vOLn9RGK604B1aycDrr0Tr/zVenEEGOnQJAFg+Q130c6owt132t6n9LbvOrENI8vnn WKptAoN7tWSmG4iRVmVczamqAoqERIx+tY49I4wXkl5SArhD3PpFnUqBmEGVo7stD5zL lE6V6XbO/l4I07EnB8YK4ivQZmnBMigFcUD3aNQCXx1IJEVwktlpIGN5lpLauWy0Pyoy YBi45c+VmybXU64UecpC4OLf6G88HG4Ob6WFQMgEskkYkmxa3Xhe6m+kd9xAL1JzmgRf 2osnLWB0JmHsB3pJq1vPUXTU1SZ2EPraqaRpjrIBxyX+wjRUUw1cPxg3JSlEjiAwTPXU Ykcw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id w4si6141861ejb.443.2020.08.23.22.51.27; Sun, 23 Aug 2020 22:51:49 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727944AbgHXFpK (ORCPT + 99 others); Mon, 24 Aug 2020 01:45:10 -0400 Received: from spam.zju.edu.cn ([61.164.42.155]:37716 "EHLO zju.edu.cn" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1725836AbgHXFpJ (ORCPT ); Mon, 24 Aug 2020 01:45:09 -0400 Received: from localhost.localdomain (unknown [210.32.144.184]) by mail-app2 (Coremail) with SMTP id by_KCgCHL2DNU0NfqbMiAg--.23431S4; Mon, 24 Aug 2020 13:44:48 +0800 (CST) From: Dinghao Liu To: dinghao.liu@zju.edu.cn, kjlu@umn.edu Cc: Yisen Zhuang , Salil Mehta , "David S. Miller" , Jakub Kicinski , Heiner Kallweit , "Jason A. Donenfeld" , Shannon Nelson , "Michael S. Tsirkin" , Yonglong Liu , Kejian Yan , netdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH] net: hns: Fix memleak in hns_nic_dev_probe Date: Mon, 24 Aug 2020 13:44:42 +0800 Message-Id: <20200824054444.24142-1-dinghao.liu@zju.edu.cn> X-Mailer: git-send-email 2.17.1 X-CM-TRANSID: by_KCgCHL2DNU0NfqbMiAg--.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nxnUUI43ZEXa7VUbDDG5UUUUU== X-CM-SenderInfo: qrrzjiaqtzq6lmxovvfxof0/1tbiAgUCBlZdtPpD7wAFsv Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org hns_nic_dev_probe allocates ndev, but not free it on two error handling paths, which may lead to memleak. Fixes: 63434888aaf1b ("net: hns: net: hns: enet adds support of acpi") Signed-off-by: Dinghao Liu --- drivers/net/ethernet/hisilicon/hns/hns_enet.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/drivers/net/ethernet/hisilicon/hns/hns_enet.c b/drivers/net/ethernet/hisilicon/hns/hns_enet.c index 23f278e46975..22522f8a5299 100644 --- a/drivers/net/ethernet/hisilicon/hns/hns_enet.c +++ b/drivers/net/ethernet/hisilicon/hns/hns_enet.c @@ -2282,8 +2282,10 @@ static int hns_nic_dev_probe(struct platform_device *pdev) priv->enet_ver = AE_VERSION_1; else if (acpi_dev_found(hns_enet_acpi_match[1].id)) priv->enet_ver = AE_VERSION_2; - else - return -ENXIO; + else { + ret = -ENXIO; + goto out_read_prop_fail; + } /* try to find port-idx-in-ae first */ ret = acpi_node_get_property_reference(dev->fwnode, @@ -2299,7 +2301,8 @@ static int hns_nic_dev_probe(struct platform_device *pdev) priv->fwnode = args.fwnode; } else { dev_err(dev, "cannot read cfg data from OF or acpi\n"); - return -ENXIO; + ret = -ENXIO; + goto out_read_prop_fail; } ret = device_property_read_u32(dev, "port-idx-in-ae", &port_id); -- 2.17.1