From: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
To: "Uwe Kleine-König" <u.kleine-koenig@pengutronix.de>
Cc: Thierry Reding <thierry.reding@gmail.com>,
linux-pwm@vger.kernel.org, linux-kernel@vger.kernel.org,
kernel@pengutronix.de
Subject: Re: [PATCH 4/4] pwm: Don't initialize list head before calling list_add()
Date: Wed, 16 Nov 2022 10:21:05 +0200 [thread overview]
Message-ID: <Y3SdcQFRDySk3+9f@smile.fi.intel.com> (raw)
In-Reply-To: <20221115211515.3750209-5-u.kleine-koenig@pengutronix.de>
On Tue, Nov 15, 2022 at 10:15:15PM +0100, Uwe Kleine-König wrote:
> list_add() just overwrites the members of the element to add (here:
> chip->list) without any checks, even in the DEBUG_LIST case. So save the
> effort to initialize the list.
This is good patch. I agree with it.
The cause of this code appearing either some older changes, or cargo cult
of the trick similar to when list_del_init() is used against a list node.
(FYI: that trick is useful to simplify the check if the node in question
belongs to any list, by calling list_empty() against _node_ pointer)
The _add_ case with initialization makes no sense to me,
Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
> Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
> ---
> Hello,
>
> this patch I'm not sure about. A quick grep shows there are (only?) 40
> more code locations that call INIT_LIST_HEAD just before list_add().
> In my understanding INIT_LIST_HEAD is only to initialize lists, but
> chip->list is not a list, but the data needed to track chip as a list
> member.
>
> Best regards
> Uwe
>
> drivers/pwm/core.c | 1 -
> 1 file changed, 1 deletion(-)
>
> diff --git a/drivers/pwm/core.c b/drivers/pwm/core.c
> index b43b24bd3c9f..61bacd8d9b44 100644
> --- a/drivers/pwm/core.c
> +++ b/drivers/pwm/core.c
> @@ -299,7 +299,6 @@ int pwmchip_add(struct pwm_chip *chip)
> radix_tree_insert(&pwm_tree, pwm->pwm, pwm);
> }
>
> - INIT_LIST_HEAD(&chip->list);
> list_add(&chip->list, &pwm_chips);
>
> mutex_unlock(&pwm_lock);
> --
> 2.38.1
>
--
With Best Regards,
Andy Shevchenko
prev parent reply other threads:[~2022-11-16 8:23 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-11-15 21:15 [PATCH 0/4] pwm: Some refactoring of pwmchip_add() Uwe Kleine-König
2022-11-15 21:15 ` [PATCH 1/4] pwm: Document variables protected by pwm_lock Uwe Kleine-König
2022-11-16 8:22 ` Andy Shevchenko
2022-11-15 21:15 ` [PATCH 2/4] pwm: Reduce time the pwm_lock mutex is held in pwmchip_add() Uwe Kleine-König
2022-11-16 8:11 ` Andy Shevchenko
2022-11-17 14:00 ` Uwe Kleine-König
2022-11-17 15:33 ` Andy Shevchenko
2022-11-15 21:15 ` [PATCH 3/4] pwm: Mark free pwm IDs as used in alloc_pwms() Uwe Kleine-König
2022-11-16 8:17 ` Andy Shevchenko
2022-11-16 13:59 ` Uwe Kleine-König
2022-11-16 14:04 ` Andy Shevchenko
2022-11-15 21:15 ` [PATCH 4/4] pwm: Don't initialize list head before calling list_add() Uwe Kleine-König
2022-11-16 8:21 ` Andy Shevchenko [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=Y3SdcQFRDySk3+9f@smile.fi.intel.com \
--to=andriy.shevchenko@linux.intel.com \
--cc=kernel@pengutronix.de \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pwm@vger.kernel.org \
--cc=thierry.reding@gmail.com \
--cc=u.kleine-koenig@pengutronix.de \
/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