Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

media: atomisp: don't pass a pointer to a local variable

As warned by gcc 12.1:

drivers/staging/media/atomisp/pci/runtime/rmgr/src/rmgr_vbuf.c: In function 'ia_css_rmgr_acq_vbuf':
drivers/staging/media/atomisp/pci/runtime/rmgr/src/rmgr_vbuf.c:275:33: error: storing the address of local variable 'h' in '*handle' [-Werror=dangling-pointer=]
275 | *handle = &h;
| ~~~~~~~~^~~~
drivers/staging/media/atomisp/pci/runtime/rmgr/src/rmgr_vbuf.c:257:40: note: 'h' declared here
257 | struct ia_css_rmgr_vbuf_handle h;
| ^
drivers/staging/media/atomisp/pci/runtime/rmgr/src/rmgr_vbuf.c:257:40: note: 'handle' declared here
cc1: all warnings being treated as errors

The logic uses a temporary struct to update the handler, but,
instead of copying the value to the pointer sent by the caller, it
replaces it with the content with a local variable. That's wrong, and
may lead the caller to use a weird value.

Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>

+2 -2
+2 -2
drivers/staging/media/atomisp/pci/runtime/rmgr/src/rmgr_vbuf.c
··· 254 254 void ia_css_rmgr_acq_vbuf(struct ia_css_rmgr_vbuf_pool *pool, 255 255 struct ia_css_rmgr_vbuf_handle **handle) 256 256 { 257 - struct ia_css_rmgr_vbuf_handle h; 257 + struct ia_css_rmgr_vbuf_handle h = { 0 }; 258 258 259 259 if ((!pool) || (!handle) || (!*handle)) { 260 260 IA_CSS_LOG("Invalid inputs"); ··· 272 272 h.size = (*handle)->size; 273 273 /* release ref to current buffer */ 274 274 ia_css_rmgr_refcount_release_vbuf(handle); 275 - *handle = &h; 275 + **handle = h; 276 276 } 277 277 /* get new buffer for needed size */ 278 278 if ((*handle)->vptr == 0x0) {