linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Geert Uytterhoeven <geert@linux-m68k.org>
To: Bartosz Golaszewski <brgl@bgdev.pl>
Cc: Kent Gibson <warthog618@gmail.com>,
	Linus Walleij <linus.walleij@linaro.org>,
	Andy Shevchenko <andriy.shevchenko@linux.intel.com>,
	"open list:GPIO SUBSYSTEM" <linux-gpio@vger.kernel.org>,
	Linux Kernel Mailing List <linux-kernel@vger.kernel.org>,
	Bartosz Golaszewski <bgolaszewski@baylibre.com>
Subject: Re: [RESEND PATCH v6 5/7] gpiolib: provide a dedicated function for setting lineinfo
Date: Mon, 16 Mar 2020 17:20:54 +0100	[thread overview]
Message-ID: <CAMuHMdUc9Vwh=B5nA2tW66DwYr3AE6g2Jvd_o0W-oShDs+QQEg@mail.gmail.com> (raw)
In-Reply-To: <20200211091937.29558-6-brgl@bgdev.pl>

Hi Bartosz,

On Tue, Feb 11, 2020 at 10:21 AM Bartosz Golaszewski <brgl@bgdev.pl> wrote:
> From: Bartosz Golaszewski <bgolaszewski@baylibre.com>
> We'll soon be filling out the gpioline_info structure in multiple
> places. Add a separate function that given a gpio_desc sets all relevant
> fields.
>
> Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
> Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>

This is now commit d2ac25798208fb85 ("gpiolib: provide a dedicated
function for setting lineinfo") in gpio/for-next.

> --- a/drivers/gpio/gpiolib.c
> +++ b/drivers/gpio/gpiolib.c
> @@ -1147,6 +1147,60 @@ static int lineevent_create(struct gpio_device *gdev, void __user *ip)
>         return ret;
>  }
>
> +static void gpio_desc_to_lineinfo(struct gpio_desc *desc,
> +                                 struct gpioline_info *info)
> +{
> +       struct gpio_chip *chip = desc->gdev->chip;
> +       unsigned long flags;
> +
> +       spin_lock_irqsave(&gpio_lock, flags);

spinlock taken

> +
> +       if (desc->name) {
> +               strncpy(info->name, desc->name, sizeof(info->name));
> +               info->name[sizeof(info->name) - 1] = '\0';
> +       } else {
> +               info->name[0] = '\0';
> +       }
> +
> +       if (desc->label) {
> +               strncpy(info->consumer, desc->label, sizeof(info->consumer));
> +               info->consumer[sizeof(info->consumer) - 1] = '\0';
> +       } else {
> +               info->consumer[0] = '\0';
> +       }
> +
> +       /*
> +        * Userspace only need to know that the kernel is using this GPIO so
> +        * it can't use it.
> +        */
> +       info->flags = 0;
> +       if (test_bit(FLAG_REQUESTED, &desc->flags) ||
> +           test_bit(FLAG_IS_HOGGED, &desc->flags) ||
> +           test_bit(FLAG_USED_AS_IRQ, &desc->flags) ||
> +           test_bit(FLAG_EXPORT, &desc->flags) ||
> +           test_bit(FLAG_SYSFS, &desc->flags) ||
> +           !pinctrl_gpio_can_use_line(chip->base + info->line_offset))

pinctrl_gpio_can_use_line(), and pinctrl_get_device_gpio_range() called
from it, call mutex_lock():

    BUG: sleeping function called from invalid context at
kernel/locking/mutex.c:281
    in_atomic(): 1, irqs_disabled(): 128, non_block: 0, pid: 652, name: lsgpio
    CPU: 1 PID: 652 Comm: lsgpio Not tainted
5.6.0-rc1-koelsch-00008-gd2ac25798208fb85 #755
    Hardware name: Generic R-Car Gen2 (Flattened Device Tree)
    [<c020e3f0>] (unwind_backtrace) from [<c020a5b8>] (show_stack+0x10/0x14)
    [<c020a5b8>] (show_stack) from [<c07d31b4>] (dump_stack+0x88/0xa8)
    [<c07d31b4>] (dump_stack) from [<c0241318>] (___might_sleep+0xf8/0x168)
    [<c0241318>] (___might_sleep) from [<c07ec13c>] (mutex_lock+0x24/0x7c)
    [<c07ec13c>] (mutex_lock) from [<c046f47c>]
(pinctrl_get_device_gpio_range+0x1c/0xb4)
    [<c046f47c>] (pinctrl_get_device_gpio_range) from [<c046f5e8>]
(pinctrl_gpio_can_use_line+0x24/0x88)
    [<c046f5e8>] (pinctrl_gpio_can_use_line) from [<c0478bd0>]
(gpio_ioctl+0x270/0x584)
    [<c0478bd0>] (gpio_ioctl) from [<c03194c0>] (vfs_ioctl+0x20/0x38)

Reproducer is "lsgpio" with CONFIG_DEBUG_ATOMIC_SLEEP=y.

Gr{oetje,eeting}s,

                        Geert

-- 
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
                                -- Linus Torvalds

  reply	other threads:[~2020-03-16 16:21 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-02-11  9:19 [RESEND PATCH v6 0/7] gpiolib: add an ioctl() for monitoring line status changes Bartosz Golaszewski
2020-02-11  9:19 ` [RESEND PATCH v6 1/7] kfifo: provide noirqsave variants of spinlocked in and out helpers Bartosz Golaszewski
2020-02-11  9:19 ` [RESEND PATCH v6 2/7] kfifo: provide kfifo_is_empty_spinlocked() Bartosz Golaszewski
2020-02-11  9:19 ` [RESEND PATCH v6 3/7] gpiolib: rework the locking mechanism for lineevent kfifo Bartosz Golaszewski
2020-02-11  9:19 ` [RESEND PATCH v6 4/7] gpiolib: emit a debug message when adding events to a full kfifo Bartosz Golaszewski
2020-02-11  9:19 ` [RESEND PATCH v6 5/7] gpiolib: provide a dedicated function for setting lineinfo Bartosz Golaszewski
2020-03-16 16:20   ` Geert Uytterhoeven [this message]
2020-03-17 13:40     ` Bartosz Golaszewski
2020-02-11  9:19 ` [RESEND PATCH v6 6/7] gpiolib: add new ioctl() for monitoring changes in line info Bartosz Golaszewski
2020-02-12 10:47   ` Linus Walleij
2020-02-12 11:00     ` Bartosz Golaszewski
2020-02-20 15:03       ` Linus Walleij
2020-02-20 15:06         ` Bartosz Golaszewski
2020-02-11  9:19 ` [RESEND PATCH v6 7/7] tools: gpio: implement gpio-watch Bartosz Golaszewski
2020-02-12 10:49 ` [RESEND PATCH v6 0/7] gpiolib: add an ioctl() for monitoring line status changes Linus Walleij

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='CAMuHMdUc9Vwh=B5nA2tW66DwYr3AE6g2Jvd_o0W-oShDs+QQEg@mail.gmail.com' \
    --to=geert@linux-m68k.org \
    --cc=andriy.shevchenko@linux.intel.com \
    --cc=bgolaszewski@baylibre.com \
    --cc=brgl@bgdev.pl \
    --cc=linus.walleij@linaro.org \
    --cc=linux-gpio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=warthog618@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;
as well as URLs for NNTP newsgroup(s).