linux-bluetooth.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Lukas Wunner <lukas@wunner.de>
To: Linus Walleij <linus.walleij@linaro.org>
Cc: Andy Shevchenko <andriy.shevchenko@linux.intel.com>,
	Marcel Holtmann <marcel@holtmann.org>,
	Johan Hedberg <johan.hedberg@gmail.com>,
	Mika Westerberg <mika.westerberg@linux.intel.com>,
	Frederic Danis <frederic.danis.oss@gmail.com>,
	Loic Poulain <loic.poulain@linaro.org>,
	Hans de Goede <hdegoede@redhat.com>, Max Shavrick <mxms@me.com>,
	Leif Liddy <leif.liddy@gmail.com>,
	Daniel Roschka <danielroschka@phoenitydawn.de>,
	Ronald Tschalaer <ronald@innovation.ch>,
	"Peter Y. Chuang" <peteryuchuang@gmail.com>,
	linux-bluetooth@vger.kernel.org
Subject: Re: [PATCH 3/3] Bluetooth: Avoid WARN splat due to missing GPIOLIB
Date: Fri, 29 Dec 2017 10:51:35 +0100	[thread overview]
Message-ID: <20171229095135.GA25623@wunner.de> (raw)
In-Reply-To: <CACRpkdYRojbfCC_b9vO0MquvLeenru0rrYNv7WzMg3d3b=iF+g@mail.gmail.com>

On Thu, Dec 28, 2017 at 01:45:34PM +0100, Linus Walleij wrote:
> On Thu, Dec 28, 2017 at 1:40 PM, Andy Shevchenko <andriy.shevchenko@linux.intel.com> wrote:
> > On Thu, 2017-12-28 at 13:29 +0100, Linus Walleij wrote:
> >> On Thu, Dec 28, 2017 at 10:26 AM, Andy Shevchenko <andriy.shevchenko@linux.intel.com> wrote:
> >> > On Thu, 2017-12-28 at 10:18 +0100, Lukas Wunner wrote:
> >> > > On Thu, Dec 28, 2017 at 10:41:17AM +0200, Andy Shevchenko wrote:
> >> > > > On Tue, 2017-12-26 at 17:07 +0200, Lukas Wunner wrote:
> >> > > Hm okay, Documentation/gpio/consumer.txt says:
> >> > >
> >> > >     Guidelines for GPIOs consumers
> >> > >     ==============================
> >> > >
> >> > >     Drivers that can't work without standard GPIO calls should have
> >> > >     Kconfig entries that depend on GPIOLIB.
> >> > >
> >> > > So a "depends on GPIOLIB" would be more appropriate, right?
> >> >
> >> > Yes, but still wrong for this certain driver. It *can* work w/o
> >> > GPIOLIB.
> >> > Now you have done unnecessary dependency for that case.
> >>
> >> No I think it should use depends on GPIOLIB.
> >>
> >> The reason is that the driver uses unconditional devm_gpiod_get(),
> >> not devm_gpiod_get_optional().
> >
> > How come?
> > I just checked the code, all three use _optional() variant.
> >
> > I checked in bcm_get_resources().

Even though hci_bcm.c uses devm_gpiod_get_optional() for the device
wakeup and shutdown pins, it calls gpiod_set_value() on both pins
without checking if the're NULL in bcm_gpio_set_power().

It also calls gpiod_to_irq() on the host wakeup pin without checking
if it's NULL in bcm_get_resources(), which results in a WARN splat
if GPIOLIB is not enabled.

So this is clearly wrong.  The problem is, I don't have this hardware
to test myself, I don't have a spec for the chip and I don't know
what the driver author's intention was.  Perhaps these are just glitches
that snuck in when power management was retrofitted into the driver
and we can fix them with a few NULL pointer checks.  But I'm not sure
if these pins are really optional.  What if there are boards where
the chip is off by default and must be powered on by the driver?
In that case the pins aren't optional and enabling GPIOLIB is required.

I guess this driver was never really tested without these pins present
as users would immediately get a NULL pointer deref on probe.


> And BT_HCIUART_NOKIA compiles drivers/bluetooth/hci_nokia.c
> which does depend on GPIOLIB.

Sorry, you weren't cc'ed on the original patch, I stated in the commit
message:

    The same issue is present in hci_intel.c and hci_nokia.c, fix those up
    as well.

These two use devm_gpiod_get(), so we agree that they need to depend
on GPIOLIB, right?

By the way, what is the rationale for this rule that consumers shall
depend on rather than select GPIOLIB?  So that users are forced to
enable at least one GPIO driver?  If that is the motivation, it's
not bullet-proof as users can still select GPIOLIB without selecting
a driver, or select an input-only GPIO driver even though the GPIOs
are used as outputs by hci_*.c.

Thanks,

Lukas

  reply	other threads:[~2017-12-29  9:51 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-12-26 15:07 [PATCH 1/3] Bluetooth: hci_bcm: Support Apple GPIO handling Lukas Wunner
2017-12-26 15:07 ` [PATCH 2/3] Bluetooth: hci_bcm: Streamline runtime PM code Lukas Wunner
2017-12-26 20:57   ` Marcel Holtmann
2017-12-26 15:07 ` [PATCH 3/3] Bluetooth: Avoid WARN splat due to missing GPIOLIB Lukas Wunner
2017-12-26 20:57   ` Marcel Holtmann
2017-12-28  8:41   ` Andy Shevchenko
2017-12-28  9:18     ` Lukas Wunner
2017-12-28  9:26       ` Andy Shevchenko
2017-12-28 12:29         ` Linus Walleij
2017-12-28 12:40           ` Andy Shevchenko
2017-12-28 12:45             ` Linus Walleij
2017-12-29  9:51               ` Lukas Wunner [this message]
2017-12-29 14:18                 ` Loic Poulain
2017-12-29 15:12                   ` Lukas Wunner
2017-12-29 15:18                     ` Andy Shevchenko
2017-12-29 15:28                     ` Lukas Wunner
2018-01-01 15:23                 ` Linus Walleij
2018-01-02 15:27                   ` Marcel Holtmann
2018-01-02 16:58                     ` Lukas Wunner
2018-01-02 17:10                       ` Marcel Holtmann
2017-12-26 17:08 ` [PATCH 1/3] Bluetooth: hci_bcm: Support Apple GPIO handling Lukas Wunner
2017-12-26 20:50 ` Marcel Holtmann
2017-12-27 14:17   ` Lukas Wunner
2017-12-28  7:15   ` Lukas Wunner
2017-12-28 12:40     ` Hans de Goede
2017-12-28  7:38   ` Andy Shevchenko

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=20171229095135.GA25623@wunner.de \
    --to=lukas@wunner.de \
    --cc=andriy.shevchenko@linux.intel.com \
    --cc=danielroschka@phoenitydawn.de \
    --cc=frederic.danis.oss@gmail.com \
    --cc=hdegoede@redhat.com \
    --cc=johan.hedberg@gmail.com \
    --cc=leif.liddy@gmail.com \
    --cc=linus.walleij@linaro.org \
    --cc=linux-bluetooth@vger.kernel.org \
    --cc=loic.poulain@linaro.org \
    --cc=marcel@holtmann.org \
    --cc=mika.westerberg@linux.intel.com \
    --cc=mxms@me.com \
    --cc=peteryuchuang@gmail.com \
    --cc=ronald@innovation.ch \
    /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).