Received: by 2002:ac0:946b:0:0:0:0:0 with SMTP id j40csp876418imj; Fri, 15 Feb 2019 08:14:41 -0800 (PST) X-Google-Smtp-Source: AHgI3IYjXD5Fp7fe7Cz5W/tYM5UdWCIgZ27WoU88Zk7vFk3K0sv2SwV+9MukH7hIQmPJiu66ihhg X-Received: by 2002:a63:6cc8:: with SMTP id h191mr5874339pgc.366.1550247281597; Fri, 15 Feb 2019 08:14:41 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1550247281; cv=none; d=google.com; s=arc-20160816; b=aVcgeBtl9nLeD96u+A8rPOa9/KnAHx8Gp1nHlvyUhKIUG6HOdCPUko6l4/Hw0Jbcfi Q3WWBvGXrr+OwbG4qHeLAbchBT2XMVUO9zcgKTHSdwOUdMYL3Eojmm1vxD5h9b+yOLE3 IsbQVJE1MdMONqeHCZmYE+ropBUnB2oY950ce2qwga/koo0iqFL5GcOKDnakkJG+e6JX MQ4Zq615FGhTanOeidiU4nB422C6q3UweyeG5S7Z2Kvi8PbeGGYXHV4AbvSkmUOnxFEI 6NP6gIrs62WEvP1Okq/xLjn7CU/spftji9TLyQdX/Wmwokgqa5wPxa1EygJyxYoge5Cb 2lYA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:in-reply-to :mime-version:user-agent:date:message-id:from:cc:references:to :subject; bh=OHfHzMGnjIuHSx4gmtbS132uTRGLqWi63gdpyUwwkLc=; b=QsWStQtzDethfKnPrhkbfZK/XNoCpczcCu3zo6wQYmC8qOOvPGIlEZJv8Ph40YrORc AQZGIJi2/0XBtvttS2dwZhgdBmdRG9DjwXOuSTRhHT2tv279HUGQj95F7bHZclAziDNl L90sY6825qXGeswDct3l7UmmmTWy3y2gHK3cMrd5nnQIRG/Ti+4pSwLISYqbVw6F3A0X gavA9YyGYTbaIqRaeMn93Ha9X5tisjAH/CyLyuL2kjV7QR1FbJw3RkVPkAJ2p8xalHPV YI83ZUI+lxm/wSDoNociq2cVIWzAfhtbaVSMNA/OfoSS7txnJ0fJBwbXygOS3rf/g4xE CHYQ== 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 1si3254630plb.103.2019.02.15.08.14.25; Fri, 15 Feb 2019 08:14:41 -0800 (PST) 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 S2394636AbfBOMAd (ORCPT + 99 others); Fri, 15 Feb 2019 07:00:33 -0500 Received: from szxga07-in.huawei.com ([45.249.212.35]:35728 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1733182AbfBOMAd (ORCPT ); Fri, 15 Feb 2019 07:00:33 -0500 Received: from DGGEMS412-HUB.china.huawei.com (unknown [172.30.72.58]) by Forcepoint Email with ESMTP id AC3AA1AE38023D200772; Fri, 15 Feb 2019 20:00:27 +0800 (CST) Received: from [127.0.0.1] (10.202.227.238) by DGGEMS412-HUB.china.huawei.com (10.3.19.212) with Microsoft SMTP Server id 14.3.408.0; Fri, 15 Feb 2019 20:00:18 +0800 Subject: Re: [PATCH] net: hns: Fix object reference leaks in hns_dsaf_roce_reset() To: Salil Mehta , Huang Zijiang , "Zhuangyuzeng (Yisen)" References: <1550126505-28394-1-git-send-email-huang.zijiang@zte.com.cn> <11b3bcdf50ee435587fbfad6043e49bc@huawei.com> CC: "davem@davemloft.net" , "lipeng (Y)" , liuyonglong , yuehaibing , "keescook@chromium.org" , "wangxi (M)" , "netdev@vger.kernel.org" , "linux-kernel@vger.kernel.org" , "wang.yi59@zte.com.cn" , Linuxarm From: John Garry Message-ID: <4ca251e6-22a1-a792-bb64-2498d8cb6fcd@huawei.com> Date: Fri, 15 Feb 2019 12:00:11 +0000 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:45.0) Gecko/20100101 Thunderbird/45.3.0 MIME-Version: 1.0 In-Reply-To: <11b3bcdf50ee435587fbfad6043e49bc@huawei.com> Content-Type: text/plain; charset="windows-1252"; format=flowed Content-Transfer-Encoding: 7bit X-Originating-IP: [10.202.227.238] X-CFilter-Loop: Reflected Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 15/02/2019 11:25, Salil Mehta wrote: >> From: John Garry >> Sent: Friday, February 15, 2019 10:52 AM >> >> On 14/02/2019 06:41, Huang Zijiang wrote: >>> The of_find_device_by_node() takes a reference to the underlying device >>> structure, we should release that reference. >> >> of_find_device_by_node() is not called for every path, so is this change proper: > > > It looks okay to me and with the suggested device reference is being > released from every possible error leg in the function. Could you be > more specific which error path is not being addressed? > > > >> /* find the platform device corresponding to fwnode */ >> if (is_of_node(dsaf_fwnode)) { >> pdev = of_find_device_by_node(to_of_node(dsaf_fwnode)); > > > This will get the reference to the device, which needs to be > released later. > > >> } else if (is_acpi_device_node(dsaf_fwnode)) { >> pdev = hns_dsaf_find_platform_device(dsaf_fwnode); > > > This will also get the reference to the device when bus_find_device() > gets called and returns the 'device'. Therefore, this needs to be > released as well using put_device() OK, I see. That's non-obvious. And so the commit message was simply incomplete. > So who finally drops this reference? This patch only seems to release on error path. I checked the callers and they don't seem to. John > > >> } else { >> pr_err("fwnode is neither OF or ACPI type\n"); >> return -EINVAL; >> } >> >> /* check if we were a success in fetching pdev */ >> if (!pdev) { >> pr_err("couldn't find platform device for node\n"); >> return -ENODEV; >> } >> >> /* retrieve the dsaf_device from the driver data */ >> dsaf_dev = dev_get_drvdata(&pdev->dev); >> if (!dsaf_dev) { >> dev_err(&pdev->dev, "dsaf_dev is NULL\n"); >> return -ENODEV; >> } >> >> John > > > [...] > >>> --- a/drivers/net/ethernet/hisilicon/hns/hns_dsaf_main.c >>> +++ b/drivers/net/ethernet/hisilicon/hns/hns_dsaf_main.c >>> @@ -3081,6 +3081,7 @@ int hns_dsaf_roce_reset(struct fwnode_handle *dsaf_fwnode, bool dereset) >>> dsaf_dev = dev_get_drvdata(&pdev->dev); >>> if (!dsaf_dev) { >>> dev_err(&pdev->dev, "dsaf_dev is NULL\n"); >>> + put_device(&pdev->dev); > > > This looks okay. > > >>> return -ENODEV; >>> } >>> >>> @@ -3088,6 +3089,7 @@ int hns_dsaf_roce_reset(struct fwnode_handle *dsaf_fwnode, bool dereset) >>> if (AE_IS_VER1(dsaf_dev->dsaf_ver)) { >>> dev_err(dsaf_dev->dev, "%s v1 chip doesn't support RoCE!\n", >>> dsaf_dev->ae_dev.name); >>> + put_device(&pdev->dev); > > > This looks okay. > > > Salil. > > . >