Received: by 2002:ac0:8845:0:0:0:0:0 with SMTP id g63csp1544051img; Wed, 27 Feb 2019 00:54:38 -0800 (PST) X-Google-Smtp-Source: AHgI3IYG7zKsRB+O9UI9ktMSg4D98sWlWsAadWV8Nf5UkyUEPz2CRxCwg0laHap2Tq+8oufJTVWW X-Received: by 2002:a17:902:461:: with SMTP id 88mr1015138ple.216.1551257678865; Wed, 27 Feb 2019 00:54:38 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1551257678; cv=none; d=google.com; s=arc-20160816; b=kAw4ijhoPnmrCGCJbm7X/gP/jfBJv9haNPSf5iTV6Db+F+/Lc88UtYaW4GXXsGp6OT KRXt4Z6ntG4Ua+KxxJY3j3M64HAQfnbnULLGhqrFk3RX4I41xq8uL34IE4baatobAQI9 ATRM5fwwEtD+tXAej1/rQ+EF1wJcGvxkuK1s6HKiJ369skfhyUPNU8bp+SBkIt3w92G2 NcWXiB2OrO+dgNJDMyaz4pJ5PTCHmnIDpnO+lFH8C892XzaYwHUmhhcWS0GchvVlUvWc IzzHDiCBsvxTB27tEUV1d4otiw7mX6JqMG689vLaomDvtBre5pNNysoJWZWXzZ5zA6AZ MUEA== 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:dkim-signature; bh=/mUa/vym5ddVBhZIqOEynsOi0KZa15p+8beP3S6vewA=; b=dbN8kDPW1nqedBSEUPl071bd1/5J6+yu7YRBzksGSsRr9Cj77p4fJip2dO0awrptBS fVSUlpjGWfqD2JzHcs8TekF7/31t3RpGDwm+1ftgQJcswVVwE4sC9EoAuzGe+ZGpOAdX XXfe/C9Kw7SQU4FtdiqE9ZDcvMaMkYU0wEpoQxciNtI3ENLZorIEvrsk4eV7LToKBfBx Zx8LPINq+0r4XB5Xsthb9x3jzV315SuTApvINtuV1y9qT6PrTGzVg7jc3WcEA5YfyAVn A12jxvGvTPlNysQfxQgdKZueUZiEVRxFIVB+VS9DHG75IDRvFlbKorJJ1hCCls71Ky12 0OEA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@renesasgroup.onmicrosoft.com header.s=selector1-renesas-com header.b=RnfiIOgI; 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 1si15134813pln.122.2019.02.27.00.54.23; Wed, 27 Feb 2019 00:54:38 -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; dkim=pass header.i=@renesasgroup.onmicrosoft.com header.s=selector1-renesas-com header.b=RnfiIOgI; 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 S1729674AbfB0Ixn (ORCPT + 99 others); Wed, 27 Feb 2019 03:53:43 -0500 Received: from mail-eopbgr1310115.outbound.protection.outlook.com ([40.107.131.115]:47668 "EHLO APC01-SG2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726031AbfB0Ixn (ORCPT ); Wed, 27 Feb 2019 03:53:43 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=renesasgroup.onmicrosoft.com; s=selector1-renesas-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=/mUa/vym5ddVBhZIqOEynsOi0KZa15p+8beP3S6vewA=; b=RnfiIOgI0Fqpz8hNLbdrFFy/HtoQm6SZfJ+nUpWs9q5Mj2IQ5rwlQDi7CPd+kuL5pQMOQFQKWTB2b8So/oI3Kpv/nGpsZw/HEZ6ltcW+i41hUeoc5Nnphw2Iq9PoH12FsF9sAvJjIQHFnx0LCYWSdweqS2Nvv518q5t/6B0X7ek= Received: from TY2PR01MB4812.jpnprd01.prod.outlook.com (20.179.170.147) by TY2PR01MB3275.jpnprd01.prod.outlook.com (20.177.100.137) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1643.18; Wed, 27 Feb 2019 08:53:35 +0000 Received: from TY2PR01MB4812.jpnprd01.prod.outlook.com ([fe80::44b:a054:4954:f819]) by TY2PR01MB4812.jpnprd01.prod.outlook.com ([fe80::44b:a054:4954:f819%2]) with mapi id 15.20.1643.022; Wed, 27 Feb 2019 08:53:35 +0000 From: Yoshihiro Shimoda To: Julia Lawall CC: "kishon@ti.com" , "linux-kernel@vger.kernel.org" , "linux-renesas-soc@vger.kernel.org" Subject: RE: [PATCH] phy: renesas: rcar-gen2: Fix memory leak at error paths Thread-Topic: [PATCH] phy: renesas: rcar-gen2: Fix memory leak at error paths Thread-Index: AQHUzmoRtGFFVYG3M06xnOGKQQhNVaXzTx6AgAAGzdA= Date: Wed, 27 Feb 2019 08:53:35 +0000 Message-ID: References: <1551250826-10302-1-git-send-email-yoshihiro.shimoda.uh@renesas.com> In-Reply-To: Accept-Language: ja-JP, en-US Content-Language: ja-JP X-MS-Has-Attach: X-MS-TNEF-Correlator: authentication-results: spf=none (sender IP is ) smtp.mailfrom=yoshihiro.shimoda.uh@renesas.com; x-originating-ip: [124.210.22.195] x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: f9899241-c4f7-4750-38d7-08d69c910f42 x-ms-office365-filtering-ht: Tenant x-microsoft-antispam: BCL:0;PCL:0;RULEID:(2390118)(7020095)(4652040)(8989299)(4534185)(7168020)(4627221)(201703031133081)(201702281549075)(8990200)(5600127)(711020)(4605104)(4618075)(2017052603328)(7153060)(7193020);SRVR:TY2PR01MB3275; x-ms-traffictypediagnostic: TY2PR01MB3275: x-microsoft-exchange-diagnostics: 1;TY2PR01MB3275;20:b4UylppEWkWztrYBLrA+vfi3feI0xUepowyMHv8JWAaWPanEPziA8vNww0uUgRVI+n5XyzQSeGllbEJW//51pRfgNsbNSABtCOfB/Vi/jt7X6cgS3TZUUi/scLBpbSthAYr+4GFiMhK4/D3fpL/bWULghLcowZE+Pv/5q/CffY4= x-microsoft-antispam-prvs: x-forefront-prvs: 0961DF5286 x-forefront-antispam-report: SFV:NSPM;SFS:(10019020)(396003)(346002)(366004)(376002)(39860400002)(136003)(199004)(189003)(446003)(55236004)(11346002)(102836004)(6506007)(97736004)(316002)(68736007)(486006)(256004)(71200400001)(6246003)(4326008)(71190400001)(476003)(25786009)(52536013)(26005)(76176011)(86362001)(186003)(5660300002)(53936002)(8676002)(229853002)(6916009)(106356001)(8936002)(7736002)(33656002)(6116002)(74316002)(3846002)(9686003)(55016002)(7696005)(14454004)(66066001)(478600001)(99286004)(54906003)(2906002)(81166006)(81156014)(105586002)(305945005)(6436002);DIR:OUT;SFP:1102;SCL:1;SRVR:TY2PR01MB3275;H:TY2PR01MB4812.jpnprd01.prod.outlook.com;FPR:;SPF:None;LANG:en;PTR:InfoNoRecords;A:1;MX:1; received-spf: None (protection.outlook.com: renesas.com does not designate permitted sender hosts) x-ms-exchange-senderadcheck: 1 x-microsoft-antispam-message-info: PrKjwdykwSeRlIw9BqKkXYYR3osXZ9vdZsU42xEAWtvXA1BCOK100jH2LDxBcshBztgGG4ZIk70df/nK3fkxoEQzkG+812HrhkXLO2DQwOvRXISE035muUQRwFz49jdJQ2f5SbAbjHM9g6QAWz3ev0Syw390XNgza7usDV6CKhY7OnNuzATvbXImX5MATd2UeoE5o8xmOEGQ3U3VYpUkrOCKQrKie8drLLh4qingHo5MrmHH/wpjDha+6m9CTy360/NdDVlHIXtg8i4q3CJsdHQCQ6gdHz6o0v+XqV4QXQKGMTqyf3+Cg/YI3o8yk25G27vxu8P2QbZCDJ/+erQq+l7t6P2wghHB6J9XN39mhuD5yC6AH8NQEkVqyvpX78NBuXvYrsuMEQpbXDtSgXL2wc1JnsZoI57g0wIVuk/cBc4= Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-OriginatorOrg: renesas.com X-MS-Exchange-CrossTenant-Network-Message-Id: f9899241-c4f7-4750-38d7-08d69c910f42 X-MS-Exchange-CrossTenant-originalarrivaltime: 27 Feb 2019 08:53:35.7821 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 53d82571-da19-47e4-9cb4-625a166a4a2a X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-Transport-CrossTenantHeadersStamped: TY2PR01MB3275 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hello, > From: Julia Lawall, Sent: Wednesday, February 27, 2019 5:25 PM >=20 > On Wed, 27 Feb 2019, Yoshihiro Shimoda wrote: >=20 > > This patch fixes memory leak at error paths of the probe function. > > In for_each_child_of_node, if the loop returns, the driver should > > call of_put_node() before returns. > > > > Reported-by: Julia Lawall > > Fixes: 1233f59f745 ("phy: Renesas R-Car Gen2 PHY driver") > > Signed-off-by: Yoshihiro Shimoda > > --- > > drivers/phy/renesas/phy-rcar-gen2.c | 2 ++ > > 1 file changed, 2 insertions(+) > > > > diff --git a/drivers/phy/renesas/phy-rcar-gen2.c b/drivers/phy/renesas/= phy-rcar-gen2.c > > index 72eeb06..570b4e4 100644 > > --- a/drivers/phy/renesas/phy-rcar-gen2.c > > +++ b/drivers/phy/renesas/phy-rcar-gen2.c > > @@ -285,6 +285,7 @@ static int rcar_gen2_phy_probe(struct platform_devi= ce *pdev) > > error =3D of_property_read_u32(np, "reg", &channel_num); > > if (error || channel_num > 2) { > > dev_err(dev, "Invalid \"reg\" property\n"); > > + of_node_put(np); > > return error; > > } > > channel->select_mask =3D select_mask[channel_num]; > > @@ -300,6 +301,7 @@ static int rcar_gen2_phy_probe(struct platform_devi= ce *pdev) > > &rcar_gen2_phy_ops); > > if (IS_ERR(phy->phy)) { > > dev_err(dev, "Failed to create PHY\n"); > > + of_node_put(np); > > return PTR_ERR(phy->phy); > > } > > phy_set_drvdata(phy->phy, phy); >=20 > Hello, >=20 > I was concerned about the assignment channel->of_node =3D np;. Because > channels is allocated with a devm function, it will get freed on an error > return, so this pointer doesn't matter. But don't you need an of_node_ge= t > on this assignment? Does the fact that you haven't seen a problem with > this in testing mean that the field is actually never accessed? The channel->of_node will be used in the rcar_gen2_phy_xlate() as drv->chan= nels[i].of_node. The assignment is not used for any device tree APIs, just comparing the poi= nter. So, I don't think this driver needs an of_node_get() on this assignment. Is my understanding incorrect? --- static struct phy *rcar_gen2_phy_xlate(struct device *dev, struct of_phandle_args *args) { struct rcar_gen2_phy_driver *drv; struct device_node *np =3D args->np; int i; drv =3D dev_get_drvdata(dev); if (!drv) return ERR_PTR(-EINVAL); for (i =3D 0; i < drv->num_channels; i++) { if (np =3D=3D drv->channels[i].of_node) // <--- here only break; } if (i >=3D drv->num_channels || args->args[0] >=3D 2) return ERR_PTR(-ENODEV); return drv->channels[i].phys[args->args[0]].phy; } --- Best regards, Yoshihiro Shimoda > julia