linux-staging.lists.linux.dev archive mirror
 help / color / mirror / Atom feed
* [PATCH] media: atomisp: Perform a single memset() for union
@ 2021-07-11 14:51 Kees Cook
  2021-07-11 15:16 ` Sakari Ailus
  0 siblings, 1 reply; 2+ messages in thread
From: Kees Cook @ 2021-07-11 14:51 UTC (permalink / raw)
  To: Mauro Carvalho Chehab
  Cc: Kees Cook, Mauro Carvalho Chehab, Hans Verkuil, Sakari Ailus,
	Greg Kroah-Hartman, Martiros Shakhzadyan, linux-kernel,
	linux-media, linux-staging, linux-hardening

There is no need to memset() both dvs_grid_info and dvs_stat_grid_info
separately: they are part of the same union. Instead, just zero the
union itself. This additionally avoids a false positive (due to a
gcc optimization bug[1]) when building with the coming FORTIFY_SOURCE
improvements:

In function 'fortify_memset_chk',
    inlined from 'sh_css_pipe_get_grid_info' at drivers/staging/media/atomisp/pci/sh_css.c:5186:3,
    inlined from 'ia_css_stream_create' at drivers/staging/media/atomisp/pci/sh_css.c:9442:10:
./include/linux/fortify-string.h:199:4: warning: call to '__write_overflow_field' declared with attribute warning: detected write beyond size of field (1st parameter); maybe use struct_group()? [-Wattribute-warning]
  199 |    __write_overflow_field();
      |    ^~~~~~~~~~~~~~~~~~~~~~~~

[1] https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101419

Signed-off-by: Kees Cook <keescook@chromium.org>
---
 drivers/staging/media/atomisp/pci/sh_css.c | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)

diff --git a/drivers/staging/media/atomisp/pci/sh_css.c b/drivers/staging/media/atomisp/pci/sh_css.c
index d26b1301eeb7..ffa7f8a88a70 100644
--- a/drivers/staging/media/atomisp/pci/sh_css.c
+++ b/drivers/staging/media/atomisp/pci/sh_css.c
@@ -5181,10 +5181,7 @@ sh_css_pipe_get_grid_info(struct ia_css_pipe *pipe,
 		ia_css_binary_dvs_grid_info(binary, info, pipe);
 		ia_css_binary_dvs_stat_grid_info(binary, info, pipe);
 	} else {
-		memset(&info->dvs_grid.dvs_grid_info, 0,
-		       sizeof(info->dvs_grid.dvs_grid_info));
-		memset(&info->dvs_grid.dvs_stat_grid_info, 0,
-		       sizeof(info->dvs_grid.dvs_stat_grid_info));
+		memset(&info->dvs_grid, 0, sizeof(info->dvs_grid));
 	}
 
 	if (binary) {
-- 
2.30.2


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

* Re: [PATCH] media: atomisp: Perform a single memset() for union
  2021-07-11 14:51 [PATCH] media: atomisp: Perform a single memset() for union Kees Cook
@ 2021-07-11 15:16 ` Sakari Ailus
  0 siblings, 0 replies; 2+ messages in thread
From: Sakari Ailus @ 2021-07-11 15:16 UTC (permalink / raw)
  To: Kees Cook
  Cc: Mauro Carvalho Chehab, Mauro Carvalho Chehab, Hans Verkuil,
	Greg Kroah-Hartman, Martiros Shakhzadyan, linux-kernel,
	linux-media, linux-staging, linux-hardening

On Sun, Jul 11, 2021 at 07:51:01AM -0700, Kees Cook wrote:
> There is no need to memset() both dvs_grid_info and dvs_stat_grid_info
> separately: they are part of the same union. Instead, just zero the
> union itself. This additionally avoids a false positive (due to a
> gcc optimization bug[1]) when building with the coming FORTIFY_SOURCE
> improvements:
> 
> In function 'fortify_memset_chk',
>     inlined from 'sh_css_pipe_get_grid_info' at drivers/staging/media/atomisp/pci/sh_css.c:5186:3,
>     inlined from 'ia_css_stream_create' at drivers/staging/media/atomisp/pci/sh_css.c:9442:10:
> ./include/linux/fortify-string.h:199:4: warning: call to '__write_overflow_field' declared with attribute warning: detected write beyond size of field (1st parameter); maybe use struct_group()? [-Wattribute-warning]
>   199 |    __write_overflow_field();
>       |    ^~~~~~~~~~~~~~~~~~~~~~~~
> 
> [1] https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101419
> 
> Signed-off-by: Kees Cook <keescook@chromium.org>

Acked-by: Sakari Ailus <sakari.ailus@linux.intel.com>

-- 
Sakari Ailus

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

end of thread, other threads:[~2021-07-11 15:16 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-07-11 14:51 [PATCH] media: atomisp: Perform a single memset() for union Kees Cook
2021-07-11 15:16 ` Sakari Ailus

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