linux-media.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCHv2] fix GCC enum warning
@ 2020-08-03 21:39 Rosen Penev
  2020-08-20 12:26 ` Hans Verkuil
  0 siblings, 1 reply; 5+ messages in thread
From: Rosen Penev @ 2020-08-03 21:39 UTC (permalink / raw)
  To: linux-media

Found with -Wenum-compare

../utils/common/v4l-helpers.h:880:36: warning: enumerated and
non-enumerated type in conditional expression [-Wextra]
  880 |  return hsv_enc < V4L2_HSV_ENC_180 ? V4L2_HSV_ENC_180 : hsv_enc;

Signed-off-by: Rosen Penev <rosenp@gmail.com>
---
 v2: Added warning message.
 utils/common/v4l-helpers.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/utils/common/v4l-helpers.h b/utils/common/v4l-helpers.h
index e093e717..edd21c16 100644
--- a/utils/common/v4l-helpers.h
+++ b/utils/common/v4l-helpers.h
@@ -877,7 +877,7 @@ v4l_format_g_hsv_enc(const struct v4l2_format *fmt)
 {
 	unsigned hsv_enc = v4l_format_g_ycbcr_enc(fmt);
 
-	return hsv_enc < V4L2_HSV_ENC_180 ? V4L2_HSV_ENC_180 : hsv_enc;
+	return hsv_enc < V4L2_HSV_ENC_180 ? unsigned(V4L2_HSV_ENC_180) : hsv_enc;
 }
 
 static inline void v4l_format_s_quantization(struct v4l2_format *fmt,
-- 
2.26.2


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

* Re: [PATCHv2] fix GCC enum warning
  2020-08-03 21:39 [PATCHv2] fix GCC enum warning Rosen Penev
@ 2020-08-20 12:26 ` Hans Verkuil
  2020-08-20 22:12   ` Rosen Penev
  0 siblings, 1 reply; 5+ messages in thread
From: Hans Verkuil @ 2020-08-20 12:26 UTC (permalink / raw)
  To: Rosen Penev, linux-media

On 03/08/2020 23:39, Rosen Penev wrote:
> Found with -Wenum-compare
> 
> ../utils/common/v4l-helpers.h:880:36: warning: enumerated and
> non-enumerated type in conditional expression [-Wextra]
>   880 |  return hsv_enc < V4L2_HSV_ENC_180 ? V4L2_HSV_ENC_180 : hsv_enc;
> 
> Signed-off-by: Rosen Penev <rosenp@gmail.com>
> ---
>  v2: Added warning message.
>  utils/common/v4l-helpers.h | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/utils/common/v4l-helpers.h b/utils/common/v4l-helpers.h
> index e093e717..edd21c16 100644
> --- a/utils/common/v4l-helpers.h
> +++ b/utils/common/v4l-helpers.h
> @@ -877,7 +877,7 @@ v4l_format_g_hsv_enc(const struct v4l2_format *fmt)
>  {
>  	unsigned hsv_enc = v4l_format_g_ycbcr_enc(fmt);

Does the warning go away if you replace 'unsigned' with enum v4l2_hsv_encoding?

I would like that a lot better than casting V4L2_HSV_ENC_180.

Regards,

	Hans

>  
> -	return hsv_enc < V4L2_HSV_ENC_180 ? V4L2_HSV_ENC_180 : hsv_enc;
> +	return hsv_enc < V4L2_HSV_ENC_180 ? unsigned(V4L2_HSV_ENC_180) : hsv_enc;
>  }
>  
>  static inline void v4l_format_s_quantization(struct v4l2_format *fmt,
> 


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

* Re: [PATCHv2] fix GCC enum warning
  2020-08-20 12:26 ` Hans Verkuil
@ 2020-08-20 22:12   ` Rosen Penev
  2020-09-09 14:01     ` Hans Verkuil
  0 siblings, 1 reply; 5+ messages in thread
From: Rosen Penev @ 2020-08-20 22:12 UTC (permalink / raw)
  To: Hans Verkuil; +Cc: Linux Media Mailing List

