From: Lee Jones <lee@kernel.org>
To: Baolin Wang <baolin.wang@linux.alibaba.com>
Cc: Chunyan Zhang <chunyan.zhang@unisoc.com>,
Pavel Machek <pavel@ucw.cz>,
linux-leds@vger.kernel.org, Orson Zhai <orsonzhai@gmail.com>,
Chunyan Zhang <zhang.lyra@gmail.com>,
LKML <linux-kernel@vger.kernel.org>
Subject: Re: [RESEND PATCH V2] leds: sc27xx: Move mutex_init() to the end of probe
Date: Thu, 12 Oct 2023 10:16:02 +0100 [thread overview]
Message-ID: <20231012091602.GD8314@google.com> (raw)
In-Reply-To: <6110db84-546d-fc5c-f241-7923d673bbd5@linux.alibaba.com>
On Thu, 12 Oct 2023, Baolin Wang wrote:
>
>
> On 10/12/2023 11:47 AM, Chunyan Zhang wrote:
> > Move the mutex_init() to avoid redundant mutex_destroy() calls after
> > that for each time the probe fails.
> >
> > Signed-off-by: Chunyan Zhang <chunyan.zhang@unisoc.com>
> > ---
> > Rebased onto linux-next.
> >
> > V2:
> > - Move the mutex_init() to the end of .probe() instead of adding
> > mutex_destroy() according to Lee's comments.
> > ---
> > drivers/leds/leds-sc27xx-bltc.c | 9 ++++-----
> > 1 file changed, 4 insertions(+), 5 deletions(-)
> >
> > diff --git a/drivers/leds/leds-sc27xx-bltc.c b/drivers/leds/leds-sc27xx-bltc.c
> > index af1f00a2f328..ef57e57ecf07 100644
> > --- a/drivers/leds/leds-sc27xx-bltc.c
> > +++ b/drivers/leds/leds-sc27xx-bltc.c
> > @@ -296,7 +296,6 @@ static int sc27xx_led_probe(struct platform_device *pdev)
> > return -ENOMEM;
> > platform_set_drvdata(pdev, priv);
> > - mutex_init(&priv->lock);
> > priv->base = base;
> > priv->regmap = dev_get_regmap(dev->parent, NULL);
> > if (!priv->regmap) {
> > @@ -309,13 +308,11 @@ static int sc27xx_led_probe(struct platform_device *pdev)
> > err = of_property_read_u32(child, "reg", ®);
> > if (err) {
> > of_node_put(child);
> > - mutex_destroy(&priv->lock);
> > return err;
> > }
> > if (reg >= SC27XX_LEDS_MAX || priv->leds[reg].active) {
> > of_node_put(child);
> > - mutex_destroy(&priv->lock);
> > return -EINVAL;
> > }
> > @@ -325,9 +322,11 @@ static int sc27xx_led_probe(struct platform_device *pdev)
> > err = sc27xx_led_register(dev, priv);
> > if (err)
> > - mutex_destroy(&priv->lock);
> > + return err;
> > - return err;
> > + mutex_init(&priv->lock);
>
> I think it is better to prepare all the required resources before
> registering the led device, what I mean is moving mutex_init() before
> calling sc27xx_led_register().
Is the mutex used before this point?
If not, I don't see any reason to initialise it sooner.
--
Lee Jones [李琼斯]
next prev parent reply other threads:[~2023-10-12 9:16 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-10-12 3:47 [RESEND PATCH V2] leds: sc27xx: Move mutex_init() to the end of probe Chunyan Zhang
2023-10-12 7:29 ` Baolin Wang
2023-10-12 9:16 ` Lee Jones [this message]
2023-10-12 11:43 ` Baolin Wang
2023-10-13 10:19 ` Lee Jones
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=20231012091602.GD8314@google.com \
--to=lee@kernel.org \
--cc=baolin.wang@linux.alibaba.com \
--cc=chunyan.zhang@unisoc.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-leds@vger.kernel.org \
--cc=orsonzhai@gmail.com \
--cc=pavel@ucw.cz \
--cc=zhang.lyra@gmail.com \
/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