[PATCH net-next 2/2] net: ti: icssg-prueth: Add ethtool RX flow classification support
Meghana Malladi
m-malladi at ti.com
Wed Nov 25 22:10:55 PST 2026
Hi Marco, Simon,
On 11/25/26 17:06, Simon Horman wrote:
> On Thu, Nov 19, 2026 at 10:19:48AM +0100, Marco Crivellari wrote:
>> Hi,
>>
>> On Wed, Nov 18, 2026 at 7:50 PM Meghana Malladi <m-malladi at ti.com> wrote:
>>> [...]
>>> + mutex_lock(&emac->rxnfc.rxnfc_lock);
>>> +
>>> + /* Check max rules */
>>> + if (emac->rxnfc.rxnfc_rule_count >= ICSSG_RXNFC_MAX_RULES) {
>>> + ret = -ENOSPC;
>>> + goto unlock;
>>> + }
>>> [...]
>>> +
>>> +unlock:
>>> + mutex_unlock(&emac->rxnfc.rxnfc_lock);
>>> + return ret;
>>> +}
>>> +EXPORT_SYMBOL_GPL(icssg_rxnfc_rule_add);
>>
>> nit: instead of mutex_lock() you can use guard() [1]:
>>
>> guard(mutex)(&emac->rxnfc.rxnfc_lock)
>>
>> and remove all the "goto unlock", returning directly. This handles the
>> automatic cleanup.
>>
>> Same for other places where you're using mutex_lock() / mutex_unlock().
>>
>> - [1] https://docs.kernel.org/core-api/cleanup.html
>
> Thanks Marco,
>
> That may be good general advice.
> But for networking code the explicit approach taken by this patch
> is still preferred.
>
> Using device-managed and cleanup.h constructs
>
> Netdev remains skeptical about promises of all “auto-cleanup” APIs,
> including even devm_ helpers, historically. They are not the preferred
> style of implementation, merely an acceptable one.
>
> Use of guard() is discouraged within any function longer than 20 lines,
> scoped_guard() is considered more readable. Using normal lock/unlock is
> still (weakly) preferred.
>
> 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.
>
> Link: https://docs.kernel.org/process/maintainer-netdev.html#using-device-managed-and-cleanup-h-constructs
Thanks for the insights! I had actually just implemented Marco's
suggestion locally, so I'll revert that back now :/ I'll definitely give
the netdev documentation a good read as well.
More information about the linux-arm-kernel
mailing list