Re: [PATCH net-next 4/4] net: dsa: realtek: add LED drivers for rtl8366rb

From: Andrew Lunn
Date: Mon Mar 25 2024 - 11:21:05 EST


> static int rtl8366rb_setup(struct dsa_switch *ds)
> {
> (...)
> if (priv->leds_disabled) {

if (!priv->leds_disable)
return;

Saves you one level of indentation.

or

static int rtl8366rb_setup_all_off(foo *priv)
{

> /* Turn everything off */
> regmap_update_bits(priv->map,
> RTL8366RB_INTERRUPT_CONTROL_REG,
> RTL8366RB_P4_RGMII_LED,
> 0);
>
> for (i = 0; i < RTL8366RB_NUM_LEDGROUPS; i++) {
> ret = rb8366rb_set_ledgroup_mode(priv, i,
> RTL8366RB_LEDGROUP_OFF);
> if (ret)
> return ret;
> }
> }
> }

This is what i meant by small helpers. And the function names replaces
the need for the comment.

This is part of the thinking behind the coding style. Function names
can replace comments. And the higher level functions becomes easier to
follow because you don't need to dig into the details to understand:

if (priv->leds_disabled)
rtl8366rb_setup_all_off(priv);

Andrew