Commit cd136706 authored by Linus Walleij's avatar Linus Walleij Committed by Greg Kroah-Hartman

USB: bcma: Make GPIO explicitly optional

What the code does is to not check the return value from
devm_gpiod_get() and then avoid using an erroneous GPIO descriptor
with IS_ERR_OR_NULL().

This will miss real errors from the GPIO core that should not be
ignored, such as probe deferral.

Instead request the GPIO as explicitly optional, which means that
if it doesn't exist, the descriptor returned will be NULL.

Then we can add error handling and also avoid just doing this on
the device tree path, and simplify the site where the optional
GPIO descriptor is used.

There were some problems with cleaning up this GPIO descriptor
use in the past, but this is the proper way to deal with it.

Cc: Rafał Miłecki <rafal@milecki.pl>
Cc: Chuhong Yuan <hslester96@gmail.com>
Signed-off-by: default avatarLinus Walleij <linus.walleij@linaro.org>
Cc: stable <stable@kernel.org>
Link: https://lore.kernel.org/r/20221107090753.1404679-1-linus.walleij@linaro.orgSigned-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent 30a0b95b
...@@ -285,7 +285,7 @@ static void bcma_hci_platform_power_gpio(struct bcma_device *dev, bool val) ...@@ -285,7 +285,7 @@ static void bcma_hci_platform_power_gpio(struct bcma_device *dev, bool val)
{ {
struct bcma_hcd_device *usb_dev = bcma_get_drvdata(dev); struct bcma_hcd_device *usb_dev = bcma_get_drvdata(dev);
if (IS_ERR_OR_NULL(usb_dev->gpio_desc)) if (!usb_dev->gpio_desc)
return; return;
gpiod_set_value(usb_dev->gpio_desc, val); gpiod_set_value(usb_dev->gpio_desc, val);
...@@ -406,9 +406,11 @@ static int bcma_hcd_probe(struct bcma_device *core) ...@@ -406,9 +406,11 @@ static int bcma_hcd_probe(struct bcma_device *core)
return -ENOMEM; return -ENOMEM;
usb_dev->core = core; usb_dev->core = core;
if (core->dev.of_node) usb_dev->gpio_desc = devm_gpiod_get_optional(&core->dev, "vcc",
usb_dev->gpio_desc = devm_gpiod_get(&core->dev, "vcc", GPIOD_OUT_HIGH);
GPIOD_OUT_HIGH); if (IS_ERR(usb_dev->gpio_desc))
return dev_err_probe(&core->dev, PTR_ERR(usb_dev->gpio_desc),
"error obtaining VCC GPIO");
switch (core->id.id) { switch (core->id.id) {
case BCMA_CORE_USB20_HOST: case BCMA_CORE_USB20_HOST:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment