[bug report] backlight: mp3309c: Add support for MPS MP3309C

Flavio Suligoi f.suligoi at asem.it
Tue Nov 28 08:24:21 UTC 2023


Hi Dan,

Thanks for the report, I'll fix the bug as soon as possible.

Regards,
Flavio

> -----Original Message-----
> From: Dan Carpenter <dan.carpenter at linaro.org>
> Sent: Tuesday, November 28, 2023 8:20 AM
> To: Flavio Suligoi <f.suligoi at asem.it>
> Cc: dri-devel at lists.freedesktop.org
> Subject: [bug report] backlight: mp3309c: Add support for MPS MP3309C
> 
> Hello Flavio Suligoi,
> 
> The patch 2e914516a58c: "backlight: mp3309c: Add support for MPS
> MP3309C" from Nov 16, 2023 (linux-next), leads to the following
> Smatch static checker warning:
> 
> 	drivers/video/backlight/mp3309c.c:277 pm3309c_parse_dt_node()
> 	error: uninitialized symbol 'prop_levels'.
> 
> drivers/video/backlight/mp3309c.c
>     202 static int pm3309c_parse_dt_node(struct mp3309c_chip *chip,
>     203                                  struct mp3309c_platform_data
> *pdata)
>     204 {
>     205         struct device_node *node = chip->dev->of_node;
>     206         struct property *prop_pwms, *prop_levels;
>     207         int length = 0;
>     208         int ret, i;
>     209         unsigned int num_levels, tmp_value;
>     210
>     211         if (!node) {
>     212                 dev_err(chip->dev, "failed to get DT node\n");
>     213                 return -ENODEV;
>     214         }
>     215
>     216         /*
>     217          * Dimming mode: the MP3309C provides two dimming
> control mode:
>     218          *
>     219          * - PWM mode
>     220          * - Analog by I2C control mode (default)
>     221          *
>     222          * I2C control mode is assumed as default but, if the
> pwms property is
>     223          * found in the backlight node, the mode switches to PWM
> mode.
>     224          */
>     225         pdata->dimming_mode = DIMMING_ANALOG_I2C;
>     226         prop_pwms = of_find_property(node, "pwms", &length);
>     227         if (prop_pwms) {
>     228                 chip->pwmd = devm_pwm_get(chip->dev, NULL);
>     229                 if (IS_ERR(chip->pwmd))
>     230                         return dev_err_probe(chip->dev,
> PTR_ERR(chip->pwmd),
>     231                                              "error getting pwm
> data\n");
>     232                 pdata->dimming_mode = DIMMING_PWM;
>     233                 pwm_apply_args(chip->pwmd);
>     234         }
>     235
>     236         /*
>     237          * In I2C control mode the dimming levels (0..31) are
> fixed by the
>     238          * hardware, while in PWM control mode they can be
> chosen by the user,
>     239          * to allow nonlinear mappings.
>     240          */
>     241         if  (pdata->dimming_mode == DIMMING_ANALOG_I2C) {
>     242                 /*
>     243                  * Analog (by I2C commands) control mode: fixed
> 0..31 brightness
>     244                  * levels
>     245                  */
>     246                 num_levels = ANALOG_I2C_NUM_LEVELS;
>     247
>     248                 /* Enable GPIO used in I2C dimming mode only */
>     249                 chip->enable_gpio = devm_gpiod_get(chip->dev,
> "enable",
>     250
> GPIOD_OUT_HIGH);
>     251                 if (IS_ERR(chip->enable_gpio))
>     252                         return dev_err_probe(chip->dev,
>     253                                              PTR_ERR(chip-
> >enable_gpio),
>     254                                              "error getting
> enable gpio\n");
> 
> prop_levels not initialized on this path.
> 
>     255         } else {
>     256                 /*
>     257                  * PWM control mode: check for brightness level
> in DT
>     258                  */
>     259                 prop_levels = of_find_property(node,
> "brightness-levels",
>     260                                                &length);
>     261                 if (prop_levels) {
>     262                         /* Read brightness levels from DT */
>     263                         num_levels = length / sizeof(u32);
>     264                         if (num_levels < 2)
>     265                                 return -EINVAL;
>     266                 } else {
>     267                         /* Use default brightness levels */
>     268                         num_levels =
> MP3309C_PWM_DEFAULT_NUM_LEVELS;
>     269                 }
>     270         }
>     271
>     272         /* Fill brightness levels array */
>     273         pdata->levels = devm_kcalloc(chip->dev, num_levels,
>     274                                      sizeof(*pdata->levels),
> GFP_KERNEL);
>     275         if (!pdata->levels)
>     276                 return -ENOMEM;
> --> 277         if (prop_levels) {
>                     ^^^^^^^^^^^
> Uninitialized
> 
>     278                 ret = of_property_read_u32_array(node,
> "brightness-levels",
>     279                                                  pdata->levels,
>     280                                                  num_levels);
>     281                 if (ret < 0)
>     282                         return ret;
>     283         } else {
>     284                 for (i = 0; i < num_levels; i++)
>     285                         pdata->levels[i] = i;
>     286         }
>     287
>     288         pdata->max_brightness = num_levels - 1;
>     289
>     290         ret = of_property_read_u32(node, "default-brightness",
>     291                                    &pdata->default_brightness);
>     292         if (ret)
>     293                 pdata->default_brightness = pdata-
> >max_brightness;
>     294         if (pdata->default_brightness > pdata->max_brightness) {
>     295                 dev_err(chip->dev,
>     296                         "default brightness exceeds max
> brightness\n");
>     297                 pdata->default_brightness = pdata-
> >max_brightness;
>     298         }
>     299
>     300         /*
> 
> regards,
> dan carpenter


More information about the dri-devel mailing list