From: Lee Jones <lee@kernel.org>
To: MarileneGarcia <marilene.agarcia@gmail.com>
Cc: Javier Carrasco <javier.carrasco.cruz@gmail.com>,
linux-kernel@vger.kernel.org,
Julia Lawall <julia.lawall@inria.fr>,
Nicholas Piggin <npiggin@gmail.com>, Pavel Machek <pavel@ucw.cz>,
Shuah Khan <skhan@linuxfoundation.org>,
"Naveen N. Rao" <naveen.n.rao@linux.ibm.com>,
linuxppc-dev@lists.ozlabs.org, linux-leds@vger.kernel.org
Subject: Re: [PATCH v2 linux-next] leds: powernv: replace of_node_put to __free
Date: Fri, 31 May 2024 17:44:05 +0100 [thread overview]
Message-ID: <20240531164405.GV1005600@google.com> (raw)
In-Reply-To: <20240529200233.1188228-1-marilene.agarcia@gmail.com>
On Wed, 29 May 2024, MarileneGarcia wrote:
> Use __free for device_node values, and thus drop calls to
> of_node_put.
>
> The variable attribute __free adds a scope based cleanup to
> the device node. The goal is to reduce memory management issues
> in the kernel code.
>
> The of_node_put calls were removed, and the
> for_each_available_child_of_node was replaced to the equivalent
> for_each_available_child_of_node_scoped which use the __free.
>
> Suggested-by: Julia Lawall <julia.lawall@inria.fr>
> Signed-off-by: MarileneGarcia <marilene.agarcia@gmail.com>
> ---
> Changes v2:
> It was missing a blank line.
>
> Suggested-by: Julia Lawall <julia.lawall@inria.fr>
> Signed-off-by: MarileneGarcia <marilene.agarcia@gmail.com>
> ---
> drivers/leds/leds-powernv.c | 28 +++++++++-------------------
> 1 file changed, 9 insertions(+), 19 deletions(-)
>
> diff --git a/drivers/leds/leds-powernv.c b/drivers/leds/leds-powernv.c
> index 4f01acb75727..8f94d2efed9f 100644
> --- a/drivers/leds/leds-powernv.c
> +++ b/drivers/leds/leds-powernv.c
> @@ -246,29 +246,25 @@ static int powernv_led_classdev(struct platform_device *pdev,
> const char *cur = NULL;
> int rc = -1;
> struct property *p;
> - struct device_node *np;
> struct powernv_led_data *powernv_led;
> struct device *dev = &pdev->dev;
>
> - for_each_available_child_of_node(led_node, np) {
> + for_each_available_child_of_node_scoped(led_node, np) {
> p = of_find_property(np, "led-types", NULL);
>
> while ((cur = of_prop_next_string(p, cur)) != NULL) {
> powernv_led = devm_kzalloc(dev, sizeof(*powernv_led),
> GFP_KERNEL);
> - if (!powernv_led) {
> - of_node_put(np);
> + if (!powernv_led)
> return -ENOMEM;
> - }
>
> powernv_led->common = powernv_led_common;
> powernv_led->loc_code = (char *)np->name;
>
> rc = powernv_led_create(dev, powernv_led, cur);
> - if (rc) {
> - of_node_put(np);
> + if (rc)
> return rc;
> - }
> +
> } /* while end */
> }
>
> @@ -278,12 +274,11 @@ static int powernv_led_classdev(struct platform_device *pdev,
> /* Platform driver probe */
> static int powernv_led_probe(struct platform_device *pdev)
> {
> - struct device_node *led_node;
> struct powernv_led_common *powernv_led_common;
> struct device *dev = &pdev->dev;
> - int rc;
> + struct device_node *led_node __free(device_node) =
> + of_find_node_by_path("/ibm,opal/leds");
This is not a good line-break strategy.
struct device_node *led_node
__free(device_node) = of_find_node_by_path("/ibm,opal/leds");
struct device_node *led_node __free(device_node) =
of_find_node_by_path("/ibm,opal/leds");
Please choose one of these instead.
I suggest the top one might read a little easier.
> - led_node = of_find_node_by_path("/ibm,opal/leds");
Does the __free() have to be combined with an allocation?
> if (!led_node) {
> dev_err(dev, "%s: LED parent device node not found\n",
> __func__);
> @@ -292,20 +287,15 @@ static int powernv_led_probe(struct platform_device *pdev)
>
> powernv_led_common = devm_kzalloc(dev, sizeof(*powernv_led_common),
> GFP_KERNEL);
> - if (!powernv_led_common) {
> - rc = -ENOMEM;
> - goto out;
> - }
> + if (!powernv_led_common)
> + return -ENOMEM;
>
> mutex_init(&powernv_led_common->lock);
> powernv_led_common->max_led_type = cpu_to_be64(OPAL_SLOT_LED_TYPE_MAX);
>
> platform_set_drvdata(pdev, powernv_led_common);
>
> - rc = powernv_led_classdev(pdev, led_node, powernv_led_common);
> -out:
> - of_node_put(led_node);
> - return rc;
> + return powernv_led_classdev(pdev, led_node, powernv_led_common);
> }
>
> /* Platform driver remove */
> --
> 2.34.1
>
--
Lee Jones [李琼斯]
prev parent reply other threads:[~2024-05-31 16:45 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-05-29 20:02 [PATCH v2 linux-next] leds: powernv: replace of_node_put to __free MarileneGarcia
2024-05-31 16:44 ` Lee Jones [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20240531164405.GV1005600@google.com \
--to=lee@kernel.org \
--cc=javier.carrasco.cruz@gmail.com \
--cc=julia.lawall@inria.fr \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-leds@vger.kernel.org \
--cc=linuxppc-dev@lists.ozlabs.org \
--cc=marilene.agarcia@gmail.com \
--cc=naveen.n.rao@linux.ibm.com \
--cc=npiggin@gmail.com \
--cc=pavel@ucw.cz \
--cc=skhan@linuxfoundation.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).