All of lore.kernel.org
 help / color / mirror / Atom feed
From: Hans Verkuil <hverkuil-cisco@xs4all.nl>
To: Shuah Khan <skhan@linuxfoundation.org>,
	mchehab@kernel.org, sakari.ailus@linux.intel.com,
	niklas.soderlund+renesas@ragnatech.se, ezequiel@collabora.com,
	paul.kocialkowski@bootlin.com
Cc: Randy Dunlap <rdunlap@infradead.org>,
	linux-media@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH 1/2] media: v4l2-core: Shifting signed 32-bit value by 31 bits error
Date: Thu, 6 Jun 2019 08:33:20 +0200	[thread overview]
Message-ID: <7819cae4-58e5-cbe1-ac9d-bca00d390066@xs4all.nl> (raw)
In-Reply-To: <8cc03625-f41d-6009-d50c-823e5f498dca@infradead.org>

On 6/6/19 5:22 AM, Randy Dunlap wrote:
> On 6/5/19 2:53 PM, Shuah Khan wrote:
>> Fix the following cppcheck error:
>>
>> Checking drivers/media/v4l2-core/v4l2-ioctl.c ...
>> [drivers/media/v4l2-core/v4l2-ioctl.c:1370]: (error) Shifting signed 32-bit value by 31 bits is undefined behaviour
>>
>> Signed-off-by: Shuah Khan <skhan@linuxfoundation.org>
>> ---
>>  drivers/media/v4l2-core/v4l2-ioctl.c | 2 +-
>>  1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> diff --git a/drivers/media/v4l2-core/v4l2-ioctl.c b/drivers/media/v4l2-core/v4l2-ioctl.c
>> index 6859bdac86fe..333e387bafeb 100644
>> --- a/drivers/media/v4l2-core/v4l2-ioctl.c
>> +++ b/drivers/media/v4l2-core/v4l2-ioctl.c
>> @@ -1364,7 +1364,7 @@ static void v4l_fill_fmtdesc(struct v4l2_fmtdesc *fmt)
>>  					(char)((fmt->pixelformat >> 8) & 0x7f),
>>  					(char)((fmt->pixelformat >> 16) & 0x7f),
>>  					(char)((fmt->pixelformat >> 24) & 0x7f),
>> -					(fmt->pixelformat & (1 << 31)) ? "-BE" : "");
>> +					(fmt->pixelformat & BIT(31)) ? "-BE" : "");
>>  			break;
>>  		}
>>  	}
>>
> 
> If this builds, I guess #define BIT(x) got pulled in indirectly
> since bits.h nor bitops.h is currently #included in that source file.
> 
> Documentation/process/submit-checklist.rst rule #1 says:
> 1) If you use a facility then #include the file that defines/declares
>    that facility.  Don't depend on other header files pulling in ones
>    that you use.
> 
> Please add #include <linux/bits or bitops.h>
> 

I'm not sure about this patch. '1 << 31' is used all over in the kernel,
including in public headers (e.g. media.h, videodev2.h).

It seems arbitrary to change it only here, but not anywhere else.

In this particular example for the fourcc handling I would prefer to just
use '1U << 31', both in v4l2-ioctl.c and videodev2.h.

A separate patch doing the same for MEDIA_ENT_ID_FLAG_NEXT in media.h would
probably be a good idea either: that way the public API at least will do
the right thing.

Regards,

	Hans

  reply	other threads:[~2019-06-06  6:33 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-06-05 21:53 [PATCH 0/2] Fixes to cppcheck errors in v4l2-ioctl.c Shuah Khan
2019-06-05 21:53 ` [PATCH 1/2] media: v4l2-core: Shifting signed 32-bit value by 31 bits error Shuah Khan
2019-06-06  3:22   ` Randy Dunlap
2019-06-06  6:33     ` Hans Verkuil [this message]
2019-06-11 19:42       ` Shuah Khan
2019-06-11 20:50         ` Hans Verkuil
2019-06-11 22:27           ` Shuah Khan
2019-06-12 23:04             ` Shuah Khan
2019-06-05 21:53 ` [PATCH 2/2] media: v4l2-core: fix uninitialized variable error Shuah Khan
2019-06-06  7:48   ` Hans Verkuil

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=7819cae4-58e5-cbe1-ac9d-bca00d390066@xs4all.nl \
    --to=hverkuil-cisco@xs4all.nl \
    --cc=ezequiel@collabora.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-media@vger.kernel.org \
    --cc=mchehab@kernel.org \
    --cc=niklas.soderlund+renesas@ragnatech.se \
    --cc=paul.kocialkowski@bootlin.com \
    --cc=rdunlap@infradead.org \
    --cc=sakari.ailus@linux.intel.com \
    --cc=skhan@linuxfoundation.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.