diff mbox series

[1/2,media] cec: Move capability check inside #if

Message ID 20170404123219.22040-1-lee.jones@linaro.org
State New
Headers show
Series [1/2,media] cec: Move capability check inside #if | expand

Commit Message

Lee Jones April 4, 2017, 12:32 p.m. UTC
If CONFIG_RC_CORE is not enabled then none of the RC code will be
executed anyway, so we're placing the capability check inside the

Signed-off-by: Lee Jones <lee.jones@linaro.org>

---
 drivers/media/cec/cec-core.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

-- 
2.9.3

Comments

Hans Verkuil April 4, 2017, 12:39 p.m. UTC | #1
On 04/04/2017 02:32 PM, Lee Jones wrote:
> If CONFIG_RC_CORE is not enabled then none of the RC code will be

> executed anyway, so we're placing the capability check inside the

> 

> Signed-off-by: Lee Jones <lee.jones@linaro.org>

> ---

>  drivers/media/cec/cec-core.c | 2 +-

>  1 file changed, 1 insertion(+), 1 deletion(-)

> 

> diff --git a/drivers/media/cec/cec-core.c b/drivers/media/cec/cec-core.c

> index 37217e2..06a312c 100644

> --- a/drivers/media/cec/cec-core.c

> +++ b/drivers/media/cec/cec-core.c

> @@ -234,10 +234,10 @@ struct cec_adapter *cec_allocate_adapter(const struct cec_adap_ops *ops,

>  		return ERR_PTR(res);

>  	}

>  

> +#if IS_REACHABLE(CONFIG_RC_CORE)

>  	if (!(caps & CEC_CAP_RC))

>  		return adap;

>  

> -#if IS_REACHABLE(CONFIG_RC_CORE)

>  	/* Prepare the RC input device */

>  	adap->rc = rc_allocate_device(RC_DRIVER_SCANCODE);

>  	if (!adap->rc) {

> 


Not true, there is an #else further down.

That said, this code is clearly a bit confusing.

It would be better if at the beginning of the function we'd have this:

#if !IS_REACHABLE(CONFIG_RC_CORE)
	caps &= ~CEC_CAP_RC;
#endif

and then drop the #else bit and (as you do in this patch) move the #if up.

Can you make a new patch for this?

Thanks!

	Hans
Hans Verkuil April 4, 2017, 12:58 p.m. UTC | #2
On 04/04/2017 02:54 PM, Lee Jones wrote:
> On Tue, 04 Apr 2017, Hans Verkuil wrote:

> 

>> On 04/04/2017 02:32 PM, Lee Jones wrote:

>>> If CONFIG_RC_CORE is not enabled then none of the RC code will be

>>> executed anyway, so we're placing the capability check inside the

>>>

>>> Signed-off-by: Lee Jones <lee.jones@linaro.org>

>>> ---

>>>  drivers/media/cec/cec-core.c | 2 +-

>>>  1 file changed, 1 insertion(+), 1 deletion(-)

>>>

>>> diff --git a/drivers/media/cec/cec-core.c b/drivers/media/cec/cec-core.c

>>> index 37217e2..06a312c 100644

>>> --- a/drivers/media/cec/cec-core.c

>>> +++ b/drivers/media/cec/cec-core.c

>>> @@ -234,10 +234,10 @@ struct cec_adapter *cec_allocate_adapter(const struct cec_adap_ops *ops,

>>>  		return ERR_PTR(res);

>>>  	}

>>>  

>>> +#if IS_REACHABLE(CONFIG_RC_CORE)

>>>  	if (!(caps & CEC_CAP_RC))

>>>  		return adap;

>>>  

>>> -#if IS_REACHABLE(CONFIG_RC_CORE)

>>>  	/* Prepare the RC input device */

>>>  	adap->rc = rc_allocate_device(RC_DRIVER_SCANCODE);

>>>  	if (!adap->rc) {

>>>

>>

>> Not true, there is an #else further down.

> 

> I saw the #else.  It's inert code that becomes function-less.


No, it isn't. It clears the CAP_RC bit so it isn't returned in the CEC_ADAP_G_CAPS ioctl.
Drivers set this cap bit if they want RC support (they typically want it), but if the
config option isn't there then the capability should be removed.

Regards,

	Hans

> 

>> That said, this code is clearly a bit confusing.

>>

>> It would be better if at the beginning of the function we'd have this:

>>

>> #if !IS_REACHABLE(CONFIG_RC_CORE)

>> 	caps &= ~CEC_CAP_RC;

>> #endif

>>

>> and then drop the #else bit and (as you do in this patch) move the #if up.

>>

>> Can you make a new patch for this?

> 

> Sure.

>
Lee Jones April 4, 2017, 1:01 p.m. UTC | #3
On Tue, 04 Apr 2017, Lee Jones wrote:

> On Tue, 04 Apr 2017, Hans Verkuil wrote:

> 

> > On 04/04/2017 02:32 PM, Lee Jones wrote:

> > > If CONFIG_RC_CORE is not enabled then none of the RC code will be

> > > executed anyway, so we're placing the capability check inside the

> > > 

> > > Signed-off-by: Lee Jones <lee.jones@linaro.org>

> > > ---

> > >  drivers/media/cec/cec-core.c | 2 +-

> > >  1 file changed, 1 insertion(+), 1 deletion(-)

> > > 

> > > diff --git a/drivers/media/cec/cec-core.c b/drivers/media/cec/cec-core.c

> > > index 37217e2..06a312c 100644

> > > --- a/drivers/media/cec/cec-core.c

> > > +++ b/drivers/media/cec/cec-core.c

> > > @@ -234,10 +234,10 @@ struct cec_adapter *cec_allocate_adapter(const struct cec_adap_ops *ops,

> > >  		return ERR_PTR(res);

> > >  	}

> > >  

> > > +#if IS_REACHABLE(CONFIG_RC_CORE)

> > >  	if (!(caps & CEC_CAP_RC))

> > >  		return adap;

> > >  

> > > -#if IS_REACHABLE(CONFIG_RC_CORE)

> > >  	/* Prepare the RC input device */

> > >  	adap->rc = rc_allocate_device(RC_DRIVER_SCANCODE);

> > >  	if (!adap->rc) {

> > > 

> > 

> > Not true, there is an #else further down.

> 

> I saw the #else.  It's inert code that becomes function-less.

> 

> > That said, this code is clearly a bit confusing.

> > 

> > It would be better if at the beginning of the function we'd have this:

> > 

> > #if !IS_REACHABLE(CONFIG_RC_CORE)

> > 	caps &= ~CEC_CAP_RC;

> > #endif

> > 

> > and then drop the #else bit and (as you do in this patch) move the #if up.

> > 

> > Can you make a new patch for this?

> 

> Sure.


No wait, sorry!  This patch is the correct fix.

'caps' is already indicating !CEC_CAP_RC, which is right.

What we're trying to do here is only consider looking at the
capabilities if the RC Core is enabled.  If it is not enabled, the #if
still does the right thing and makes sure that the caps are updated.

Please take another look at the semantics.

-- 
Lee Jones
Linaro STMicroelectronics Landing Team Lead
Linaro.org │ Open source software for ARM SoCs
Follow Linaro: Facebook | Twitter | Blog
Hans Verkuil April 4, 2017, 1:14 p.m. UTC | #4
On 04/04/2017 03:01 PM, Lee Jones wrote:
> On Tue, 04 Apr 2017, Lee Jones wrote:

> 

>> On Tue, 04 Apr 2017, Hans Verkuil wrote:

>>

>>> On 04/04/2017 02:32 PM, Lee Jones wrote:

>>>> If CONFIG_RC_CORE is not enabled then none of the RC code will be

>>>> executed anyway, so we're placing the capability check inside the

>>>>

>>>> Signed-off-by: Lee Jones <lee.jones@linaro.org>

>>>> ---

>>>>  drivers/media/cec/cec-core.c | 2 +-

>>>>  1 file changed, 1 insertion(+), 1 deletion(-)

>>>>

>>>> diff --git a/drivers/media/cec/cec-core.c b/drivers/media/cec/cec-core.c

>>>> index 37217e2..06a312c 100644

>>>> --- a/drivers/media/cec/cec-core.c

>>>> +++ b/drivers/media/cec/cec-core.c

>>>> @@ -234,10 +234,10 @@ struct cec_adapter *cec_allocate_adapter(const struct cec_adap_ops *ops,

>>>>  		return ERR_PTR(res);

>>>>  	}

>>>>  

>>>> +#if IS_REACHABLE(CONFIG_RC_CORE)

>>>>  	if (!(caps & CEC_CAP_RC))

>>>>  		return adap;

>>>>  

>>>> -#if IS_REACHABLE(CONFIG_RC_CORE)

>>>>  	/* Prepare the RC input device */

>>>>  	adap->rc = rc_allocate_device(RC_DRIVER_SCANCODE);

>>>>  	if (!adap->rc) {

>>>>

>>>

>>> Not true, there is an #else further down.

>>

>> I saw the #else.  It's inert code that becomes function-less.

>>

>>> That said, this code is clearly a bit confusing.

>>>

>>> It would be better if at the beginning of the function we'd have this:

>>>

>>> #if !IS_REACHABLE(CONFIG_RC_CORE)

>>> 	caps &= ~CEC_CAP_RC;

>>> #endif

>>>

>>> and then drop the #else bit and (as you do in this patch) move the #if up.

>>>

>>> Can you make a new patch for this?

>>

>> Sure.

> 

> No wait, sorry!  This patch is the correct fix.

> 

> 'caps' is already indicating !CEC_CAP_RC, which is right.

> 

> What we're trying to do here is only consider looking at the

> capabilities if the RC Core is enabled.  If it is not enabled, the #if

> still does the right thing and makes sure that the caps are updated.

> 

> Please take another look at the semantics.


Ah, yes. You are right. But so am I: the code is just unnecessarily confusing
as is seen by this discussion.

I still would like to see a patch with my proposed solution. The control flow
is much easier to understand that way.

Regards,

	Hans
Lee Jones April 4, 2017, 1:30 p.m. UTC | #5
On Tue, 04 Apr 2017, Hans Verkuil wrote:

> On 04/04/2017 03:01 PM, Lee Jones wrote:

> > On Tue, 04 Apr 2017, Lee Jones wrote:

> > 

> >> On Tue, 04 Apr 2017, Hans Verkuil wrote:

> >>

> >>> On 04/04/2017 02:32 PM, Lee Jones wrote:

> >>>> If CONFIG_RC_CORE is not enabled then none of the RC code will be

> >>>> executed anyway, so we're placing the capability check inside the

> >>>>

> >>>> Signed-off-by: Lee Jones <lee.jones@linaro.org>

> >>>> ---

> >>>>  drivers/media/cec/cec-core.c | 2 +-

> >>>>  1 file changed, 1 insertion(+), 1 deletion(-)

> >>>>

> >>>> diff --git a/drivers/media/cec/cec-core.c b/drivers/media/cec/cec-core.c

> >>>> index 37217e2..06a312c 100644

> >>>> --- a/drivers/media/cec/cec-core.c

> >>>> +++ b/drivers/media/cec/cec-core.c

> >>>> @@ -234,10 +234,10 @@ struct cec_adapter *cec_allocate_adapter(const struct cec_adap_ops *ops,

> >>>>  		return ERR_PTR(res);

> >>>>  	}

> >>>>  

> >>>> +#if IS_REACHABLE(CONFIG_RC_CORE)

> >>>>  	if (!(caps & CEC_CAP_RC))

> >>>>  		return adap;

> >>>>  

> >>>> -#if IS_REACHABLE(CONFIG_RC_CORE)

> >>>>  	/* Prepare the RC input device */

> >>>>  	adap->rc = rc_allocate_device(RC_DRIVER_SCANCODE);

> >>>>  	if (!adap->rc) {

> >>>>

> >>>

> >>> Not true, there is an #else further down.

> >>

> >> I saw the #else.  It's inert code that becomes function-less.

> >>

> >>> That said, this code is clearly a bit confusing.

> >>>

> >>> It would be better if at the beginning of the function we'd have this:

> >>>

> >>> #if !IS_REACHABLE(CONFIG_RC_CORE)

> >>> 	caps &= ~CEC_CAP_RC;

> >>> #endif

> >>>

> >>> and then drop the #else bit and (as you do in this patch) move the #if up.

> >>>

> >>> Can you make a new patch for this?

> >>

> >> Sure.

> > 

> > No wait, sorry!  This patch is the correct fix.

> > 

> > 'caps' is already indicating !CEC_CAP_RC, which is right.

> > 

> > What we're trying to do here is only consider looking at the

> > capabilities if the RC Core is enabled.  If it is not enabled, the #if

> > still does the right thing and makes sure that the caps are updated.

> > 

> > Please take another look at the semantics.

> 

> Ah, yes. You are right. But so am I: the code is just unnecessarily confusing

> as is seen by this discussion.

> 

> I still would like to see a patch with my proposed solution. The control flow

> is much easier to understand that way.


I have an idea.  Please bear with me.

-- 
Lee Jones
Linaro STMicroelectronics Landing Team Lead
Linaro.org │ Open source software for ARM SoCs
Follow Linaro: Facebook | Twitter | Blog
diff mbox series

Patch

diff --git a/drivers/media/cec/cec-core.c b/drivers/media/cec/cec-core.c
index 37217e2..06a312c 100644
--- a/drivers/media/cec/cec-core.c
+++ b/drivers/media/cec/cec-core.c
@@ -234,10 +234,10 @@  struct cec_adapter *cec_allocate_adapter(const struct cec_adap_ops *ops,
 		return ERR_PTR(res);
 	}
 
+#if IS_REACHABLE(CONFIG_RC_CORE)
 	if (!(caps & CEC_CAP_RC))
 		return adap;
 
-#if IS_REACHABLE(CONFIG_RC_CORE)
 	/* Prepare the RC input device */
 	adap->rc = rc_allocate_device(RC_DRIVER_SCANCODE);
 	if (!adap->rc) {