diff mbox series

[1/2] usb: gadget: udc: atmel: check rc of devm_gpiod_get_optional()

Message ID 20220705131951.1388968-1-michael@walle.cc (mailing list archive)
State New, archived
Headers show
Series [1/2] usb: gadget: udc: atmel: check rc of devm_gpiod_get_optional() | expand

Commit Message

Michael Walle July 5, 2022, 1:19 p.m. UTC
devm_gpiod_get_optional() might still return an error code, esp.
EPROBE_DEFER. Return any errors.

Signed-off-by: Michael Walle <michael@walle.cc>
---
 drivers/usb/gadget/udc/atmel_usba_udc.c | 2 ++
 1 file changed, 2 insertions(+)

Comments

Saravana Kannan July 5, 2022, 6:53 p.m. UTC | #1
On Tue, Jul 5, 2022 at 6:19 AM Michael Walle <michael@walle.cc> wrote:
>
> devm_gpiod_get_optional() might still return an error code, esp.
> EPROBE_DEFER. Return any errors.
>
> Signed-off-by: Michael Walle <michael@walle.cc>
> ---
>  drivers/usb/gadget/udc/atmel_usba_udc.c | 2 ++
>  1 file changed, 2 insertions(+)
>
> diff --git a/drivers/usb/gadget/udc/atmel_usba_udc.c b/drivers/usb/gadget/udc/atmel_usba_udc.c
> index ae2bfbac603e..48355e0cee76 100644
> --- a/drivers/usb/gadget/udc/atmel_usba_udc.c
> +++ b/drivers/usb/gadget/udc/atmel_usba_udc.c
> @@ -2165,6 +2165,8 @@ static struct usba_ep * atmel_udc_of_init(struct platform_device *pdev,
>
>         udc->vbus_pin = devm_gpiod_get_optional(&pdev->dev, "atmel,vbus",
>                                                 GPIOD_IN);
> +       if (IS_ERR(udc->vbus_pin))
> +               return ERR_CAST(udc->vbus_pin);

I'm confused. Is it really an optional resource if you treat a failure to get it
as a reason to fail a probe?

-Saravana

>
>         if (fifo_mode == 0) {
>                 udc->num_ep = udc_config->num_ep;
> --
> 2.30.2
>
Michael Walle July 5, 2022, 8:56 p.m. UTC | #2
Am 2022-07-05 20:53, schrieb Saravana Kannan:
> On Tue, Jul 5, 2022 at 6:19 AM Michael Walle <michael@walle.cc> wrote:
>> 
>> devm_gpiod_get_optional() might still return an error code, esp.
>> EPROBE_DEFER. Return any errors.
>> 
>> Signed-off-by: Michael Walle <michael@walle.cc>
>> ---
>>  drivers/usb/gadget/udc/atmel_usba_udc.c | 2 ++
>>  1 file changed, 2 insertions(+)
>> 
>> diff --git a/drivers/usb/gadget/udc/atmel_usba_udc.c 
>> b/drivers/usb/gadget/udc/atmel_usba_udc.c
>> index ae2bfbac603e..48355e0cee76 100644
>> --- a/drivers/usb/gadget/udc/atmel_usba_udc.c
>> +++ b/drivers/usb/gadget/udc/atmel_usba_udc.c
>> @@ -2165,6 +2165,8 @@ static struct usba_ep * atmel_udc_of_init(struct 
>> platform_device *pdev,
>> 
>>         udc->vbus_pin = devm_gpiod_get_optional(&pdev->dev, 
>> "atmel,vbus",
>>                                                 GPIOD_IN);
>> +       if (IS_ERR(udc->vbus_pin))
>> +               return ERR_CAST(udc->vbus_pin);
> 
> I'm confused. Is it really an optional resource if you treat a failure 
> to get it
> as a reason to fail a probe?

If the gpio isn't found NULL is returned.

-michael
Saravana Kannan July 6, 2022, 2:24 a.m. UTC | #3
On Tue, Jul 5, 2022 at 1:56 PM Michael Walle <michael@walle.cc> wrote:
>
> Am 2022-07-05 20:53, schrieb Saravana Kannan:
> > On Tue, Jul 5, 2022 at 6:19 AM Michael Walle <michael@walle.cc> wrote:
> >>
> >> devm_gpiod_get_optional() might still return an error code, esp.
> >> EPROBE_DEFER. Return any errors.
> >>
> >> Signed-off-by: Michael Walle <michael@walle.cc>
> >> ---
> >>  drivers/usb/gadget/udc/atmel_usba_udc.c | 2 ++
> >>  1 file changed, 2 insertions(+)
> >>
> >> diff --git a/drivers/usb/gadget/udc/atmel_usba_udc.c
> >> b/drivers/usb/gadget/udc/atmel_usba_udc.c
> >> index ae2bfbac603e..48355e0cee76 100644
> >> --- a/drivers/usb/gadget/udc/atmel_usba_udc.c
> >> +++ b/drivers/usb/gadget/udc/atmel_usba_udc.c
> >> @@ -2165,6 +2165,8 @@ static struct usba_ep * atmel_udc_of_init(struct
> >> platform_device *pdev,
> >>
> >>         udc->vbus_pin = devm_gpiod_get_optional(&pdev->dev,
> >> "atmel,vbus",
> >>                                                 GPIOD_IN);
> >> +       if (IS_ERR(udc->vbus_pin))
> >> +               return ERR_CAST(udc->vbus_pin);
> >
> > I'm confused. Is it really an optional resource if you treat a failure
> > to get it
> > as a reason to fail a probe?
>
> If the gpio isn't found NULL is returned.

Ah, ok.

-Saravana
diff mbox series

Patch

diff --git a/drivers/usb/gadget/udc/atmel_usba_udc.c b/drivers/usb/gadget/udc/atmel_usba_udc.c
index ae2bfbac603e..48355e0cee76 100644
--- a/drivers/usb/gadget/udc/atmel_usba_udc.c
+++ b/drivers/usb/gadget/udc/atmel_usba_udc.c
@@ -2165,6 +2165,8 @@  static struct usba_ep * atmel_udc_of_init(struct platform_device *pdev,
 
 	udc->vbus_pin = devm_gpiod_get_optional(&pdev->dev, "atmel,vbus",
 						GPIOD_IN);
+	if (IS_ERR(udc->vbus_pin))
+		return ERR_CAST(udc->vbus_pin);
 
 	if (fifo_mode == 0) {
 		udc->num_ep = udc_config->num_ep;