Received: by 2002:ac0:8845:0:0:0:0:0 with SMTP id g63csp1524333img; Wed, 27 Feb 2019 00:25:55 -0800 (PST) X-Google-Smtp-Source: AHgI3IZ1LiNWaqeDixpwtaX1F5Q3iLTTzKQ0H5KxhTWMdRBDOrySSWZpdtjdfD6zcz9fNXvTt6Tz X-Received: by 2002:a17:902:6a83:: with SMTP id n3mr892504plk.313.1551255955394; Wed, 27 Feb 2019 00:25:55 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1551255955; cv=none; d=google.com; s=arc-20160816; b=HqvvXiOPmZ7eAV8raoKno/8QUDUwuxUML01VtNINrgl2THYK5Flx8cZsMzls3I/WK+ O6UsH6GuV/6eK/TuQy4AbpJg+FzuY+z6Qtm32IuI8xXZFJ6z1316lT5wP668tt9pd4dH nemPRZ95pkg5wQm94rvvExRtAgGJ19Om/v4mh8DjL+u+cRw3ajEvc4dnBjp7Jlnmz4JF TfZq/lMoz660bv3OBtg81R9FA4WYehj2CK0zj076TOBd7EafKzvX/VYC4lR73LayTmFC rl9FCB33iEVHeBzWHigyw2Blc2vGXBkp3BT2pQFwPta97SvwsDVHRVyYTd3M4vDYKrcz 8x0Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :message-id:in-reply-to:subject:cc:to:from:date; bh=EweGS459EmXMXy12RWPuLznF+QvDdeATXxDMjqTkysU=; b=WLHgAxfmlIUOhIWMLMFACsdDqe+uAp19SPlPCaE5MMhpY+IkaYJJzzETNlNgQiuLwo EtBaXm82t5nuYwuJKz8K0+wXLzDy+pDx5ckoySePCznrohdToUMBjqxQ63QtMIQHpww9 ngBVYnkWownUz3bdZMVXI6dZezh8XXXBZK3dg5FLS4xjgVqZI3A4Iogeu+zZuY2E0iv0 TiJoj8Qz9K4sdq7oLeg/hJOci/Ch7i7/Ih4aTw4f3pYY1HLio8nCTJgSD+VeOMdbUpXA teI4PKE/q4xwSc5o7g8llei534sqxdUAGpuaSmFV7Gc3ZFsJKFmbVZxE9K4OZAmJcsIJ kzhg== 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 n18si10438958pfe.166.2019.02.27.00.25.40; Wed, 27 Feb 2019 00:25:55 -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 S1729605AbfB0IZV (ORCPT + 99 others); Wed, 27 Feb 2019 03:25:21 -0500 Received: from mail2-relais-roc.national.inria.fr ([192.134.164.83]:53017 "EHLO mail2-relais-roc.national.inria.fr" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726791AbfB0IZV (ORCPT ); Wed, 27 Feb 2019 03:25:21 -0500 X-IronPort-AV: E=Sophos;i="5.58,418,1544482800"; d="scan'208";a="371074940" Received: from think-julia.rsr.lip6.fr ([132.227.76.14]) by mail2-relais-roc.national.inria.fr with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 27 Feb 2019 09:25:19 +0100 Date: Wed, 27 Feb 2019 09:25:19 +0100 (CET) From: Julia Lawall X-X-Sender: jll@hadrien To: Yoshihiro Shimoda 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 In-Reply-To: <1551250826-10302-1-git-send-email-yoshihiro.shimoda.uh@renesas.com> Message-ID: References: <1551250826-10302-1-git-send-email-yoshihiro.shimoda.uh@renesas.com> User-Agent: Alpine 2.21 (DEB 202 2017-01-01) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, 27 Feb 2019, Yoshihiro Shimoda wrote: > 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_device *pdev) > error = 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 = select_mask[channel_num]; > @@ -300,6 +301,7 @@ static int rcar_gen2_phy_probe(struct platform_device *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); Hello, I was concerned about the assignment channel->of_node = 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_get 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? julia