Devicetree
 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 v3 2/4] video: backlight: Add Awinic AW99703
Date: Fri, 04 Dec 2026 22:05:09 +0000	[thread overview]
Message-ID: <sashiko-outbox-250717@kernel.org> (raw)
In-Reply-To: <20261204-bl-aw99703-upstr-v3-2-b98b78720ac2@kemnade.info>

Thank you for your contribution! Sashiko AI review found 5 potential
issues to consider:
- [Medium] backlight: aw99703: active backlight stuck on when
  enable-gpios is omitted
- [Medium] backlight: aw99703: bad GPIO rollback and missing delay in
  aw99703_powerdown()
- [Medium] backlight: aw99703_set_brightness() does not roll back
  power-up on I2C error
- [Medium] backlight: aw99703: aw99703_disable() skips
  regulator_disable() on GPIO error
- [Low] backlight: aw99703: dead code, stale comment, unused clientdata,
  and typo
--

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

video: backlight: Add Awinic AW99703

This commit adds a backlight driver for the Awinic AW99703 LED driver
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..cc6715b246839
> --- /dev/null
> +++ b/drivers/video/backlight/aw99703.c
> @@ -0,0 +1,467 @@

[ ... ]

> +#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)

[Severity: Low]
This isn't a bug, but AW99703_REG_TURNCFG, AW99703_TURNCFG_ON_TIM_MASK,
and AW99703_TURNCFG_OFF_TIM_MASK are defined without being used anywhere.

aw99703_backlight_init() also calls seven single-use wrappers that do
separate regmap_update_bits() cycles on AW99703_REG_BSTCTR1,
AW99703_REG_LEDCUR, and AW99703_REG_MODE; combining fields per register
would avoid the extra I2C traffic and boilerplate.

Lastly, the "/* auto freq high/low */" comment above channel_mask_vals[]
looks stale, i2c_set_clientdata() in aw99703_probe() is never read back,
and the Kconfig help text spells the vendor name "Awininc" instead of
"Awinic".

[ ... ]

> +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;
> +}

[Severity: Medium]
Can this rollback leave the chip unready for I2C when regulator_disable()
fails?

Re-asserting hwen_gpio after pulling it low omits the usleep_range(250,
1000) wake-up delay used in aw99703_powerup() and ignores any error from
gpiod_set_value_cansleep().

Because aw99703_set_brightness() clears drvdata->initialized but leaves
drvdata->enable true on error, the next non-zero brightness update skips
aw99703_powerup() and runs aw99703_backlight_init() immediately before
the chip exits reset (or while hwen_gpio stays low if rollback failed).

When called from aw99703_disable() during driver removal, this rollback
also re-asserts hwen_gpio high right before teardown.

[ ... ]

> +static int aw99703_set_brightness(struct aw99703_data *drvdata, int brt_val)
> +{
> +	int ret;
> +
> +	if (brt_val > 0) {
> +		if (!drvdata->enable) {
> +			ret = aw99703_powerup(drvdata);
> +			if (ret < 0)
> +				return ret;
> +
> +			drvdata->enable = true;
> +		}
> +
> +		if (!drvdata->initialized) {
> +			ret = aw99703_backlight_init(drvdata);
> +			if (ret < 0)
> +				return ret;
> +
> +			drvdata->initialized = true;
> +		}
> +
> +		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;

[Severity: Medium]
Should an I2C failure after a fresh aw99703_powerup() roll back vin and
hwen_gpio?

When userspace transitions bl_power from BACKLIGHT_POWER_OFF to
BACKLIGHT_POWER_ON with a non-zero brightness and an I2C write fails
here, bl_power_store() reverts bd->props.power back to
BACKLIGHT_POWER_OFF.

Subsequent BACKLIGHT_POWER_OFF writes then become no-ops in the backlight
core while vin stays enabled and hwen_gpio stays high.  Rolling back with
aw99703_powerdown() and clearing drvdata->enable and drvdata->initialized
on error when powering up from off would keep hardware and core in sync.

> +	} else {
> +		if (drvdata->initialized) {
> +			ret = aw99703_set_work_mode(drvdata, AW99703_MODE_WORKMODE_STANDBY);
> +			if (ret < 0)
> +				return ret;
> +		}
> +
> +		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.
> +			 * Do not assume tha backlight is initialized after
> +			 * successful or unsuccesful call to powerdown.
> +			 */
> +			drvdata->initialized = false;
> +			ret = aw99703_powerdown(drvdata);
> +			if (ret < 0)
> +				return 0;
> +		}
> +		drvdata->enable = false;
> +	}

[Severity: Medium]
Can an already-lit backlight stay stuck on when enable-gpios is omitted?

enable-gpios is optional, and aw99703_probe() does not reset, standby, or
read back chip state, leaving drvdata->enable and drvdata->initialized
false.

If the bootloader left the AW99703 active on an always-on or boot-enabled
vin supply, writing 0 to brightness, blanking, or suspending hits these
guards and returns 0 as a no-op while the backlight remains physically
lit.

aw99703_disable() has the same drvdata->enable guard, so unbinding the
driver also leaves the chip running until a non-zero brightness has been
written first.

[ ... ]

> +static void aw99703_disable(void *d)
> +{
> +	struct aw99703_data *drvdata = d;
> +
> +	if (drvdata->enable) {
> +		aw99703_set_work_mode(drvdata, AW99703_MODE_WORKMODE_STANDBY);
> +		aw99703_powerdown(drvdata);
> +	}
> +}

[Severity: Medium]
Does aw99703_disable() leak the vin regulator enable count if lowering
hwen_gpio fails during unbind?

If gpiod_set_value_cansleep(drvdata->hwen_gpio, 0) returns an error (for
example, -ENODEV if the GPIO chip was already removed or a bus error on a
GPIO expander), aw99703_powerdown() returns early without calling
regulator_disable(drvdata->vin).

devm_regulator_release() then runs regulator_put(drvdata->vin) ->
_regulator_put(), which triggers WARN_ON(regulator->enable_count) and
destroys the consumer handle without decrementing rdev->use_count,
permanently leaking the enable count on vin.

During teardown, aw99703_disable() should still call
regulator_disable(drvdata->vin) even if lowering hwen_gpio fails, and
avoid re-asserting hwen_gpio if regulator_disable() fails.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261204-bl-aw99703-upstr-v3-0-b98b78720ac2@kemnade.info?part=2

  reply	other threads:[~2026-12-04 22:05 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-04 21:44 [PATCH v3 0/4] video: backlight: Backlight for Kobo Clara 2e Andreas Kemnade
2026-12-04 21:44 ` [PATCH v3 1/4] dt-bindings: leds: backlight: Add Awinic AW99703 backlight Andreas Kemnade
2026-12-04 21:57   ` sashiko-bot
2026-12-04 21:44 ` [PATCH v3 2/4] video: backlight: Add Awinic AW99703 Andreas Kemnade
2026-12-04 22:05   ` sashiko-bot [this message]
2026-12-04 21:44 ` [PATCH v3 3/4] ARM: dts: imx: Add backlight for Kobo Clara 2e Andreas Kemnade
2026-12-04 21:44 ` [PATCH v3 4/4] arm: mach-imx: enable shared gpios Andreas Kemnade
2026-12-04 21:55   ` sashiko-bot

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-250717@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