Re: [net-next RFC PATCH 2/2] net: dsa: qca: qca8k: convert to guard API

From: Andrew Lunn
Date: Wed Jun 26 2024 - 20:01:04 EST


On Thu, Jun 27, 2024 at 01:02:32AM +0200, Christian Marangi wrote:
> Convert every entry of mutex_lock/unlock() to guard API.
>
> Signed-off-by: Christian Marangi <ansuelsmth@xxxxxxxxx>
> ---
> drivers/net/dsa/qca/qca8k-8xxx.c | 99 +++++++----------------
> drivers/net/dsa/qca/qca8k-common.c | 122 ++++++++++++-----------------
> 2 files changed, 81 insertions(+), 140 deletions(-)
>
> diff --git a/drivers/net/dsa/qca/qca8k-8xxx.c b/drivers/net/dsa/qca/qca8k-8xxx.c
> index b3c27cf538e8..2d9526b696f2 100644
> --- a/drivers/net/dsa/qca/qca8k-8xxx.c
> +++ b/drivers/net/dsa/qca/qca8k-8xxx.c
> @@ -6,6 +6,7 @@
> * Copyright (c) 2016 John Crispin <john@xxxxxxxxxxx>
> */
>
> +#include <linux/cleanup.h>
> #include <linux/module.h>
> #include <linux/phy.h>
> #include <linux/netdevice.h>
> @@ -321,12 +322,11 @@ static int qca8k_read_eth(struct qca8k_priv *priv, u32 reg, u32 *val, int len)
> if (!skb)
> return -ENOMEM;
>
> - mutex_lock(&mgmt_eth_data->mutex);
> + guard(mutex)(&mgmt_eth_data->mutex);
>
> /* Check if the mgmt_conduit if is operational */
> if (!priv->mgmt_conduit) {
> kfree_skb(skb);
> - mutex_unlock(&mgmt_eth_data->mutex);
> return -EINVAL;

Sorry, but NACK.

There are two issues here.

1) guard() is very magical, the opposite of C which is explicit. We
discussed that, and think scoped_guard is O.K, since it is more C
like.

2) We don't want scope_guard or guard introduced in existing code, at
least not for the moment, because it seems like it is going to make
back porting patches for stable harder/more error prone.

We do however see that these mechanisms are useful, could solve
problems, so its O.K. to use scoped_guard in new code. In a few years
we will see how things have actually worked out, and reevaluate our
position and maybe allow scoped_guard to be added to existing code.

Andrew