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

From: Luiz Angelo Daros de Luca
Date: Thu May 16 2024 - 13:30:53 EST


> On Sat, 27 Apr 2024 02:11:30 -0300 Luiz Angelo Daros de Luca wrote:
> > +static int rtl8366rb_setup_leds(struct realtek_priv *priv)
> > +{
> > + struct device_node *leds_np, *led_np;
> > + struct dsa_switch *ds = &priv->ds;
> > + struct dsa_port *dp;
> > + int ret = 0;
> > +
> > + dsa_switch_for_each_port(dp, ds) {
> > + if (!dp->dn)
> > + continue;
> > +
> > + leds_np = of_get_child_by_name(dp->dn, "leds");
> > + if (!leds_np) {
> > + dev_dbg(priv->dev, "No leds defined for port %d",
> > + dp->index);
> > + continue;
> > + }
> > +
> > + for_each_child_of_node(leds_np, led_np) {
> > + ret = rtl8366rb_setup_led(priv, dp,
> > + of_fwnode_handle(led_np));
> > + if (ret) {
> > + of_node_put(led_np);
> > + break;
> > + }
> > + }
> > +
> > + of_node_put(leds_np);
> > + if (ret)
> > + return ret;
> > + }
> > + return 0;
> > +}
>
> coccicheck generates this warning:
>
> drivers/net/dsa/realtek/rtl8366rb.c:1032:4-15: ERROR: probable double put.
>
> I think it's a false positive.

Me too. I don't think it is a double put. The put for led_np is called
in the increment code inside the for_each_child_of_node macro. With a
break, we skip that part and we need to put it before leaving. I don't
know coccicheck but maybe it got confused by the double for.

> But aren't you missing a put(dp) before
> "return ret;" ?

dsa_switch_for_each_port doesn't get nodes. So, no put required.

Regards,

Luiz