From 679950fedec7a6ce5887c5e9f03de40a7cf7e56b Mon Sep 17 00:00:00 2001 From: Peng Fan Date: Thu, 24 Sep 2026 16:35:37 +0800 Subject: [PATCH] net: dsa: use regmap_assign_bits() for conditional set/clear Replace if/else blocks using regmap_set_bits()/regmap_clear_bits() with the simpler regmap_assign_bits() calls in the lantiq gswip, mt7530 and qca8k drivers. Signed-off-by: Peng Fan Link: https://patch.msgid.link/20260924083538.461887-1-peng.fan@oss.nxp.com Signed-off-by: Jakub Kicinski --- drivers/net/dsa/lantiq/lantiq_gswip_common.c | 8 ++------ drivers/net/dsa/mt7530.c | 10 ++-------- drivers/net/dsa/qca/qca8k-common.c | 15 +++------------ 3 files changed, 7 insertions(+), 26 deletions(-) diff --git a/drivers/net/dsa/lantiq/lantiq_gswip_common.c b/drivers/net/dsa/lantiq/lantiq_gswip_common.c index 6150dc3ffb64..20ed487f37ca 100644 --- a/drivers/net/dsa/lantiq/lantiq_gswip_common.c +++ b/drivers/net/dsa/lantiq/lantiq_gswip_common.c @@ -1279,12 +1279,8 @@ static int gswip_port_change_mtu(struct dsa_switch *ds, int port, int new_mtu) /* Enable MLEN for ports with non-standard MTUs, including the special * header on the CPU port added above. */ - if (new_mtu != ETH_DATA_LEN) - regmap_set_bits(priv->gswip, GSWIP_MAC_CTRL_2p(port), - GSWIP_MAC_CTRL_2_MLEN); - else - regmap_clear_bits(priv->gswip, GSWIP_MAC_CTRL_2p(port), - GSWIP_MAC_CTRL_2_MLEN); + regmap_assign_bits(priv->gswip, GSWIP_MAC_CTRL_2p(port), + GSWIP_MAC_CTRL_2_MLEN, new_mtu != ETH_DATA_LEN); return 0; } diff --git a/drivers/net/dsa/mt7530.c b/drivers/net/dsa/mt7530.c index 50e80585d558..7781a63b4e6f 100644 --- a/drivers/net/dsa/mt7530.c +++ b/drivers/net/dsa/mt7530.c @@ -2150,10 +2150,7 @@ mt7530_gpio_set(struct gpio_chip *gc, unsigned int offset, int value) struct mt7530_priv *priv = gpiochip_get_data(gc); u32 bit = mt7530_gpio_to_bit(offset); - if (value) - regmap_set_bits(priv->regmap, MT7530_LED_GPIO_DATA, bit); - else - regmap_clear_bits(priv->regmap, MT7530_LED_GPIO_DATA, bit); + regmap_assign_bits(priv->regmap, MT7530_LED_GPIO_DATA, bit, value); return 0; } @@ -2191,10 +2188,7 @@ mt7530_gpio_direction_output(struct gpio_chip *gc, unsigned int offset, int valu regmap_set_bits(priv->regmap, MT7530_LED_GPIO_DIR, bit); - if (value) - regmap_set_bits(priv->regmap, MT7530_LED_GPIO_DATA, bit); - else - regmap_clear_bits(priv->regmap, MT7530_LED_GPIO_DATA, bit); + regmap_assign_bits(priv->regmap, MT7530_LED_GPIO_DATA, bit, value); regmap_set_bits(priv->regmap, MT7530_LED_GPIO_OE, bit); diff --git a/drivers/net/dsa/qca/qca8k-common.c b/drivers/net/dsa/qca/qca8k-common.c index 13005f10edb7..ab978cc8367f 100644 --- a/drivers/net/dsa/qca/qca8k-common.c +++ b/drivers/net/dsa/qca/qca8k-common.c @@ -471,10 +471,7 @@ void qca8k_port_set_status(struct qca8k_priv *priv, int port, int enable) if (port > 0 && port < 6) mask |= QCA8K_PORT_STATUS_LINK_AUTO; - if (enable) - regmap_set_bits(priv->regmap, QCA8K_REG_PORT_STATUS(port), mask); - else - regmap_clear_bits(priv->regmap, QCA8K_REG_PORT_STATUS(port), mask); + regmap_assign_bits(priv->regmap, QCA8K_REG_PORT_STATUS(port), mask, enable); } void qca8k_get_strings(struct dsa_switch *ds, int port, u32 stringset, @@ -562,14 +559,8 @@ static int qca8k_port_configure_learning(struct dsa_switch *ds, int port, { struct qca8k_priv *priv = ds->priv; - if (learning) - return regmap_set_bits(priv->regmap, - QCA8K_PORT_LOOKUP_CTRL(port), - QCA8K_PORT_LOOKUP_LEARN); - else - return regmap_clear_bits(priv->regmap, - QCA8K_PORT_LOOKUP_CTRL(port), - QCA8K_PORT_LOOKUP_LEARN); + return regmap_assign_bits(priv->regmap, QCA8K_PORT_LOOKUP_CTRL(port), + QCA8K_PORT_LOOKUP_LEARN, learning); } void qca8k_port_stp_state_set(struct dsa_switch *ds, int port, u8 state)