radeonsi: Move NULL check before dereference.
authorVinson Lee <vlee@freedesktop.org>
Sat, 7 May 2022 00:17:50 +0000 (17:17 -0700)
committerMarge Bot <emma+marge@anholt.net>
Wed, 11 May 2022 04:55:35 +0000 (04:55 +0000)
Fix defect reported by Coverity Scan.

Dereference before null check (REVERSE_INULL)
check_after_deref: Null-checking desc suggests that it may be
null, but it has already been dereferenced on all paths leading to
the check.

Fixes: 2f83dce059 ("radeonsi: don't report R64_*INT as a sampler format because it doesn't work")
Signed-off-by: Vinson Lee <vlee@freedesktop.org>
Reviewed-by: Marek Olšák <marek.olsak@amd.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/16380>

src/gallium/drivers/radeonsi/si_state.c

index f1b0866..8422029 100644 (file)
@@ -2188,6 +2188,9 @@ static bool si_is_sampler_format_supported(struct pipe_screen *screen, enum pipe
    struct si_screen *sscreen = (struct si_screen *)screen;
    const struct util_format_description *desc = util_format_description(format);
 
+   if (!desc)
+      return false;
+
    /* Samplers don't support 64 bits per channel. */
    if (desc->layout == UTIL_FORMAT_LAYOUT_PLAIN &&
        desc->channel[0].size == 64)
@@ -2200,9 +2203,6 @@ static bool si_is_sampler_format_supported(struct pipe_screen *screen, enum pipe
       return true;
    }
 
-   if (!desc)
-      return false;
-
    return si_translate_texformat(screen, format, desc,
                                  util_format_get_first_non_void_channel(format)) != ~0U;
 }