linux-gpio.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Bartosz Golaszewski <brgl@bgdev.pl>
To: Koichiro Den <koichiro.den@canonical.com>
Cc: linux-gpio@vger.kernel.org, geert+renesas@glider.be,
	 linus.walleij@linaro.org, maciej.borzecki@canonical.com,
	 linux-kernel@vger.kernel.org
Subject: Re: [PATCH v5 0/9] Introduce configfs-based interface for gpio-aggregator
Date: Mon, 10 Mar 2025 18:46:25 +0100	[thread overview]
Message-ID: <CAMRc=MdPLpQTeebDPk0+5ovuFCjcpNdb3BN5c7ADAxStE08JBQ@mail.gmail.com> (raw)
In-Reply-To: <n25f2iho3yn7ahx6isnm55g2cw5ox34rhqukhvgohzmtq22vzl@p5pptw6lw7ln>

On Mon, Mar 10, 2025 at 5:28 PM Koichiro Den <koichiro.den@canonical.com> wrote:
>

[snip!]

Please remove unnecessary context from responses. You attached
hundreds of lines of stack traces here. :(

>
> Thanks, I've confirmed it. It seems I overlooked it because somehow
> lockdep and kasan were not enabled for a while.
>
> Assuming the v5 patch series rebased onto the latest gpio/for-next
> 21c853ad9309 ("gpio: adnp: use new line value setter callbacks"),
> the following follow-up patch should suffice.
>
> ------------8<--------------8<---------------
> diff --git a/drivers/gpio/gpio-aggregator.c b/drivers/gpio/gpio-aggregator.c
> index df34d8fcb79a..56f0fde8c843 100644
> --- a/drivers/gpio/gpio-aggregator.c
> +++ b/drivers/gpio/gpio-aggregator.c
> @@ -207,7 +207,18 @@ static void aggr_free_lines(struct gpio_aggregator *aggr)
>
>         list_for_each_entry_safe(line, tmp, &aggr->list_head, entry) {
>                 configfs_unregister_group(&line->group);
> -               aggr_line_del(aggr, line);
> +               /*
> +                * Normally, we acquire aggr->lock within the configfs
> +                * callback. However, in the legacy sysfs interface case,
> +                * calling configfs_(un)register_group while holding
> +                * aggr->lock could cause a deadlock. Fortunately, this is
> +                * unnecessary because the new_device/delete_device path
> +                * and the module unload path are mutually exclusive,
> +                * thanks to an explicit try_module_get. That's why this
> +                * minimal scoped_guard suffices here.
> +                */
> +               scoped_guard(mutex, &aggr->lock)
> +                       aggr_line_del(aggr, line);
>                 kfree(line->key);
>                 kfree(line);
>         }
> @@ -926,8 +937,6 @@ static void gpio_aggr_device_release(struct config_item *item)
>  {
>         struct gpio_aggregator *aggr = to_gpio_aggregator(item);
>
> -       guard(mutex)(&aggr->lock);
> -
>         /*
>          * At this point, aggr is neither active nor activating,
>          * so calling aggr_deactivate() is always unnecessary.
> @@ -1072,7 +1081,8 @@ static int aggr_parse(struct gpio_aggregator *aggr)
>                                                         &line->group);
>                         if (error)
>                                 goto err;
> -                       aggr_line_add(aggr, line);
> +                       scoped_guard(mutex, &aggr->lock)
> +                               aggr_line_add(aggr, line);
>
>                         error = aggr_add_gpio(aggr, key, U16_MAX, &n);
>                         if (error)
> @@ -1101,7 +1111,8 @@ static int aggr_parse(struct gpio_aggregator *aggr)
>                                                         &line->group);
>                         if (error)
>                                 goto err;
> -                       aggr_line_add(aggr, line);
> +                       scoped_guard(mutex, &aggr->lock)
> +                               aggr_line_add(aggr, line);
>
>                         error = aggr_add_gpio(aggr, key, i, &n);
>                         if (error)
> @@ -1205,8 +1216,10 @@ static DRIVER_ATTR_WO(new_device);
>
>  static void gpio_aggregator_free(struct gpio_aggregator *aggr)
>  {
> -       if (aggr_is_activating(aggr) || aggr_is_active(aggr))
> -               aggr_deactivate(aggr);
> +       scoped_guard(mutex, &aggr->lock) {
> +               if (aggr_is_activating(aggr) || aggr_is_active(aggr))
> +                       aggr_deactivate(aggr);
> +       }
>         aggr_free_lines(aggr);
>         configfs_unregister_group(&aggr->group);
>         kfree(aggr);
> ------------8<--------------8<---------------
>
>
> * The second hunk should be squashed into
>   [PATCH v5 4/9] gpio: aggregator: introduce basic configfs interface
>
> * The rest of the hunks should be squashed into
>   [PATCH v5 8/9] gpio: aggregator: expose aggregator created via legacy sysfs to configfs
>
> If you agree with the above approach, I'll send out v6,
> while also addressing your feedback here:
> https://lore.kernel.org/all/CAMRc=MdoMKdqyzGMFDa3aMz3h=vfZ0OtwARxY7FdsPKcBu9HQA@mail.gmail.com/
>
> Koichiro
>

I won't be testing in-line diff chunks. Please, just fix these issues
and send a v6. Also: please do write some sort of a script to automate
the testing of this driver if possible. Ideally: add test script to
selftests.

Bart

  reply	other threads:[~2025-03-10 17:46 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-02-24 14:31 [PATCH v5 0/9] Introduce configfs-based interface for gpio-aggregator Koichiro Den
2025-02-24 14:31 ` [PATCH v5 1/9] gpio: aggregator: protect driver attr handlers against module unload Koichiro Den
2025-02-27  9:51   ` Bartosz Golaszewski
2025-02-24 14:31 ` [PATCH v5 2/9] gpio: aggregator: reorder functions to prepare for configfs introduction Koichiro Den
2025-02-24 14:31 ` [PATCH v5 3/9] gpio: aggregator: add aggr_alloc()/aggr_free() Koichiro Den
2025-02-24 14:31 ` [PATCH v5 4/9] gpio: aggregator: introduce basic configfs interface Koichiro Den
2025-02-24 14:31 ` [PATCH v5 5/9] gpio: aggregator: add 'name' attribute for custom GPIO line names Koichiro Den
2025-02-27  9:50   ` Bartosz Golaszewski
2025-03-05 12:44     ` Koichiro Den
2025-02-24 14:31 ` [PATCH v5 6/9] gpio: aggregator: rename 'name' to 'key' in aggr_parse() Koichiro Den
2025-02-24 14:31 ` [PATCH v5 7/9] gpio: aggregator: expose aggregator created via legacy sysfs to configfs Koichiro Den
2025-02-24 14:31 ` [PATCH v5 8/9] gpio: aggregator: cancel deferred probe for devices created via configfs Koichiro Den
2025-02-24 14:31 ` [PATCH v5 9/9] Documentation: gpio: document configfs interface for gpio-aggregator Koichiro Den
2025-03-05 12:15 ` (subset) [PATCH v5 0/9] Introduce configfs-based " Bartosz Golaszewski
2025-03-10 10:19 ` Bartosz Golaszewski
2025-03-10 13:32   ` Koichiro Den
2025-03-10 14:17     ` Bartosz Golaszewski
2025-03-10 16:28       ` Koichiro Den
2025-03-10 17:46         ` Bartosz Golaszewski [this message]
2025-03-13 17:00           ` Koichiro Den

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='CAMRc=MdPLpQTeebDPk0+5ovuFCjcpNdb3BN5c7ADAxStE08JBQ@mail.gmail.com' \
    --to=brgl@bgdev.pl \
    --cc=geert+renesas@glider.be \
    --cc=koichiro.den@canonical.com \
    --cc=linus.walleij@linaro.org \
    --cc=linux-gpio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=maciej.borzecki@canonical.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;
as well as URLs for NNTP newsgroup(s).