]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
drm/panel: himax-hx8279: Always initialize goa_{even,odd}_valid in hx8279_check_goa_c...
authorNathan Chancellor <nathan@kernel.org>
Wed, 23 Apr 2025 17:41:41 +0000 (10:41 -0700)
committerNeil Armstrong <neil.armstrong@linaro.org>
Thu, 24 Apr 2025 08:19:10 +0000 (10:19 +0200)
Clang warns (or errors with CONFIG_WERROR=y):

  drivers/gpu/drm/panel/panel-himax-hx8279.c:838:6: error: variable 'goa_even_valid' is used uninitialized whenever 'if' condition is false [-Werror,-Wsometimes-uninitialized]
    838 |         if (num_zero == ARRAY_SIZE(desc->goa_even_timing))
        |             ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  drivers/gpu/drm/panel/panel-himax-hx8279.c:842:23: note: uninitialized use occurs here
    842 |         if (goa_odd_valid != goa_even_valid)
        |                              ^~~~~~~~~~~~~~
  drivers/gpu/drm/panel/panel-himax-hx8279.c:838:2: note: remove the 'if' if its condition is always true
    838 |         if (num_zero == ARRAY_SIZE(desc->goa_even_timing))
        |         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    839 |                 goa_even_valid = false;
  drivers/gpu/drm/panel/panel-himax-hx8279.c:818:36: note: initialize the variable 'goa_even_valid' to silence this warning
    818 |         bool goa_odd_valid, goa_even_valid;
        |                                           ^
        |                                            = 0

Even though only the even valid variable gets flagged, both valid
variables appear to have the same issue of possibly being used
uninitialized if the if statement initializing them to false is not
taken.

Turn the if statement then variable assignment into a single variable
assignment, which states that the configuration is valid when there are
not all zeros, clearing up the warning since the variable will always be
initialized.

Fixes: 38d42c261389 ("drm: panel: Add driver for Himax HX8279 DDIC panels")
Suggested-by: AngeloGioacchino Del Regno <angelogioacchino.delregno@collabora.com>
Reviewed-by: AngeloGioacchino Del Regno <angelogioacchino.delregno@collabora.com>
Signed-off-by: Nathan Chancellor <nathan@kernel.org>
Reviewed-by: Neil Armstrong <neil.armstrong@linaro.org>
Link: https://lore.kernel.org/r/20250423-panel-himax-hx8279-fix-sometimes-uninitialized-v2-1-fc501c6558d9@kernel.org
Signed-off-by: Neil Armstrong <neil.armstrong@linaro.org>
Link: https://lore.kernel.org/r/20250423-panel-himax-hx8279-fix-sometimes-uninitialized-v2-1-fc501c6558d9@kernel.org
drivers/gpu/drm/panel/panel-himax-hx8279.c

index b48b350b62da3ee1b64393aa0eaf35c0c22bfee7..fb302d1f91b92e82c3cfe27b0d30a39a16005793 100644 (file)
@@ -825,8 +825,7 @@ static int hx8279_check_goa_config(struct hx8279 *hx, struct device *dev)
                        num_zero++;
        }
 
-       if (num_zero == ARRAY_SIZE(desc->goa_odd_timing))
-               goa_odd_valid = false;
+       goa_odd_valid = (num_zero != ARRAY_SIZE(desc->goa_odd_timing));
 
        /* Up to 3 zeroes is a valid config. Check them all. */
        num_zero = 1;
@@ -835,8 +834,7 @@ static int hx8279_check_goa_config(struct hx8279 *hx, struct device *dev)
                        num_zero++;
        }
 
-       if (num_zero == ARRAY_SIZE(desc->goa_even_timing))
-               goa_even_valid = false;
+       goa_even_valid = (num_zero != ARRAY_SIZE(desc->goa_even_timing));
 
        /* Programming one without the other would make no sense! */
        if (goa_odd_valid != goa_even_valid)