From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796066698; b=uFs33Er+drlBAvr3pSRZ5jdM6EkKwMHibGcRq7Q+4lHajIbqgnU4xtNBSj8nCAiabxGj pnc08ye3cPLM/yusGl4TLsYf7FNEzyAX2xlDRzcLsdl4O/K6GjUmREZs+kHBwTm5Cse4d mTe4fWK49CTli1kpEnCiPwiH7io7U0RJ8ZolnNdgYLvqGGr6gTV/1coGsTFE+UlEqWjSV IjSMyX0+fENgoD0IjpjXHYpUx+tQ2VsJW4z/DrfeZkqfb3lyp9j2+0RqiPvKibe0+9Fsl UOjIKPlgu67pU1FbGlrQigavRbYqDgznL24I6NhGyVWSnulXMoeO+M/eNVVCe9fnB1A== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796066698; h=Received:DKIM-Signature:Message-ID:From:Subject:Reply-To:To:Cc: In-Reply-To:References:Content-Type:Content-Transfer-Encoding:Date; bh=s+uj/ZlStwuykW0Jkf+lm8WrLMFxDazpwG5tpH2HheI=; b=Rd/RCT+YANX/1Y4m8r+mVzJQvbKyGh/PmAxu6xaC1u5WDWKEWoWSyA+dXEX61Qjz5aHq 50rarqqU8QuIMNZTqifJ2msm9cf+PhoJf43xn53Pr901E2sF0PbAW1YybkNVky9SlnW6J hENPTrfjVxqCfOgtOzon9quMO6p39hmn//bOefP6vuz42CJ3rM8rmSQeLAzaC9H6Yorgp ek3IN9Un2PQP95p1nVSpVi0hARcbD3ZZe4J5sGvG/afoq+EFJ97vwFnZ2zjc+xTKhU6n7 gkIoxmpmqggZQGLBQIFhi68WRhLt55tpDQeoumerqPdbUXRhxq08rc2V1yYAV79alow== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=YcjNLqsh; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0205A606A31C; Mon, 30 Nov 2026 19:24:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=YcjNLqsh Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3FB241F00897; Mon, 30 Nov 2026 19:24:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796066697; bh=s+uj/ZlStwuykW0Jkf+lm8WrLMFxDazpwG5tpH2HheI=; h=From:Subject:Reply-To:To:Cc:In-Reply-To:References:Date; b=YcjNLqshfLcz7qbnd6jonezMLgdmLrn5Zfi6xe8rTHlou4UcBDh1gU2pA6MMr2mup An6ZWz4bMqxhYXdDFtNugsz7EXRCbTqA4IfznAqM/Am8trFMgArh0gKsWKtv1qGUqf WiJHGa6JO0f9Ol2WXQ1bFJo2DwqH8YUhOHpJ7W04Ma8q72FZCkEbRih/gFMYB1Xh6p P7Wvkz+DumuqO6LntIIzcK8BlrADiA0ULjI1zqtXujc2fujNHy50crTwrEK6g4+aWt 4NmmHzKgKCRbrx8gf8flKm8cTTv0/QxMJIMPlg8j/904alX5eBTJk8n1XwDHi3fhQG 4jS+ABRbxgxpA== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH 2/4] video: backlight: Add Awinic AW99703 Reply-To: sashiko-reviews@lists.linux.dev To: "Andreas Kemnade" 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 In-Reply-To: <20261130-bl-aw99703-upstr-v1-2-986a15505ad7@kemnade.info> References: <20261130-bl-aw99703-upstr-v1-0-986a15505ad7@kemnade.info> <20261130-bl-aw99703-upstr-v1-2-986a15505ad7@kemnade.info> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Mon, 30 Nov 2026 19:24:56 +0000 X-Mailing-List: devicetree@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list 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 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 =3D aw99703_set_ovp_level(drvdata); > + if (r) > + return r; > + > + r =3D aw99703_set_ocp_level(drvdata); > + if (r) > + return r; > + > + r =3D aw99703_set_full_scale_cur(drvdata); > + if (r) > + return r; > + > + r =3D aw99703_set_channel_mask(drvdata); > + if (r) > + return r; > + > + r =3D aw99703_set_inductor(drvdata); > + if (r) > + return r; > + > + r =3D aw99703_i2c_mode_enable(drvdata); > + if (r) > + return r; > + > + r =3D aw99703_set_map_type(drvdata); > + if (r) > + return r; > + > + r =3D 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 =3D pm_runtime_resume_and_get(drvdata->dev); > + if (ret < 0) > + return ret; > + > + drvdata->enable =3D 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 =3D=3D 0. Every resume from brightness 0 therefore wri= tes 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, er= r) > + > +static const u32 ovp_level_vals[] =3D {17500000, 24000000, 310000000, 38= 000000, 41500000}; [Severity: Medium] Does ovp_level_vals[2] have an extra zero (310000000 instead of 31000000)? A device tree setting awinic,ovp-microvolt =3D <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 =3D {}; > + int ret =3D 0; > + > + drvdata =3D devm_kzalloc(&client->dev, sizeof(struct aw99703_data), > + GFP_KERNEL); > + if (!drvdata) > + return -ENOMEM; > + > + drvdata->dev =3D &client->dev; > + drvdata->brightness =3D 0; > + drvdata->enable =3D 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 =3D 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 =3D 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 =3D 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 =3D BACKLIGHT_RAW; > + props.scale =3D drvdata->map_type ? BACKLIGHT_SCALE_LINEAR : > + BACKLIGHT_SCALE_NON_LINEAR; > + props.max_brightness =3D MAX_BRIGHTNESS; > + > + pm_runtime_set_autosuspend_delay(&client->dev, 3000); > + pm_runtime_use_autosuspend(&client->dev); > + ret =3D 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 =3D dev_get_drvdata(dev); > + int ret; > + > + aw99703_set_work_mode(drvdata, 0); > + > + ret =3D gpiod_set_value_cansleep(drvdata->hwen_gpio, 0); > + if (ret < 0) > + return ret; > + > + ret =3D regulator_disable(drvdata->vin); > + if (ret < 0) { > + ret =3D gpiod_set_value_cansleep(drvdata->hwen_gpio, 1); > + return ret; > + } > + > + return 0; > +} > + > +static int aw99703_runtime_resume(struct device *dev) > +{ > + struct aw99703_data *drvdata =3D dev_get_drvdata(dev); > + int ret; > + > + ret =3D regulator_enable(drvdata->vin); > + if (ret < 0) > + return ret; > + > + ret =3D gpiod_set_value_cansleep(drvdata->hwen_gpio, 1); > + if (ret < 0) { > + ret =3D 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 =3D { > + SET_RUNTIME_PM_OPS(aw99703_runtime_suspend, aw99703_runtime_resume, NUL= L) > + SET_SYSTEM_SLEEP_PM_OPS(pm_runtime_force_suspend, pm_runtime_force_resu= me) > +}; [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 =3D=3D true, skips pm_runtime_resume_and_get(), and is= sues I2C writes while drvdata->vin is off (or if brt_val =3D=3D 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[] =3D { > + { "aw99703", 0}, > + { } > +}; [Severity: Low] This isn't a bug, but new struct i2c_device_id entries should use named initializers (e.g. { .name =3D "aw99703" }). Also, struct aw99703_data has several unused members (pwm_cfg, auto_freq_high, auto_freq_low, full_scale_led, and bl_dev), and and are unused. > +MODULE_DEVICE_TABLE(i2c, aw99703_id); > + > +static const struct of_device_id match_table[] =3D { > + {.compatible =3D "awinic,aw99703"}, > + { } > +}; > +MODULE_DEVICE_TABLE(of, match_table); > + > +static struct i2c_driver aw99703_i2c_driver =3D { > + .probe =3D aw99703_probe, > + .id_table =3D aw99703_id, > + .driver =3D { > + .name =3D "aw99703", > + .of_match_table =3D match_table, > + .pm =3D &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(). --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/20261130-bl-aw99703= -upstr-v1-0-986a15505ad7@kemnade.info?part=3D2