2024-03-25 16:24:54

by Ricardo Ribalda

[permalink] [raw]
Subject: [PATCH v2 0/3] media: Fix gcc warnings

drivers/staging/media/tegra-video/tegra20.c: In function ‘tegra20_vip_start_streaming’:
drivers/staging/media/tegra-video/tegra20.c:624:72: warning: ‘yuv_input_format’ may be used uninitialized [-Wmaybe-uninitialized]
624 | VI_INPUT_VIP_INPUT_ENABLE | main_input_format | yuv_input_format);
drivers/staging/media/tegra-video/tegra20.c:617:22: note: ‘yuv_input_format’ was declared here
617 | unsigned int yuv_input_format;
| ^~~~~~~~~~~~~~~~
drivers/media/radio/radio-shark2.c: In function ‘usb_shark_probe’:
drivers/media/radio/radio-shark2.c:191:17: warning: ‘%s’ directive output may be truncated writing up to 35 bytes into a region of size 32 [-Wformat-truncation=]
191 | .name = "%s:blue:",
| ^
In function ‘shark_register_leds’,
inlined from ‘usb_shark_probe’ at drivers/media/radio/radio-shark2.c:306:11:
drivers/media/radio/radio-shark2.c:212:17: note: ‘snprintf’ output between 7 and 42 bytes into a destination of size 32
212 | snprintf(shark->led_names[i], sizeof(shark->led_names[0]),
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
213 | shark->leds[i].name, shark->v4l2_dev.name);
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
drivers/media/radio/radio-shark2.c: In function ‘usb_shark_probe’:
drivers/media/radio/radio-shark2.c:197:17: warning: ‘%s’ directive output may be truncated writing up to 35 bytes into a region of size 32 [-Wformat-truncation=]
197 | .name = "%s:red:",
| ^
In function ‘shark_register_leds’,
inlined from ‘usb_shark_probe’ at drivers/media/radio/radio-shark2.c:306:11:
drivers/media/radio/radio-shark2.c:212:17: note: ‘snprintf’ output between 6 and 41 bytes into a destination of size 32
212 | snprintf(shark->led_names[i], sizeof(shark->led_names[0]),
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
213 | shark->leds[i].name, shark->v4l2_dev.name);
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
AR drivers/staging/media/tegra-video/built-in.a
AR drivers/staging/media/built-in.a
In file included from ./include/asm-generic/preempt.h:5,
from ./arch/arm/include/generated/asm/preempt.h:1,
from ./include/linux/preempt.h:79,
from ./include/linux/spinlock.h:56,
from ./include/linux/mmzone.h:8,
from ./include/linux/gfp.h:7,
from ./include/linux/umh.h:4,
from ./include/linux/kmod.h:9,
from ./include/linux/module.h:17,
from drivers/media/dvb-core/dvbdev.c:15:
In function ‘check_object_size’,
inlined from ‘check_copy_size’ at ./include/linux/thread_info.h:251:2,
inlined from ‘copy_from_user’ at ./include/linux/uaccess.h:182:6,
inlined from ‘dvb_usercopy’ at drivers/media/dvb-core/dvbdev.c:987:7:
./include/linux/thread_info.h:215:17: warning: ‘sbuf’ may be used uninitialized [-Wmaybe-uninitialized]
215 | __check_object_size(ptr, n, to_user);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
./include/linux/thread_info.h: In function ‘dvb_usercopy’:
./include/linux/thread_info.h:208:13: note: by argument 1 of type ‘const void *’ to ‘__check_object_size’ declared here
208 | extern void __check_object_size(const void *ptr, unsigned long n,
| ^~~~~~~~~~~~~~~~~~~
drivers/media/dvb-core/dvbdev.c:959:17: note: ‘sbuf’ declared here
959 | char sbuf[128];
| ^~~~
AR drivers/media/radio/built-in.a

Signed-off-by: Ricardo Ribalda <[email protected]>
---
Changes in v2: Thanks Thierry
- Make tegra20_vi_get_output_formats() and tegra20_vi_get_inut_formats,
consistent.
- Link to v1: https://lore.kernel.org/r/[email protected]

---
Ricardo Ribalda (3):
staging: media: tegra-video: Fix -Wmaybe-unitialized warn in gcc
media: radio-shark2: Avoid led_names truncations
media: dvbdev: Initialize sbuf

drivers/media/dvb-core/dvbdev.c | 2 +-
drivers/media/radio/radio-shark2.c | 2 +-
drivers/staging/media/tegra-video/tegra20.c | 1 +
3 files changed, 3 insertions(+), 2 deletions(-)
---
base-commit: b14257abe7057def6127f6fb2f14f9adc8acabdb
change-id: 20240323-gcc-arm-warnings-e4c142cb5ac0

Best regards,
--
Ricardo Ribalda <[email protected]>



2024-03-25 16:25:12

by Ricardo Ribalda

[permalink] [raw]
Subject: [PATCH v2 3/3] media: dvbdev: Initialize sbuf

Because the size passed to copy_from_user() cannot be known beforehand,
it needs to be checked during runtime with check_object_size. That makes
gcc believe that the content of sbuf can be used before init.

Fix:
/include/linux/thread_info.h:215:17: warning: ‘sbuf’ may be used uninitialized [-Wmaybe-uninitialized]

Signed-off-by: Ricardo Ribalda <[email protected]>
---
drivers/media/dvb-core/dvbdev.c | 2 +-
drivers/staging/media/tegra-video/tegra20.c | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/media/dvb-core/dvbdev.c b/drivers/media/dvb-core/dvbdev.c
index 733d0bc4b4cc3..b43695bc51e75 100644
--- a/drivers/media/dvb-core/dvbdev.c
+++ b/drivers/media/dvb-core/dvbdev.c
@@ -956,7 +956,7 @@ int dvb_usercopy(struct file *file,
int (*func)(struct file *file,
unsigned int cmd, void *arg))
{
- char sbuf[128];
+ char sbuf[128] = {};
void *mbuf = NULL;
void *parg = NULL;
int err = -EINVAL;
diff --git a/drivers/staging/media/tegra-video/tegra20.c b/drivers/staging/media/tegra-video/tegra20.c
index c39b52d0e4447..630e2ff987a37 100644
--- a/drivers/staging/media/tegra-video/tegra20.c
+++ b/drivers/staging/media/tegra-video/tegra20.c
@@ -164,6 +164,7 @@ static void tegra20_vi_get_input_formats(struct tegra_vi_channel *chan,
unsigned int input_mbus_code = chan->fmtinfo->code;

(*main_input_format) = VI_INPUT_INPUT_FORMAT_YUV422;
+ (*yuv_input_format) = VI_INPUT_YUV_INPUT_FORMAT_UYVY;

switch (input_mbus_code) {
case MEDIA_BUS_FMT_UYVY8_2X8:
@@ -176,7 +177,6 @@ static void tegra20_vi_get_input_formats(struct tegra_vi_channel *chan,
(*yuv_input_format) = VI_INPUT_YUV_INPUT_FORMAT_YUYV;
break;
case MEDIA_BUS_FMT_YVYU8_2X8:
- default:
(*yuv_input_format) = VI_INPUT_YUV_INPUT_FORMAT_YVYU;
break;
}

--
2.44.0.396.g6e790dbe36-goog


2024-03-25 16:29:47

by Ricardo Ribalda

[permalink] [raw]
Subject: [PATCH v2 1/3] staging: media: tegra-video: Fix -Wmaybe-unitialized warn in gcc

Make sure that tegra20_vi_get_input_formats always assign a value for
yuv_input_format.

Fix:
drivers/staging/media/tegra-video/tegra20.c:624:72: warning: ‘yuv_input_format’ may be used uninitialized [-Wmaybe-uninitialized]

Signed-off-by: Ricardo Ribalda <[email protected]>
---
drivers/staging/media/tegra-video/tegra20.c | 1 +
1 file changed, 1 insertion(+)

diff --git a/drivers/staging/media/tegra-video/tegra20.c b/drivers/staging/media/tegra-video/tegra20.c
index c25286772603c..c39b52d0e4447 100644
--- a/drivers/staging/media/tegra-video/tegra20.c
+++ b/drivers/staging/media/tegra-video/tegra20.c
@@ -176,6 +176,7 @@ static void tegra20_vi_get_input_formats(struct tegra_vi_channel *chan,
(*yuv_input_format) = VI_INPUT_YUV_INPUT_FORMAT_YUYV;
break;
case MEDIA_BUS_FMT_YVYU8_2X8:
+ default:
(*yuv_input_format) = VI_INPUT_YUV_INPUT_FORMAT_YVYU;
break;
}

--
2.44.0.396.g6e790dbe36-goog


2024-03-25 16:29:53

by Ricardo Ribalda

[permalink] [raw]
Subject: [PATCH v2 2/3] media: radio-shark2: Avoid led_names truncations

Increase the size of led_names so it can fit any valid v4l2 device name.

Fixes:
drivers/media/radio/radio-shark2.c:197:17: warning: ‘%s’ directive output may be truncated writing up to 35 bytes into a region of size 32 [-Wformat-truncation=]

Signed-off-by: Ricardo Ribalda <[email protected]>
---
drivers/media/radio/radio-shark2.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/media/radio/radio-shark2.c b/drivers/media/radio/radio-shark2.c
index f1c5c0a6a335c..e3e6aa87fe081 100644
--- a/drivers/media/radio/radio-shark2.c
+++ b/drivers/media/radio/radio-shark2.c
@@ -62,7 +62,7 @@ struct shark_device {
#ifdef SHARK_USE_LEDS
struct work_struct led_work;
struct led_classdev leds[NO_LEDS];
- char led_names[NO_LEDS][32];
+ char led_names[NO_LEDS][64];
atomic_t brightness[NO_LEDS];
unsigned long brightness_new;
#endif

--
2.44.0.396.g6e790dbe36-goog


2024-03-25 16:40:35

by Luca Ceresoli

[permalink] [raw]
Subject: Re: [PATCH v2 3/3] media: dvbdev: Initialize sbuf

Hello Ricardo,

On Mon, 25 Mar 2024 14:19:55 +0000
Ricardo Ribalda <[email protected]> wrote:

> Because the size passed to copy_from_user() cannot be known beforehand,
> it needs to be checked during runtime with check_object_size. That makes
> gcc believe that the content of sbuf can be used before init.
>
> Fix:
> ./include/linux/thread_info.h:215:17: warning: ‘sbuf’ may be used uninitialized [-Wmaybe-uninitialized]
>
> Signed-off-by: Ricardo Ribalda <[email protected]>
> ---
> drivers/media/dvb-core/dvbdev.c | 2 +-
> drivers/staging/media/tegra-video/tegra20.c | 2 +-
> 2 files changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/media/dvb-core/dvbdev.c b/drivers/media/dvb-core/dvbdev.c
> index 733d0bc4b4cc3..b43695bc51e75 100644
> --- a/drivers/media/dvb-core/dvbdev.c
> +++ b/drivers/media/dvb-core/dvbdev.c
> @@ -956,7 +956,7 @@ int dvb_usercopy(struct file *file,
> int (*func)(struct file *file,
> unsigned int cmd, void *arg))
> {
> - char sbuf[128];
> + char sbuf[128] = {};
> void *mbuf = NULL;
> void *parg = NULL;
> int err = -EINVAL;
> diff --git a/drivers/staging/media/tegra-video/tegra20.c b/drivers/staging/media/tegra-video/tegra20.c
> index c39b52d0e4447..630e2ff987a37 100644
> --- a/drivers/staging/media/tegra-video/tegra20.c
> +++ b/drivers/staging/media/tegra-video/tegra20.c
> @@ -164,6 +164,7 @@ static void tegra20_vi_get_input_formats(struct tegra_vi_channel *chan,
> unsigned int input_mbus_code = chan->fmtinfo->code;
>
> (*main_input_format) = VI_INPUT_INPUT_FORMAT_YUV422;
> + (*yuv_input_format) = VI_INPUT_YUV_INPUT_FORMAT_UYVY;

I agree with Thierry this seems to be the best fix, making this
function similar to tegra20_vi_get_output_formats().

However in this v2 your change ended up in patch 3 while it should be
in patch 1. I'm glad to add my Reviewed-by tag on a new version with
this fixed.

Luca

--
Luca Ceresoli, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com