Re: [PATCH net-next 3/3] net: dsa: mv88e6xxx: leds: fix leds refcount

From: Javier Carrasco
Date: Tue Oct 08 2024 - 19:31:33 EST


On 08/10/2024 18:40, Andrew Lunn wrote:
>> - leds = fwnode_get_named_child_node(p->fwnode, "leds");
>> + struct fwnode_handle *leds __free(fwnode_handle) =
>> + fwnode_get_named_child_node(p->fwnode, "leds");
>
> https://docs.kernel.org/process/maintainer-netdev.html#using-device-managed-and-cleanup-h-constructs
>
> Low level cleanup constructs (such as __free()) can be used when
> building APIs and helpers, especially scoped iterators. However,
> direct use of __free() within networking core and drivers is
> discouraged. Similar guidance applies to declaring variables
> mid-function.
>
> Andrew
>
> ---
> pw-bot: cr


Hi Andrew,

Thanks for your review. I have seen that the __free() macro is used in
multiple net drivers, especially (but not only) __free(kfree). Why would
this one would be discouraged?

I would have nothing against declaring the variable at the top and
initializing it to NULL if that is the preferred way in the networking
subsystem, but the __free() macro seems to be well established, and it
simplifies the code.

Otherwise 4 calls to fwnode_handle_put() or a couple of goto jumps will
be required to get the same result. Moreover, if any other error path is
introduced, the mechanism will automatically account for it.

Best regards,
Javier Carrasco