Received: by 2002:ac0:946b:0:0:0:0:0 with SMTP id j40csp873460imj; Fri, 15 Feb 2019 08:11:58 -0800 (PST) X-Google-Smtp-Source: AHgI3IbCmGTGT3sM2QujMXw/OrHwHLBu53H1ToP6JOi0iOggtmjybUkUXv76wCdsT9zpn/JrxdCn X-Received: by 2002:aa7:8497:: with SMTP id u23mr10661374pfn.253.1550247118721; Fri, 15 Feb 2019 08:11:58 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1550247118; cv=none; d=google.com; s=arc-20160816; b=pOcu5dPrD0AU5zqjJMF6Nxqt38YvGhWGT/YfU4JhnVGAyiXmqRFpigG5MOzt1ctvml 4gkt17r27qcvhyB8Do35XuPpmB/uRQS6/mywO97yZIcVgtR1rwGMLNiAtPiBljp9hoKL g8R88qqXF92y/jlFyuywQR2mkiIOnXuESofew7bbGEdCJzfkNZ7cr3w+tNHWXwCV7RtH tBBDUDnV6KxRThCZaS3jTz6s0Kl2SqTUEgJ4SuGamMh5n3HAaudaA4Lbj2XkjklKlH2e EGv9U4OHkjInJJ/xWAwYxSVaTB25qJKepGYNWixQXcQ+QyAAPSZ0bAqTSOVIEF+7m0BY LpzA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:content-transfer-encoding :content-language:accept-language:in-reply-to:references:message-id :date:thread-index:thread-topic:subject:cc:to:from; bh=h1XrdvfMoQ0zkC3K04DPbfcvG3SpQNgi0wRWiwMifBU=; b=Q6+QfuMaEd1NVHqneESPQ+l85Vxf33nWDMn3ezR8B+JxY/mFtOx99AzfyG05oCmLza +rZheT6o8C6zG3OJUfun1MjgPNWxbagAtTaMKNF+pMvyt+IFTWmt7p/ZTulxY59aJDnq MdeHh6ztESopWX8MZjgA39UYGWZUlyB9uOkoQB8hhc5BEklbb4so/Xh3rlm9pPZltuOD qmCRhPHzo8wpgRlJoMtgGcS8OeClBlX2RUsAP5clfBIlgMhCc8zZS/1lzmf04UCULgSz u6CHZrz5s1ft8pmSsxjK6HJkzKJ9MLHGqHAUkGMp8QXnsQzMhYIgahzwpSAM1IKsq5Il 3K9w== 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 g34si2709191pld.15.2019.02.15.08.11.41; Fri, 15 Feb 2019 08:11:58 -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 S2392918AbfBOLZV convert rfc822-to-8bit (ORCPT + 99 others); Fri, 15 Feb 2019 06:25:21 -0500 Received: from lhrrgout.huawei.com ([185.176.76.210]:32893 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726321AbfBOLZV (ORCPT ); Fri, 15 Feb 2019 06:25:21 -0500 Received: from lhreml708-cah.china.huawei.com (unknown [172.18.7.108]) by Forcepoint Email with ESMTP id C238539BD91D82D9D915; Fri, 15 Feb 2019 11:25:19 +0000 (GMT) Received: from lhreml702-chm.china.huawei.com (10.201.108.51) by lhreml708-cah.china.huawei.com (10.201.108.49) with Microsoft SMTP Server (TLS) id 14.3.408.0; Fri, 15 Feb 2019 11:25:19 +0000 Received: from lhreml702-chm.china.huawei.com (10.201.108.51) by lhreml702-chm.china.huawei.com (10.201.108.51) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1591.10; Fri, 15 Feb 2019 11:25:19 +0000 Received: from lhreml702-chm.china.huawei.com ([10.201.68.197]) by lhreml702-chm.china.huawei.com ([10.201.68.197]) with mapi id 15.01.1591.008; Fri, 15 Feb 2019 11:25:18 +0000 From: Salil Mehta To: John Garry , Huang Zijiang , "Zhuangyuzeng (Yisen)" 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 Subject: RE: [PATCH] net: hns: Fix object reference leaks in hns_dsaf_roce_reset() Thread-Topic: [PATCH] net: hns: Fix object reference leaks in hns_dsaf_roce_reset() Thread-Index: AQHUxDBEhCVMlZMv6EeAXB5DT3ZcMKXgsKCAgAAGiyA= Date: Fri, 15 Feb 2019 11:25:18 +0000 Message-ID: <11b3bcdf50ee435587fbfad6043e49bc@huawei.com> References: <1550126505-28394-1-git-send-email-huang.zijiang@zte.com.cn> In-Reply-To: Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [10.202.226.60] Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 8BIT MIME-Version: 1.0 X-CFilter-Loop: Reflected Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org > 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() > } 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.