linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] media: st-mipid02: add a check for devm_gpiod_get_optional
@ 2019-10-16 10:56 Chuhong Yuan
  2019-10-17  5:43 ` Mickael GUENE
  0 siblings, 1 reply; 4+ messages in thread
From: Chuhong Yuan @ 2019-10-16 10:56 UTC (permalink / raw)
  Cc: Mickael Guene, Mauro Carvalho Chehab, linux-media, linux-kernel,
	Chuhong Yuan

mipid02_probe misses a check for devm_gpiod_get_optional and may miss
the failure.
Add a check to fix the problem.

Signed-off-by: Chuhong Yuan <hslester96@gmail.com>
---
 drivers/media/i2c/st-mipid02.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/drivers/media/i2c/st-mipid02.c b/drivers/media/i2c/st-mipid02.c
index 81285b8d5cfb..d38e888b0a43 100644
--- a/drivers/media/i2c/st-mipid02.c
+++ b/drivers/media/i2c/st-mipid02.c
@@ -971,6 +971,9 @@ static int mipid02_probe(struct i2c_client *client)
 	bridge->reset_gpio = devm_gpiod_get_optional(dev, "reset",
 						     GPIOD_OUT_HIGH);
 
+	if (IS_ERR(bridge->reset_gpio))
+		return PTR_ERR(bridge->reset_gpio);
+
 	ret = mipid02_get_regulators(bridge);
 	if (ret) {
 		dev_err(dev, "failed to get regulators %d", ret);
-- 
2.20.1


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] media: st-mipid02: add a check for devm_gpiod_get_optional
  2019-10-16 10:56 [PATCH] media: st-mipid02: add a check for devm_gpiod_get_optional Chuhong Yuan
@ 2019-10-17  5:43 ` Mickael GUENE
  2019-10-17  7:48   ` Chuhong Yuan
  0 siblings, 1 reply; 4+ messages in thread
From: Mickael GUENE @ 2019-10-17  5:43 UTC (permalink / raw)
  To: Chuhong Yuan; +Cc: Mauro Carvalho Chehab, linux-media, linux-kernel

Hello Chuhong,

 Is this check necessary ?
since looking into code it seems to me devm_gpiod_get_optional() can only
return NULL in case of error due to following check in devm_gpiod_get_index_optional()
	if (IS_ERR(desc)) {
		if (PTR_ERR(desc) == -ENOENT)
			return NULL;
	}
 And in that case reset_gpio is not used

Regards
Mickael

On 10/16/19 12:56, Chuhong Yuan wrote:
> mipid02_probe misses a check for devm_gpiod_get_optional and may miss
> the failure.
> Add a check to fix the problem.
> 
> Signed-off-by: Chuhong Yuan <hslester96@gmail.com>
> ---
>  drivers/media/i2c/st-mipid02.c | 3 +++
>  1 file changed, 3 insertions(+)
> 
> diff --git a/drivers/media/i2c/st-mipid02.c b/drivers/media/i2c/st-mipid02.c
> index 81285b8d5cfb..d38e888b0a43 100644
> --- a/drivers/media/i2c/st-mipid02.c
> +++ b/drivers/media/i2c/st-mipid02.c
> @@ -971,6 +971,9 @@ static int mipid02_probe(struct i2c_client *client)
>  	bridge->reset_gpio = devm_gpiod_get_optional(dev, "reset",
>  						     GPIOD_OUT_HIGH);
>  
> +	if (IS_ERR(bridge->reset_gpio))
> +		return PTR_ERR(bridge->reset_gpio);
> +
>  	ret = mipid02_get_regulators(bridge);
>  	if (ret) {
>  		dev_err(dev, "failed to get regulators %d", ret);
> 

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] media: st-mipid02: add a check for devm_gpiod_get_optional
  2019-10-17  5:43 ` Mickael GUENE
@ 2019-10-17  7:48   ` Chuhong Yuan
  2019-10-17 12:24     ` Mickael GUENE
  0 siblings, 1 reply; 4+ messages in thread
From: Chuhong Yuan @ 2019-10-17  7:48 UTC (permalink / raw)
  To: Mickael GUENE; +Cc: Mauro Carvalho Chehab, linux-media, linux-kernel

On Thu, Oct 17, 2019 at 1:43 PM Mickael GUENE <mickael.guene@st.com> wrote:
>
> Hello Chuhong,
>
>  Is this check necessary ?
> since looking into code it seems to me devm_gpiod_get_optional() can only
> return NULL in case of error due to following check in devm_gpiod_get_index_optional()
>         if (IS_ERR(desc)) {
>                 if (PTR_ERR(desc) == -ENOENT)
>                         return NULL;
>         }
>  And in that case reset_gpio is not used
>

