RE: [PATCH net-next] net: fec: Convert fec driver to use lock guards

From: Wei Fang
Date: Tue May 07 2024 - 22:41:39 EST


> -----Original Message-----
> From: Eric Dumazet <edumazet@xxxxxxxxxx>
> Sent: 2024年5月7日 18:40
> To: Wei Fang <wei.fang@xxxxxxx>
> Cc: davem@xxxxxxxxxxxxx; kuba@xxxxxxxxxx; pabeni@xxxxxxxxxx; Shenwei
> Wang <shenwei.wang@xxxxxxx>; Clark Wang <xiaoning.wang@xxxxxxx>;
> richardcochran@xxxxxxxxx; netdev@xxxxxxxxxxxxxxx;
> linux-kernel@xxxxxxxxxxxxxxx; imx@xxxxxxxxxxxxxxx
> Subject: Re: [PATCH net-next] net: fec: Convert fec driver to use lock guards
>
> On Tue, May 7, 2024 at 11:16 AM Wei Fang <wei.fang@xxxxxxx> wrote:
> >
> > Use guard() and scoped_guard() defined in linux/cleanup.h to automate
> > lock lifetime control in fec driver.
> >
> > Signed-off-by: Wei Fang <wei.fang@xxxxxxx>
> >
>
> To me, this looks like a nice recipe for future disasters when doing backports,
> because I am pretty sure the "goto ..." that assumes the lock is magically
> released will fail horribly.
>
> I would use scoped_guard() only for new code.

Now that the kernel already supports scope-based resource management,
I think we should actively use this new mechanism. At least the result could
be safer resource management in the kernel and a lot fewer gotos.