On Thu, Aug 20, 2020 at 5:26 AM Hans Verkuil <hverkuil@xs4all.nl> wrote:
>
> On 03/08/2020 23:39, Rosen Penev wrote:
> > Found with -Wenum-compare
> >
> > ../utils/common/v4l-helpers.h:880:36: warning: enumerated and
> > non-enumerated type in conditional expression [-Wextra]
> >   880 |  return hsv_enc < V4L2_HSV_ENC_180 ? V4L2_HSV_ENC_180 : hsv_enc;
> >
> > Signed-off-by: Rosen Penev <rosenp@gmail.com>
> > ---
> >  v2: Added warning message.
> >  utils/common/v4l-helpers.h | 2 +-
> >  1 file changed, 1 insertion(+), 1 deletion(-)
> >
> > diff --git a/utils/common/v4l-helpers.h b/utils/common/v4l-helpers.h
> > index e093e717..edd21c16 100644
> > --- a/utils/common/v4l-helpers.h
> > +++ b/utils/common/v4l-helpers.h
> > @@ -877,7 +877,7 @@ v4l_format_g_hsv_enc(const struct v4l2_format *fmt)
> >  {
> >       unsigned hsv_enc = v4l_format_g_ycbcr_enc(fmt);
>
> Does the warning go away if you replace 'unsigned' with enum v4l2_hsv_encoding?
../utils/common/v4l-helpers.h:878:25: error: cannot initialize a
variable of type 'enum v4l2_hsv_encoding' with an rvalue of type
'unsigned int'
        enum v4l2_hsv_encoding hsv_enc = v4l_format_g_ycbcr_enc(fmt);

>
> I would like that a lot better than casting V4L2_HSV_ENC_180.
>
> Regards,
>
>         Hans
>
> >
> > -     return hsv_enc < V4L2_HSV_ENC_180 ? V4L2_HSV_ENC_180 : hsv_enc;
> > +     return hsv_enc < V4L2_HSV_ENC_180 ? unsigned(V4L2_HSV_ENC_180) : hsv_enc;
> >  }
> >
> >  static inline void v4l_format_s_quantization(struct v4l2_format *fmt,
> >
>

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

* Re: [PATCHv2] fix GCC enum warning
  2020-08-20 22:12   ` Rosen Penev
@ 2020-09-09 14:01     ` Hans Verkuil
  2020-09-10  8:44       ` Rosen Penev
  0 siblings, 1 reply; 5+ messages in thread
From: Hans Verkuil @ 2020-09-09 14:01 UTC (permalink / raw)
  To: Rosen Penev; +Cc: Linux Media Mailing List

On 21/08/2020 00:12, Rosen Penev wrote:
> On Thu, Aug 20, 2020 at 5:26 AM Hans Verkuil <hverkuil@xs4all.nl> wrote:
>>
>> On 03/08/2020 23:39, Rosen Penev wrote:
>>> Found with -Wenum-compare
>>>
>>> ../utils/common/v4l-helpers.h:880:36: warning: enumerated and
>>> non-enumerated type in conditional expression [-Wextra]
>>>   880 |  return hsv_enc < V4L2_HSV_ENC_180 ? V4L2_HSV_ENC_180 : hsv_enc;
>>>
>>> Signed-off-by: Rosen Penev <rosenp@gmail.com>
>>> ---
>>>  v2: Added warning message.
>>>  utils/common/v4l-helpers.h | 2 +-
>>>  1 file changed, 1 insertion(+), 1 deletion(-)
>>>
>>> diff --git a/utils/common/v4l-helpers.h b/utils/common/v4l-helpers.h
>>> index e093e717..edd21c16 100644
>>> --- a/utils/common/v4l-helpers.h
>>> +++ b/utils/common/v4l-helpers.h
>>> @@ -877,7 +877,7 @@ v4l_format_g_hsv_enc(const struct v4l2_format *fmt)
>>>  {
>>>       unsigned hsv_enc = v4l_format_g_ycbcr_enc(fmt);
>>
>> Does the warning go away if you replace 'unsigned' with enum v4l2_hsv_encoding?
> ../utils/common/v4l-helpers.h:878:25: error: cannot initialize a
> variable of type 'enum v4l2_hsv_encoding' with an rvalue of type
> 'unsigned int'
>         enum v4l2_hsv_encoding hsv_enc = v4l_format_g_ycbcr_enc(fmt);

Urgh.

How about this:

	if (hsv_enc < V4L2_HSV_ENC_180)
		return V4L2_HSV_ENC_180;
	return hsv_enc;

Regards,

	Hans

> 
>>
>> I would like that a lot better than casting V4L2_HSV_ENC_180.
>>
>> Regards,
>>
>>         Hans
>>
>>>
>>> -     return hsv_enc < V4L2_HSV_ENC_180 ? V4L2_HSV_ENC_180 : hsv_enc;
>>> +     return hsv_enc < V4L2_HSV_ENC_180 ? unsigned(V4L2_HSV_ENC_180) : hsv_enc;
>>>  }
>>>
>>>  static inline void v4l_format_s_quantization(struct v4l2_format *fmt,
>>>
>>


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

* Re: [PATCHv2] fix GCC enum warning
  2020-09-09 14:01     ` Hans Verkuil
@ 2020-09-10  8:44       ` Rosen Penev
  0 siblings, 0 replies; 5+ messages in thread
From: Rosen Penev @ 2020-09-10  8:44 UTC (permalink / raw)
  To: Hans Verkuil; +Cc: Linux Media Mailing List

On Wed, Sep 9, 2020 at 7:01 AM Hans Verkuil <hverkuil@xs4all.nl> wrote:
>
> On 21/08/2020 00:12, Rosen Penev wrote:
> > On Thu, Aug 20, 2020 at 5:26 AM Hans Verkuil <hverkuil@xs4all.nl> wrote:
> >>
> >> On 03/08/2020 23:39, Rosen Penev wrote:
> >>> Found with -Wenum-compare
> >>>
> >>> ../utils/common/v4l-helpers.h:880:36: warning: enumerated and
> >>> non-enumerated type in conditional expression [-Wextra]
> >>>   880 |  return hsv_enc < V4L2_HSV_ENC_180 ? V4L2_HSV_ENC_180 : hsv_enc;
> >>>
> >>> Signed-off-by: Rosen Penev <rosenp@gmail.com>
> >>> ---
> >>>  v2: Added warning message.
> >>>  utils/common/v4l-helpers.h | 2 +-
> >>>  1 file changed, 1 insertion(+), 1 deletion(-)
> >>>
> >>> diff --git a/utils/common/v4l-helpers.h b/utils/common/v4l-helpers.h
> >>> index e093e717..edd21c16 100644
> >>> --- a/utils/common/v4l-helpers.h
> >>> +++ b/utils/common/v4l-helpers.h
> >>> @@ -877,7 +877,7 @@ v4l_format_g_hsv_enc(const struct v4l2_format *fmt)
> >>>  {
> >>>       unsigned hsv_enc = v4l_format_g_ycbcr_enc(fmt);
> >>
> >> Does the warning go away if you replace 'unsigned' with enum v4l2_hsv_encoding?
> > ../utils/common/v4l-helpers.h:878:25: error: cannot initialize a
> > variable of type 'enum v4l2_hsv_encoding' with an rvalue of type
> > 'unsigned int'
> >         enum v4l2_hsv_encoding hsv_enc = v4l_format_g_ycbcr_enc(fmt);
>
> Urgh.
>
> How about this:
>
>         if (hsv_enc < V4L2_HSV_ENC_180)
>                 return V4L2_HSV_ENC_180;
>         return hsv_enc;
Huh. That seems to have done it.
>
> Regards,
>
>         Hans
>
> >
> >>
> >> I would like that a lot better than casting V4L2_HSV_ENC_180.
> >>
> >> Regards,
> >>
> >>         Hans
> >>
> >>>
> >>> -     return hsv_enc < V4L2_HSV_ENC_180 ? V4L2_HSV_ENC_180 : hsv_enc;
> >>> +     return hsv_enc < V4L2_HSV_ENC_180 ? unsigned(V4L2_HSV_ENC_180) : hsv_enc;
> >>>  }
> >>>
> >>>  static inline void v4l_format_s_quantization(struct v4l2_format *fmt,
> >>>
> >>
>

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

end of thread, other threads:[~2020-09-10  8:46 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-08-03 21:39 [PATCHv2] fix GCC enum warning Rosen Penev
2020-08-20 12:26 ` Hans Verkuil
2020-08-20 22:12   ` Rosen Penev
2020-09-09 14:01     ` Hans Verkuil
2020-09-10  8:44       ` Rosen Penev

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