The problem may not be a null return value, but a returned error,
which is a minus value,
like -EPROBE_DEFER or -EINVAL returned by gpiod_find in gpiod_get_index.
In these cases, devm_gpiod_get_index_optional will not return null but
return the error.
Therefore, this check is necessary.

> Regards
> Mickael
>
> On 10/16/19 12:56, Chuhong Yuan wrote:
> > mipid02_probe misses a check for devm_gpiod_get_optional and may miss
> > the failure.
> > Add a check to fix the problem.
> >
> > Signed-off-by: Chuhong Yuan <hslester96@gmail.com>
> > ---
> >  drivers/media/i2c/st-mipid02.c | 3 +++
> >  1 file changed, 3 insertions(+)
> >
> > diff --git a/drivers/media/i2c/st-mipid02.c b/drivers/media/i2c/st-mipid02.c
> > index 81285b8d5cfb..d38e888b0a43 100644
> > --- a/drivers/media/i2c/st-mipid02.c
> > +++ b/drivers/media/i2c/st-mipid02.c
> > @@ -971,6 +971,9 @@ static int mipid02_probe(struct i2c_client *client)
> >       bridge->reset_gpio = devm_gpiod_get_optional(dev, "reset",
> >                                                    GPIOD_OUT_HIGH);
> >
> > +     if (IS_ERR(bridge->reset_gpio))
> > +             return PTR_ERR(bridge->reset_gpio);
> > +
> >       ret = mipid02_get_regulators(bridge);
> >       if (ret) {
> >               dev_err(dev, "failed to get regulators %d", ret);
> >

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] media: st-mipid02: add a check for devm_gpiod_get_optional
  2019-10-17  7:48   ` Chuhong Yuan
@ 2019-10-17 12:24     ` Mickael GUENE
  0 siblings, 0 replies; 4+ messages in thread
From: Mickael GUENE @ 2019-10-17 12:24 UTC (permalink / raw)
  To: Chuhong Yuan; +Cc: Mauro Carvalho Chehab, linux-media, linux-kernel

Hello Chuhong,

 Sorry I missed 'if (PTR_ERR(desc) == -ENOENT)' check ....
 Can you in this case add an error message ?

Regards
Mickael
 
On 10/17/19 09:48, Chuhong Yuan wrote:
> On Thu, Oct 17, 2019 at 1:43 PM Mickael GUENE <mickael.guene@st.com> wrote:
>>
>> Hello Chuhong,
>>
>>  Is this check necessary ?
>> since looking into code it seems to me devm_gpiod_get_optional() can only
>> return NULL in case of error due to following check in devm_gpiod_get_index_optional()
>>         if (IS_ERR(desc)) {
>>                 if (PTR_ERR(desc) == -ENOENT)
>>                         return NULL;
>>         }
>>  And in that case reset_gpio is not used
>>
> 
> The problem may not be a null return value, but a returned error,
> which is a minus value,
> like -EPROBE_DEFER or -EINVAL returned by gpiod_find in gpiod_get_index.
> In these cases, devm_gpiod_get_index_optional will not return null but
> return the error.
> Therefore, this check is necessary.
> 
>> Regards
>> Mickael
>>
>> On 10/16/19 12:56, Chuhong Yuan wrote:
>>> mipid02_probe misses a check for devm_gpiod_get_optional and may miss
>>> the failure.
>>> Add a check to fix the problem.
>>>
>>> Signed-off-by: Chuhong Yuan <hslester96@gmail.com>
>>> ---
>>>  drivers/media/i2c/st-mipid02.c | 3 +++
>>>  1 file changed, 3 insertions(+)
>>>
>>> diff --git a/drivers/media/i2c/st-mipid02.c b/drivers/media/i2c/st-mipid02.c
>>> index 81285b8d5cfb..d38e888b0a43 100644
>>> --- a/drivers/media/i2c/st-mipid02.c
>>> +++ b/drivers/media/i2c/st-mipid02.c
>>> @@ -971,6 +971,9 @@ static int mipid02_probe(struct i2c_client *client)
>>>       bridge->reset_gpio = devm_gpiod_get_optional(dev, "reset",
>>>                                                    GPIOD_OUT_HIGH);
>>>
>>> +     if (IS_ERR(bridge->reset_gpio))
>>> +             return PTR_ERR(bridge->reset_gpio);
>>> +
>>>       ret = mipid02_get_regulators(bridge);
>>>       if (ret) {
>>>               dev_err(dev, "failed to get regulators %d", ret);
>>>

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2019-10-17 12:24 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-10-16 10:56 [PATCH] media: st-mipid02: add a check for devm_gpiod_get_optional Chuhong Yuan
2019-10-17  5:43 ` Mickael GUENE
2019-10-17  7:48   ` Chuhong Yuan
2019-10-17 12:24     ` Mickael GUENE

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).