net: dsa: motorcomm: Fix register rollback in LED setup
David Yang
maintainerPATCH v2 1/1 net: dsa: motorcomm: Fix register rollback in LED setup
The LED error path writes back a stale snapshot of the whole words taken before the class device registration, silently reverting LED2 state of sibling LED groups already registered and reachable from sysfs. Although the odds are very small, fix it by reverting this group's fields only for correctness.
---
v2:
- reword
v1: https://lore.kernel.org/r/[email protected]
drivers/net/dsa/motorcomm/leds.c | 69 +++++++++++++++++++------------- 1 file changed, 42 insertions(+), 27 deletions(-)
drivers/net/dsa/motorcomm/leds.c +42 -27
@@ -420,13 +420,15 @@ yt921x_led_setup(struct yt921x_priv *priv, int port,char name[LED_MAX_NAME_SIZE ];enum led_default_state state;struct yt921x_led *led; +int polarity_orig;bool force_high;bool force_low; -u32 led2_val; -u32 inv_val; +u32 led2_orig; +int polarity;u32 group;u32 mask;u32 ctrl; +u32 val;bool on;int res;int ret;
@@ -452,6 +454,7 @@ yt921x_led_setup(struct yt921x_priv *priv, int port, port, group);return -EINVAL ; } + polarity = force_high ?1 : force_low ?-1 :0 ; led =devm_kzalloc (dev,sizeof (*led),GFP_KERNEL );if (!led) {
@@ -470,23 +473,27 @@ yt921x_led_setup(struct yt921x_priv *priv, int port,/* Inversion is internal - force on will give low logic. * In the rest of the file, treat LEDs as if active-low. */ - inv_val =U32_MAX ; -if (force_high || force_low) { - res =yt921x_reg_read (priv,YT921X_LED_PAR_INV , &inv_val); + polarity_orig =0 ; +if (polarity) { + res =yt921x_reg_read (priv,YT921X_LED_PAR_INV , &val);if (res) - goto revoke_inv; + goto err_inv; mask =YT921X_LED_PAR_INV_INVnm (group, port); - ctrl = force_high ? inv_val | mask : inv_val & ~mask; - res =yt921x_reg_write (priv,YT921X_LED_PAR_INV , ctrl); -if (res) - goto revoke_inv; + ctrl = polarity >0 ? val | mask : val & ~mask; +if (ctrl != val) { + res =yt921x_reg_write (priv,YT921X_LED_PAR_INV , ctrl); +if (res) + goto err_inv; + + polarity_orig = -polarity; + } } - led2_val =U32_MAX ; - res =yt921x_reg_read (priv,YT921X_LED2_PORTn (port), &led2_val); + led2_orig =U32_MAX ; + res =yt921x_reg_read (priv,YT921X_LED2_PORTn (port), &val);if (res) - goto revoke_led2; + goto err_led2; mask =YT921X_LED2_PORT_FORCEn_M (group);switch (state) {
@@ -494,16 +501,20 @@ yt921x_led_setup(struct yt921x_priv *priv, int port,case LEDS_DEFSTATE_ON :default : on = state ==LEDS_DEFSTATE_ON ; - ctrl = on ?YT921X_LED2_PORT_FORCEn_ON (group) : -YT921X_LED2_PORT_FORCEn_OFF (group); - res =yt921x_reg_write (priv,YT921X_LED2_PORTn (port), - (led2_val & ~mask) | ctrl); -if (res) - goto revoke_led2; + ctrl = (val & ~mask) | + (on ?YT921X_LED2_PORT_FORCEn_ON (group) : +YT921X_LED2_PORT_FORCEn_OFF (group)); +if (ctrl != val) { + res =yt921x_reg_write (priv,YT921X_LED2_PORTn (port), + ctrl); +if (res) + goto err_led2; + + led2_orig = val & mask; + }break ;case LEDS_DEFSTATE_KEEP : - on = (led2_val & mask) ==YT921X_LED2_PORT_FORCEn_ON (group); - led2_val =U32_MAX ; + on = (val & mask) ==YT921X_LED2_PORT_FORCEn_ON (group);break ; }
@@ -539,22 +550,26 @@ yt921x_led_setup(struct yt921x_priv *priv, int port, revoke:mutex_lock (&priv->reg_lock); -revoke_led2: -if (led2_val !=U32_MAX ) { - ret =yt921x_reg_write (priv,YT921X_LED2_PORTn (port), led2_val); +if (led2_orig !=U32_MAX ) { + ret =yt921x_reg_update_bits (priv,YT921X_LED2_PORTn (port), +YT921X_LED2_PORT_FORCEn_M (group), + led2_orig);if (ret)dev_err (dev,"Failed to restore %s for LED %02d:%02u: %d\n" ,"LED2_PORT" , port, group, ret); } -revoke_inv: -if (inv_val !=U32_MAX ) { - ret =yt921x_reg_write (priv,YT921X_LED_PAR_INV , inv_val); +err_led2: +if (polarity_orig) { + ret =yt921x_reg_toggle_bits (priv,YT921X_LED_PAR_INV , +YT921X_LED_PAR_INV_INVnm (group, port), + polarity_orig >0 );if (ret)dev_err (dev,"Failed to restore %s for LED %02d:%02u: %d\n" ,"LED_PAR_INV" , port, group, ret); } +err_inv:mutex_unlock (&priv->reg_lock); pp->leds[group] =NULL ;
Signature · 1 line
2.53.0
[email protected]
AI reviewThis is an automated message. This series looks like a fix, but its commit messages seem to be missing some information:
Hi!
This is an automated message. This series looks like a fix, but its commit messages seem to be missing some information:
- How the issue was discovered, e.g. hit in production, hit during development, syzbot report, manual code inspection, LLM or static analysis tool scan.
Please do not repost the series just to address the above. Instead, reply to this email with the missing information, so that reviewers can take it into account. If the series needs another revision for other reasons, please include the information in the commit messages then.
The evaluation is done by an LLM so it may be wrong, if you think that is the case please reply and explain.
David Yang
maintainerQuoted 10 lines · On Wed, Sep 30, 2026 at 10:14 PM <[email protected]> wrote:
Hi!
This is an automated message. This series looks like a fix, but its commit messages seem to be missing some information:
- How the issue was discovered, e.g. hit in production, hit during development, syzbot report, manual code inspection, LLM or static analysis tool scan.
Quoted 8 lines
Please do not repost the series just to address the above. Instead, reply to this email with the missing information, so that reviewers can take it into account. If the series needs another revision for other reasons, please include the information in the commit messages then.
The evaluation is done by an LLM so it may be wrong, if you think that is the case please reply and explain.
This is a catchup patch of previous misapplied old series version.
This patch was applied to netdev/net-next.git (main) by Jakub Kicinski <[email protected]>:
Hello:
This patch was applied to netdev/net-next.git (main) by Jakub Kicinski <[email protected]>:
Quoted 10 lines · On Wed, 30 Sep 2026 22:11:48 +0800 you wrote:
The LED error path writes back a stale snapshot of the whole words taken before the class device registration, silently reverting LED2 state of sibling LED groups already registered and reachable from sysfs. Although the odds are very small, fix it by reverting this group's fields only for correctness.
Fixes 9af9a8168213 ("net: dsa: motorcomm: Add LED support")Signed-off-by David Yang <[email protected]>[...]
Here is the summary with links:
- [net-next,v2] net: dsa: motorcomm: Fix register rollback in LED setup
https://git.kernel.org/netdev/net-next/c/1a2dbdb6602a
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html