dri-devel Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Andreas Kemnade" <andreas@kemnade.info>
Cc: dri-devel@lists.freedesktop.org, linux-leds@vger.kernel.org,
	devicetree@vger.kernel.org, imx@lists.linux.dev, robh@kernel.org,
	conor+dt@kernel.org, Frank.Li@kernel.org, lee@kernel.org
Subject: Re: [PATCH 2/4] video: backlight: Add Awinic AW99703
Date: Mon, 30 Nov 2026 19:24:56 +0000	[thread overview]
Message-ID: <sashiko-outbox-241908@kernel.org> (raw)
In-Reply-To: <20261130-bl-aw99703-upstr-v1-2-986a15505ad7@kemnade.info>

Thank you for your contribution! Sashiko AI review found 11 potential
issues to consider:
- [High] backlight: aw99703: wrong pointer in PTR_ERR() in
  aw99703_probe()
- [Medium] backlight: aw99703: extra zero typo in ovp_level_vals[] table
- [Medium] backlight: aw99703: unchecked aw99703_get_dt_data() in
  aw99703_probe()
- [Medium] backlight: aw99703: error code overwritten in runtime PM
  rollback paths
- [Medium] backlight: aw99703: ignored error returns in init, resume,
  and brightness
- [Medium] backlight: aw99703: I2C access while suspended in
  aw99703_set_brightness()
- [Medium] backlight: aw99703: PM state desync and unlocked resume in
  aw99703_set_brightness()
- [Medium] backlight: aw99703: leaked PM and vin regulator enable on
  active driver unbind
- [Medium] backlight: aw99703: SET_RUNTIME_PM_OPS() without pm_ptr()
  breaks !CONFIG_PM
- [Low] backlight: aw99703: recursive standby write in
  aw99703_set_brightness() on resume
- [Low] backlight: aw99703: positional i2c_device_id initializer and
  dead struct fields
--

commit 51c0fed1822f97f21afb605fb72c99f1142b6097
Author: Andreas Kemnade <andreas@kemnade.info>

video: backlight: Add Awinic AW99703

This commit adds an I2C backlight driver for the Awinic AW99703 LED
controller using regmap and runtime PM.

> diff --git a/drivers/video/backlight/aw99703.c b/drivers/video/backlight/aw99703.c
> new file mode 100644
> index 0000000000000..3491895e9ac82
> --- /dev/null
> +++ b/drivers/video/backlight/aw99703.c
> @@ -0,0 +1,471 @@

[ ... ]

> +static int aw99703_backlight_init(struct aw99703_data *drvdata)
> +{
> +	int r;
> +
> +	r = aw99703_set_ovp_level(drvdata);
> +	if (r)
> +		return r;
> +
> +	r = aw99703_set_ocp_level(drvdata);
> +	if (r)
> +		return r;
> +
> +	r = aw99703_set_full_scale_cur(drvdata);
> +	if (r)
> +		return r;
> +
> +	r = aw99703_set_channel_mask(drvdata);
> +	if (r)
> +		return r;
> +
> +	r = aw99703_set_inductor(drvdata);
> +	if (r)
> +		return r;
> +
> +	r = aw99703_i2c_mode_enable(drvdata);
> +	if (r)
> +		return r;
> +
> +	r = aw99703_set_map_type(drvdata);
> +	if (r)
> +		return r;
> +
> +	r = aw99703_set_fade(drvdata);
> +	return 0;
> +}

[Severity: Medium]
Should aw99703_backlight_init() return r here instead of 0?  Also, neither
aw99703_set_brightness() nor aw99703_runtime_resume() checks the return
values of their regmap and helper calls, so I2C errors during resume or
brightness updates are silently dropped while drvdata->brightness and
drvdata->enable are updated as if the writes succeeded.

> +
> +static int aw99703_set_brightness(struct aw99703_data *drvdata, int brt_val)
> +{
> +	int ret;
> +
> +	if (!drvdata->enable && brt_val > 0) {
> +		ret = pm_runtime_resume_and_get(drvdata->dev);
> +		if (ret < 0)
> +			return ret;
> +
> +		drvdata->enable = true;
> +	}

[Severity: Low]
Because pm_runtime_resume_and_get() runs before drvdata->brightness is
updated at the bottom of aw99703_set_brightness(),
aw99703_runtime_resume() re-enters aw99703_set_brightness() with the stale
drvdata->brightness == 0.  Every resume from brightness 0 therefore writes
AW99703_MODE_WORKMODE_STANDBY to AW99703_REG_MODE right before the outer
call writes LEDLSB, LEDMSB, and AW99703_MODE_WORKMODE_BACKLIGHT.

> +
> +	if (brt_val > 0) {
> +		regmap_write(drvdata->regmap,
> +			     AW99703_REG_LEDLSB,
> +			     brt_val & 0x07);
> +		regmap_write(drvdata->regmap,
> +			     AW99703_REG_LEDMSB,
> +			     (brt_val >> 3) & 0xff);
> +		regmap_update_bits(drvdata->regmap,
> +				   AW99703_REG_MODE,
> +				   AW99703_MODE_WORKMODE_MASK,
> +				   AW99703_MODE_WORKMODE_BACKLIGHT);
> +	} else {
> +		regmap_update_bits(drvdata->regmap,
> +				   AW99703_REG_MODE,
> +				   AW99703_MODE_WORKMODE_MASK,
> +				   AW99703_MODE_WORKMODE_STANDBY);
> +	}

[Severity: Medium]
Does calling aw99703_set_brightness(drvdata, 0) when drvdata->enable is
false perform an I2C transfer to an unpowered chip?

When the backlight is initially off after probe or has autosuspended,
drvdata->enable is false, drvdata->vin is disabled, and drvdata->hwen_gpio
is low.  A blanking event or writing 0 to brightness skips
pm_runtime_resume_and_get() and runs regmap_update_bits() on
AW99703_REG_MODE without holding a runtime PM reference.

[ ... ]

> +#define PARSE_DT_LIST(name, def, values, dest, err) \
> +	parse_dt_prop_list(dev, name, def, values, ARRAY_SIZE(values), dest, err)
> +
> +static const u32 ovp_level_vals[] = {17500000, 24000000, 310000000, 38000000, 41500000};

[Severity: Medium]
Does ovp_level_vals[2] have an extra zero (310000000 instead of 31000000)?
A device tree setting awinic,ovp-microvolt = <31000000> for the 31 V
threshold will be rejected with -EINVAL by parse_dt_prop_list().

[ ... ]

> +static int aw99703_probe(struct i2c_client *client)
> +{
> +	struct aw99703_data *drvdata;
> +	struct backlight_device *bl_dev;
> +	struct backlight_properties props = {};
> +	int ret = 0;
> +
> +	drvdata = devm_kzalloc(&client->dev, sizeof(struct aw99703_data),
> +			       GFP_KERNEL);
> +	if (!drvdata)
> +		return -ENOMEM;
> +
> +	drvdata->dev = &client->dev;
> +	drvdata->brightness = 0;
> +	drvdata->enable = false;
> +	aw99703_get_dt_data(drvdata);

[Severity: Medium]
Should aw99703_probe() check and return the error from
aw99703_get_dt_data()?

If an early property check in aw99703_get_dt_data() fails and returns
-EINVAL, drvdata->channel_mask and drvdata->label are never initialized,
so probe continues with all LED channels masked off and registers the
backlight device with a NULL name.

> +	i2c_set_clientdata(client, drvdata);
> +
> +	drvdata->regmap = devm_regmap_init_i2c(client, &aw99703_regmap_config);
> +	if (IS_ERR(drvdata->regmap))
> +		return dev_err_probe(&client->dev, PTR_ERR(drvdata->regmap),
> +				    "Failed to init regmap\n");
> +
> +	drvdata->hwen_gpio = devm_gpiod_get_optional(&client->dev, "enable",
> +						     GPIOD_OUT_LOW);
> +	if (IS_ERR(drvdata->hwen_gpio))
> +		return dev_err_probe(&client->dev,
> +				     PTR_ERR(drvdata->vin),
> +				     "Failed to get gpio\n");

[Severity: High]
Does this pass PTR_ERR(drvdata->vin) instead of PTR_ERR(drvdata->hwen_gpio)?
Because drvdata->vin is still NULL here, dev_err_probe() returns 0 on GPIO
errors (including -EPROBE_DEFER), leaving the device bound without a
regulator, runtime PM enabled, or a registered backlight device.

> +
> +	drvdata->vin = devm_regulator_get(&client->dev, "vin");
> +	if (IS_ERR(drvdata->vin))
> +		return dev_err_probe(&client->dev,
> +				     PTR_ERR(drvdata->vin),
> +				     "Failed to get regulator\n");
> +
> +	props.type = BACKLIGHT_RAW;
> +	props.scale = drvdata->map_type ? BACKLIGHT_SCALE_LINEAR :
> +					  BACKLIGHT_SCALE_NON_LINEAR;
> +	props.max_brightness = MAX_BRIGHTNESS;
> +
> +	pm_runtime_set_autosuspend_delay(&client->dev, 3000);
> +	pm_runtime_use_autosuspend(&client->dev);
> +	ret = devm_pm_runtime_enable(&client->dev);

[Severity: Medium]
Does unbinding the driver while the device is runtime-active leak the
drvdata->vin enable reference and trigger WARN_ON(regulator->enable_count)
in _regulator_put()?

When brightness > 0 (or during the 3000 ms autosuspend delay after setting
brightness to 0), the device holds an active runtime PM reference and
drvdata->vin is enabled.  On unbind, devm_pm_runtime_enable() disables
runtime PM without calling aw99703_runtime_suspend(), and
devm_regulator_get() then releases drvdata->vin while it is still enabled.

[ ... ]

> +static int aw99703_runtime_suspend(struct device *dev)
> +{
> +	struct aw99703_data *drvdata = dev_get_drvdata(dev);
> +	int ret;
> +
> +	aw99703_set_work_mode(drvdata, 0);
> +
> +	ret = gpiod_set_value_cansleep(drvdata->hwen_gpio, 0);
> +	if (ret < 0)
> +		return ret;
> +
> +	ret = regulator_disable(drvdata->vin);
> +	if (ret < 0) {
> +		ret = gpiod_set_value_cansleep(drvdata->hwen_gpio, 1);
> +		return ret;
> +	}
> +
> +	return 0;
> +}
> +
> +static int aw99703_runtime_resume(struct device *dev)
> +{
> +	struct aw99703_data *drvdata = dev_get_drvdata(dev);
> +	int ret;
> +
> +	ret = regulator_enable(drvdata->vin);
> +	if (ret < 0)
> +		return ret;
> +
> +	ret = gpiod_set_value_cansleep(drvdata->hwen_gpio, 1);
> +	if (ret < 0) {
> +		ret = regulator_disable(drvdata->vin);
> +		return ret;
> +	}

[Severity: Medium]
Do the error rollback paths in aw99703_runtime_suspend() and
aw99703_runtime_resume() overwrite ret with the rollback call's return
value?

When regulator_disable() fails in aw99703_runtime_suspend() (or
gpiod_set_value_cansleep() fails in aw99703_runtime_resume()) and the
rollback call succeeds, the callback returns 0 to the PM core, leaving the
runtime PM state out of sync with drvdata->vin and skipping
aw99703_backlight_init() on resume.

> +
> +	usleep_range(250, 1000);
> +
> +	aw99703_backlight_init(drvdata);
> +	aw99703_set_brightness(drvdata, drvdata->brightness);
> +	return 0;
> +}
> +
> +static const struct dev_pm_ops aw99703_pm_ops = {
> +	SET_RUNTIME_PM_OPS(aw99703_runtime_suspend, aw99703_runtime_resume, NULL)
> +	SET_SYSTEM_SLEEP_PM_OPS(pm_runtime_force_suspend, pm_runtime_force_resume)
> +};

[Severity: Medium]
Can system suspend/resume desynchronize drvdata->enable from the hardware
power state, and can aw99703_runtime_resume() race with
aw99703_bl_update_status()?

pm_runtime_force_suspend() runs aw99703_runtime_suspend() and disables
drvdata->vin without clearing drvdata->enable, and the backlight device is
registered without BL_CORE_SUSPENDRESUME.  If a display driver updates the
backlight while the I2C device is force-suspended, aw99703_set_brightness()
sees drvdata->enable == true, skips pm_runtime_resume_and_get(), and issues
I2C writes while drvdata->vin is off (or if brt_val == 0, clears
drvdata->enable while dev->power.needs_force_resume remains set).
In addition, aw99703_runtime_resume() reads drvdata->brightness and calls
aw99703_set_brightness() without holding bl_dev->update_lock.

> +
> +static const struct i2c_device_id aw99703_id[] = {
> +	{ "aw99703", 0},
> +	{ }
> +};

[Severity: Low]
This isn't a bug, but new struct i2c_device_id entries should use named
initializers (e.g. { .name = "aw99703" }).  Also, struct aw99703_data has
several unused members (pwm_cfg, auto_freq_high, auto_freq_low,
full_scale_led, and bl_dev), and <linux/input.h> and <linux/version.h> are
unused.

> +MODULE_DEVICE_TABLE(i2c, aw99703_id);
> +
> +static const struct of_device_id match_table[] = {
> +	{.compatible = "awinic,aw99703"},
> +	{ }
> +};
> +MODULE_DEVICE_TABLE(of, match_table);
> +
> +static struct i2c_driver aw99703_i2c_driver = {
> +	.probe = aw99703_probe,
> +	.id_table = aw99703_id,
> +	.driver = {
> +		.name = "aw99703",
> +		.of_match_table = match_table,
> +		.pm = &aw99703_pm_ops,
> +	},
> +};

[Severity: Medium]
Does building with !CONFIG_PM warn on unused aw99703_runtime_suspend() and
aw99703_runtime_resume() and leave the hardware unpowered at runtime?

SET_RUNTIME_PM_OPS() compiles out when CONFIG_PM is disabled, while
.driver.pm is not wrapped with pm_ptr() and aw99703_pm_ops does not use
RUNTIME_PM_OPS() / SYSTEM_SLEEP_PM_OPS().  Also, when !CONFIG_PM,
pm_runtime_resume_and_get() is a no-op returning 0, so
aw99703_runtime_resume() never runs to enable drvdata->vin, assert
drvdata->hwen_gpio, or call aw99703_backlight_init().

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261130-bl-aw99703-upstr-v1-0-986a15505ad7@kemnade.info?part=2

  reply	other threads:[~2026-11-30 19:25 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-30 19:08 [PATCH 0/4] video: backlight: Backlight for Kobo Clara 2e Andreas Kemnade
2026-11-30 19:08 ` [PATCH 1/4] dt-bindings: leds: backlight: Add Awinic AW99703 backlight Andreas Kemnade
2026-11-30 19:16   ` sashiko-bot
2026-11-30 20:21     ` Frank Li
2026-11-30 19:08 ` [PATCH 2/4] video: backlight: Add Awinic AW99703 Andreas Kemnade
2026-11-30 19:24   ` sashiko-bot [this message]
2026-11-30 20:18     ` Frank Li
2026-11-30 20:35       ` Andreas Kemnade
2026-11-30 19:08 ` [PATCH 3/4] ARM: dts: imx: Add backlight for Kobo Clara 2e Andreas Kemnade
2026-11-30 19:32   ` sashiko-bot
2026-11-30 20:25     ` Andreas Kemnade
2026-11-30 19:08 ` [PATCH 4/4] arm: mach-imx: enable shared gpios Andreas Kemnade

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=sashiko-outbox-241908@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=Frank.Li@kernel.org \
    --cc=andreas@kemnade.info \
    --cc=conor+dt@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=imx@lists.linux.dev \
    --cc=lee@kernel.org \
    --cc=linux-leds@vger.kernel.org \
    --cc=robh@kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox