On Wed, 02 Dec 2026 23:10:58 +0000
[email protected] wrote:
> Thank you for your contribution! Sashiko AI review found 3 potential
> issues to consider:
> - [Medium] backlight: aw99703: default-brightness DT property ignored in
> aw99703_probe()
> - [Medium] backlight: aw99703: regulator leak and state desync in
> aw99703_set_brightness()
> - [Low] backlight: aw99703: unused struct aw99703_data fields and
> TURNCFG macros
> --
>
> commit 95c9396e9149f789acacb52aefc88017d878d71c
> Author: Andreas Kemnade <[email protected]>
>
> video: backlight: Add Awinic AW99703
>
> This commit adds a backlight driver for the Awinic AW99703 supporting
> brightness control over I2C.
>
> > diff --git a/drivers/video/backlight/aw99703.c
> > b/drivers/video/backlight/aw99703.c
> > new file mode 100644
> > index 0000000000000..ef310bda74513
> > --- /dev/null
> > +++ b/drivers/video/backlight/aw99703.c
>
> [ ... ]
>
> > +#define AW99703_REG_LEDLSB 0x06
> > +#define AW99703_REG_LEDMSB 0x07
> > +#define AW99703_REG_TURNCFG 0x09
>
> [ ... ]
>
> > +/* TURNCFG:0x09 */
> > +#define AW99703_TURNCFG_ON_TIM_MASK GENMASK(7, 4)
> > +#define AW99703_TURNCFG_OFF_TIM_MASK GENMASK(3, 0)
> > +
> > +#define MAX_BRIGHTNESS (2047)
> > +
> > +struct aw99703_data {
> > + struct device *dev;
> > + struct regmap *regmap;
> > + struct regulator *vin;
> > + unsigned int brightness;
> > + bool enable;
> > + u8 pwm_cfg;
> > + u8 full_scale_current;
> > + struct gpio_desc *hwen_gpio;
> > + const char *label;
> > + u8 ovp_level;
> > + u8 ocp_level;
> > + u8 channel_mask;
> > + u8 map_type;
> > + u8 inductor;
> > +
> > + struct backlight_device *bl_dev;
> > +};
>
> [Severity: Low]
> This isn't a bug, but pwm_cfg, bl_dev, and the AW99703_REG_TURNCFG
> definitions are unused, and drvdata->brightness is only written in
> aw99703_set_brightness() to check whether brt_val is zero on the next
> line.
>
> [ ... ]
>
will drop them.
> > +static int aw99703_powerdown(struct aw99703_data *drvdata)
> > +{
> > + int ret;
> > +
> > + ret = gpiod_set_value_cansleep(drvdata->hwen_gpio, 0);
> > + if (ret < 0)
> > + return ret;
> > +
> > + ret = regulator_disable(drvdata->vin);
> > + if (ret < 0) {
> > + gpiod_set_value_cansleep(drvdata->hwen_gpio, 1);
> > + return ret;
> > + }
> > +
> > + return 0;
> > +}
> > +
> > +
> > +static int aw99703_set_brightness(struct aw99703_data *drvdata, int
> > brt_val)
> > +{
> > + int ret;
> > +
> > + if (!drvdata->enable && brt_val > 0) {
> > + ret = aw99703_powerup(drvdata);
> > + if (ret < 0)
> > + return ret;
> > +
> > + ret = aw99703_backlight_init(drvdata);
> > + if (ret < 0) {
> > + aw99703_powerdown(drvdata);
> > + return ret;
> > + }
> > +
> > + drvdata->enable = true;
> > + }
> > +
> > + if (brt_val > 0) {
> > + ret = regmap_write(drvdata->regmap,
> > + AW99703_REG_LEDLSB,
> > + brt_val & 0x07);
> > + if (ret < 0)
> > + return ret;
> > +
> > + ret = regmap_write(drvdata->regmap,
> > + AW99703_REG_LEDMSB,
> > + (brt_val >> 3) & 0xff);
> > + if (ret < 0)
> > + return ret;
> > +
> > + ret = aw99703_set_work_mode(drvdata,
> > AW99703_MODE_WORKMODE_BACKLIGHT);
> > + if (ret < 0)
> > + return ret;
> > + } else if (drvdata->enable) {
> > + ret = aw99703_set_work_mode(drvdata,
> > AW99703_MODE_WORKMODE_STANDBY);
> > + if (ret < 0)
> > + return ret;
> > + }
> > +
> > + drvdata->brightness = brt_val;
> > +
> > + if (drvdata->brightness == 0) {
> > + if (drvdata->enable) {
> > + /*
> > + * do not report error, the backlight is off with a bit
> > + * more power consumption, turning it back on together
> > + * with an error is probably even worse.
> > + */
> > + ret = aw99703_powerdown(drvdata);
> > + if (ret < 0)
> > + return 0;
> > + }
> > + drvdata->enable = false;
> > + }
> > +
> > + return 0;
> > +}
>
> [Severity: Medium]
> Can error paths in aw99703_set_brightness() and aw99703_powerdown() leak
> the vin regulator enable count or leave drvdata->enable out of sync with
> the hardware?
>
> When brt_val is 0 and aw99703_set_work_mode() fails over I2C,
> aw99703_set_brightness() returns before calling aw99703_powerdown(). If
> this happens during the devm cleanup callback aw99703_disable() on driver
> unbind, drvdata->vin is never disabled before devm releases it.
on removal I wlll probably better ignore I2C errors.
>
> Similarly, during power-up, drvdata->enable is set to true before writing
> AW99703_REG_LEDLSB, AW99703_REG_LEDMSB, and AW99703_MODE_WORKMODE_BACKLIGHT;
> if any of those writes fails, the function returns with drvdata->vin
> enabled, hwen_gpio asserted, and drvdata->enable set to true.
>
That is what's wanted. drvdata->enable matches the chip state (not the
backlight state).
> In aw99703_powerdown(), pulling hwen_gpio low resets the chip's internal
> registers. If gpiod_set_value_cansleep() fails, regulator_disable() is
> skipped; if regulator_disable() fails, hwen_gpio is re-asserted high and
> aw99703_set_brightness() returns early before clearing drvdata->enable,
> so later brightness updates will skip aw99703_backlight_init() and drive
> an unconfigured chip.
>
ok, another bool for initialized.
> [ ... ]
>
> > +static int aw99703_probe(struct i2c_client *client)
> > +{
>
> [ ... ]
>
> > + props.type = BACKLIGHT_RAW;
> > + props.scale = drvdata->map_type ? BACKLIGHT_SCALE_LINEAR :
> > + BACKLIGHT_SCALE_NON_LINEAR;
> > + props.max_brightness = MAX_BRIGHTNESS;
> > +
> > + ret = devm_add_action_or_reset(&client->dev, aw99703_disable, drvdata);
> > + if (ret)
> > + return ret;
> > +
> > + bl_dev = devm_backlight_device_register(&client->dev,
> > + drvdata->label,
> > + &client->dev, drvdata,
> > + &aw99703_bl_ops, &props);
> > + if (IS_ERR(bl_dev))
> > + return dev_err_probe(&client->dev, PTR_ERR(bl_dev),
> > + "Failed to register backlight!\n");
> > +
> > + return 0;
> > +}
>
> [Severity: Medium]
> Should aw99703_get_dt_data() and aw99703_probe() apply the
> default-brightness and max-brightness properties from the DT binding and
> call backlight_update_status(bl_dev)?
>
I just blindly assumed that these properties are handled by
the core. I will remove that ref to commen.
> The binding in
> Documentation/devicetree/bindings/leds/backlight/awinic,aw99703.yaml
> inherits common.yaml and uses default-brightness = <100> in its example,
> but the driver never parses default-brightness or max-brightness, leaves
> props.brightness at 0, and does not update the backlight status at probe
> time.
>
Regards,
Andreas