Message ID | 084fdd562690c08f1ee72bc08e63e8ee576dc86a.1693001599.git.christophe.jaillet@wanadoo.fr (mailing list archive) |
---|---|
State | Accepted |
Delegated to: | Sakari Ailus |
Headers |
Received: from vger.kernel.org ([23.128.96.18]) by www.linuxtv.org with esmtp (Exim 4.92) (envelope-from <linux-media-owner@vger.kernel.org>) id 1qZf5A-0080ID-OO; Fri, 25 Aug 2023 22:15:09 +0000 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230056AbjHYWOf (ORCPT <rfc822;mkrufky@linuxtv.org> + 1 other); Fri, 25 Aug 2023 18:14:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44390 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230215AbjHYWOJ (ORCPT <rfc822;linux-media@vger.kernel.org>); Fri, 25 Aug 2023 18:14:09 -0400 Received: from smtp.smtpout.orange.fr (smtp-30.smtpout.orange.fr [80.12.242.30]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9BC932711 for <linux-media@vger.kernel.org>; Fri, 25 Aug 2023 15:13:52 -0700 (PDT) Received: from pop-os.home ([86.243.2.178]) by smtp.orange.fr with ESMTPA id Zf3sqGJVgADjwZf3sq3hFV; Sat, 26 Aug 2023 00:13:50 +0200 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=wanadoo.fr; s=t20230301; t=1693001630; bh=Vbo5vzDX7vXJX6v/iiFgU/SzjBJx25qCoIqU0bH1fO0=; h=From:To:Cc:Subject:Date; b=OrQuGg2RhxTMxjxNifXtxC0fGgWsbJ8gPJ+m5RM7Xl3nJeQlKZ00dkX5VWWXY4d91 GZx0x+194k3bU3NEjwXkIOEpftqUtmrsYUCI1RScVvNHXWaJD5OytrkGcZSjeW1iTv /TGq7ZWgYCjdayw4vGHys55WGcs6Z6p2K3ycSq+253GCYNnbeaTz8S+siB/CudvK7p yus6FBf+nsSVqGM7JBDI8Ug0BvDSZlw4/vFP2U5W48N9kS1XOjmg7OPMXZLO2ImAaD RjcJxOk7LLS4GgDdqgyW6tjJgeBcDa0l8YB5kZ51ogQzZx/f5c7HRdstKEXFP1QDJb R2pA6migAjLbQ== X-ME-Helo: pop-os.home X-ME-Auth: Y2hyaXN0b3BoZS5qYWlsbGV0QHdhbmFkb28uZnI= X-ME-Date: Sat, 26 Aug 2023 00:13:50 +0200 X-ME-IP: 86.243.2.178 From: Christophe JAILLET <christophe.jaillet@wanadoo.fr> To: Jacopo Mondi <jacopo+renesas@jmondi.org>, Kieran Bingham <kieran.bingham+renesas@ideasonboard.com>, Laurent Pinchart <laurent.pinchart+renesas@ideasonboard.com>, =?utf-8?q?Nik?= =?utf-8?q?las_S=C3=B6derlund?= <niklas.soderlund+renesas@ragnatech.se>, Mauro Carvalho Chehab <mchehab@kernel.org>, Sakari Ailus <sakari.ailus@linux.intel.com> Cc: linux-kernel@vger.kernel.org, kernel-janitors@vger.kernel.org, Christophe JAILLET <christophe.jaillet@wanadoo.fr>, Mauro Carvalho Chehab <mchehab+huawei@kernel.org>, linux-media@vger.kernel.org Subject: [PATCH] media: i2c: max9286: Fix some redundant of_node_put() calls Date: Sat, 26 Aug 2023 00:13:40 +0200 Message-Id: <084fdd562690c08f1ee72bc08e63e8ee576dc86a.1693001599.git.christophe.jaillet@wanadoo.fr> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_BLOCKED, RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_PASS,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: <linux-media.vger.kernel.org> X-Mailing-List: linux-media@vger.kernel.org X-LSpam-Score: -2.5 (--) X-LSpam-Report: No, score=-2.5 required=5.0 tests=BAYES_00=-1.9,DKIM_SIGNED=0.1,DKIM_VALID=-0.1,DKIM_VALID_AU=-0.1,FREEMAIL_FORGED_FROMDOMAIN=0.001,FREEMAIL_FROM=0.001,HEADER_FROM_DIFFERENT_DOMAINS=0.5,MAILING_LIST_MULTI=-1 autolearn=ham autolearn_force=no |
Series |
media: i2c: max9286: Fix some redundant of_node_put() calls
|
|
Commit Message
Christophe JAILLET
Aug. 25, 2023, 10:13 p.m. UTC
This is odd to have a of_node_put() just after a for_each_child_of_node()
or a for_each_endpoint_of_node() loop. It should already be called
during the last iteration.
Remove these calls.
Fixes: 66d8c9d2422d ("media: i2c: Add MAX9286 driver")
Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
---
/!\ This patch is speculative, review with case /!\
---
drivers/media/i2c/max9286.c | 2 --
1 file changed, 2 deletions(-)
Comments
Hi Christophe On Sat, Aug 26, 2023 at 12:13:40AM +0200, Christophe JAILLET wrote: > This is odd to have a of_node_put() just after a for_each_child_of_node() > or a for_each_endpoint_of_node() loop. It should already be called > during the last iteration. Let's unwrap the calls: #define for_each_child_of_node(parent, child) \ for (child = of_get_next_child(parent, NULL); child != NULL; \ child = of_get_next_child(parent, child)) static struct device_node *__of_get_next_child(const struct device_node *node, struct device_node *prev) { struct device_node *next; if (!node) return NULL; next = prev ? prev->sibling : node->child; of_node_get(next); of_node_put(prev); return next; } Let's express the C for loop semantic as a while to help following the code: child = of_get_next_child(parent, NULL); while (child != NULL) child = of_get_next_child(parent, child); I concur that the last loop iteration the call to __of_get_next_child() will expand to next = NULL; of_node_get(NULL); of_node_put(prev) So it seems to me it is not necessary to put the node after for_each_child_of_node() ? In facts none of the other usages of for_each_child_of_node() in the kernel (the ones i checked at least) have a put() after the loop. > > Remove these calls. > > Fixes: 66d8c9d2422d ("media: i2c: Add MAX9286 driver") > Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr> Reviewed-by: Jacopo Mondi <jacopo.mondi@ideasonboard.com> Thanks j > --- > /!\ This patch is speculative, review with case /!\ > --- > drivers/media/i2c/max9286.c | 2 -- > 1 file changed, 2 deletions(-) > > diff --git a/drivers/media/i2c/max9286.c b/drivers/media/i2c/max9286.c > index 20e7c7cf5eeb..f27a69b1b727 100644 > --- a/drivers/media/i2c/max9286.c > +++ b/drivers/media/i2c/max9286.c > @@ -1450,7 +1450,6 @@ static int max9286_parse_dt(struct max9286_priv *priv) > > i2c_mux_mask |= BIT(id); > } > - of_node_put(node); > of_node_put(i2c_mux); > > /* Parse the endpoints */ > @@ -1514,7 +1513,6 @@ static int max9286_parse_dt(struct max9286_priv *priv) > priv->source_mask |= BIT(ep.port); > priv->nsources++; > } > - of_node_put(node); > > of_property_read_u32(dev->of_node, "maxim,bus-width", &priv->bus_width); > switch (priv->bus_width) { > -- > 2.34.1 >
Quoting Jacopo Mondi (2023-08-28 08:34:40) > Hi Christophe > > On Sat, Aug 26, 2023 at 12:13:40AM +0200, Christophe JAILLET wrote: > > This is odd to have a of_node_put() just after a for_each_child_of_node() > > or a for_each_endpoint_of_node() loop. It should already be called > > during the last iteration. > > Let's unwrap the calls: > > #define for_each_child_of_node(parent, child) \ > for (child = of_get_next_child(parent, NULL); child != NULL; \ > child = of_get_next_child(parent, child)) > > static struct device_node *__of_get_next_child(const struct device_node *node, > struct device_node *prev) > { > struct device_node *next; > > if (!node) > return NULL; > > next = prev ? prev->sibling : node->child; > of_node_get(next); > of_node_put(prev); > return next; > } > > Let's express the C for loop semantic as a while to help following the > code: > > child = of_get_next_child(parent, NULL); > while (child != NULL) > child = of_get_next_child(parent, child); > > I concur that the last loop iteration the call to > __of_get_next_child() will expand to > > next = NULL; > of_node_get(NULL); > of_node_put(prev) > > So it seems to me it is not necessary to put the node after > for_each_child_of_node() ? > > In facts none of the other usages of for_each_child_of_node() in the > kernel (the ones i checked at least) have a put() after the loop. I agree. As long as the loops don't use any break statement - there shouldn't be any _put() after the completion of the loop. That would make a good cocci script - make sure these iterators do not use 'break' internally - as that would then conflict! Reviewed-by: Kieran Bingham <kieran.bingham+renesas@ideasonboard.com> > > > > > Remove these calls. > > > > Fixes: 66d8c9d2422d ("media: i2c: Add MAX9286 driver") > > Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr> > > Reviewed-by: Jacopo Mondi <jacopo.mondi@ideasonboard.com> > > Thanks > j > > > --- > > /!\ This patch is speculative, review with case /!\ > > --- > > drivers/media/i2c/max9286.c | 2 -- > > 1 file changed, 2 deletions(-) > > > > diff --git a/drivers/media/i2c/max9286.c b/drivers/media/i2c/max9286.c > > index 20e7c7cf5eeb..f27a69b1b727 100644 > > --- a/drivers/media/i2c/max9286.c > > +++ b/drivers/media/i2c/max9286.c > > @@ -1450,7 +1450,6 @@ static int max9286_parse_dt(struct max9286_priv *priv) > > > > i2c_mux_mask |= BIT(id); > > } > > - of_node_put(node); > > of_node_put(i2c_mux); > > > > /* Parse the endpoints */ > > @@ -1514,7 +1513,6 @@ static int max9286_parse_dt(struct max9286_priv *priv) > > priv->source_mask |= BIT(ep.port); > > priv->nsources++; > > } > > - of_node_put(node); > > > > of_property_read_u32(dev->of_node, "maxim,bus-width", &priv->bus_width); > > switch (priv->bus_width) { > > -- > > 2.34.1 > >
Hi Christophe, Thank you for the patch. On Sat, Aug 26, 2023 at 12:13:40AM +0200, Christophe JAILLET wrote: > This is odd to have a of_node_put() just after a for_each_child_of_node() > or a for_each_endpoint_of_node() loop. It should already be called > during the last iteration. > > Remove these calls. > > Fixes: 66d8c9d2422d ("media: i2c: Add MAX9286 driver") > Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr> Reviewed-by: Laurent Pinchart <laurent.pinchart+renesas@ideasonboard.com> > --- > /!\ This patch is speculative, review with case /!\ > --- > drivers/media/i2c/max9286.c | 2 -- > 1 file changed, 2 deletions(-) > > diff --git a/drivers/media/i2c/max9286.c b/drivers/media/i2c/max9286.c > index 20e7c7cf5eeb..f27a69b1b727 100644 > --- a/drivers/media/i2c/max9286.c > +++ b/drivers/media/i2c/max9286.c > @@ -1450,7 +1450,6 @@ static int max9286_parse_dt(struct max9286_priv *priv) > > i2c_mux_mask |= BIT(id); > } > - of_node_put(node); > of_node_put(i2c_mux); > > /* Parse the endpoints */ > @@ -1514,7 +1513,6 @@ static int max9286_parse_dt(struct max9286_priv *priv) > priv->source_mask |= BIT(ep.port); > priv->nsources++; > } > - of_node_put(node); > > of_property_read_u32(dev->of_node, "maxim,bus-width", &priv->bus_width); > switch (priv->bus_width) {
diff --git a/drivers/media/i2c/max9286.c b/drivers/media/i2c/max9286.c index 20e7c7cf5eeb..f27a69b1b727 100644 --- a/drivers/media/i2c/max9286.c +++ b/drivers/media/i2c/max9286.c @@ -1450,7 +1450,6 @@ static int max9286_parse_dt(struct max9286_priv *priv) i2c_mux_mask |= BIT(id); } - of_node_put(node); of_node_put(i2c_mux); /* Parse the endpoints */ @@ -1514,7 +1513,6 @@ static int max9286_parse_dt(struct max9286_priv *priv) priv->source_mask |= BIT(ep.port); priv->nsources++; } - of_node_put(node); of_property_read_u32(dev->of_node, "maxim,bus-width", &priv->bus_width); switch (priv->bus_width) {