media: atomisp: Fix smatch warnings caused by atomisp custom assert() usage
authorHans de Goede <hdegoede@redhat.com>
Sun, 30 Jul 2023 15:33:42 +0000 (17:33 +0200)
committerMauro Carvalho Chehab <mchehab@kernel.org>
Thu, 10 Aug 2023 05:58:32 +0000 (07:58 +0200)
commit7b4846b6515483396af706329cb51794eb6afb6d
treef55856186b7a5686365fdad7c88974e8d36af18d
parenta2c77032465711e4ee34dbeb5491938aedccffdb
media: atomisp: Fix smatch warnings caused by atomisp custom assert() usage

The atomisp code base has a custom assert() macro, a couple of functions
use this in a construction like the following:

   assert(pipe);
   assert(pipe->stream);
   if ((!pipe) || (!pipe->stream)) {
           ia_css_debug_dtrace(IA_CSS_DEBUG_TRACE_PRIVATE,
                               "allocate_mipi_frames(%p) exit: ...\n",
                               pipe);
           return -EINVAL;
   }

The second assert is seen by smatch as dereferencing "pipe" in the above
example (and dereferencing "dvs_6axis_config" in the other case).

Following by the dereferenced variable being checked (a second time)
in the following if () statement.

This triggers the following smatch warnings:
drivers/staging/media/atomisp/pci/sh_css_mipi.c:356 allocate_mipi_frames() warn: variable dereferenced before check 'pipe' (see line 355)
drivers/staging/media/atomisp/pci/sh_css_mipi.c:562 send_mipi_frames() warn: variable dereferenced before check 'pipe' (see line 561)
drivers/staging/media/atomisp/pci/sh_css_param_dvs.c:208 free_dvs_6axis_table() warn: variable dereferenced before check 'dvs_6axis_config' (see line 206)

The custom assert() macro actually expands to a BUG() call and BUG()
calls should not be used in the kernel.

Remove the assert() calls to fix the smatch warnings and in case of
[allocate|send]_mipi_frames() also remove the if () return -EINVAL
block since these functions are never called with a NULL pipe.

Reported-by: Hans Verkuil <hverkuil-cisco@xs4all.nl>
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Signed-off-by: Hans Verkuil <hverkuil-cisco@xs4all.nl>
drivers/staging/media/atomisp/pci/sh_css_mipi.c
drivers/staging/media/atomisp/pci/sh_css_param_dvs.c