Re: [PATCH] net: intel: ice: Modernize ice_vsi_free() with scope-based guard(mutex)

From: Andrew Lunn

Date: Wed Oct 14 2026 - 16:22:49 EST


On Thu, Oct 15, 2026 at 01:36:35AM +0900, Kohei Enju wrote:
> On 10/14 16:35, Ayush Yaduvanshi wrote:
> > Signed-off-by: Ayush Yaduvanshi <ayush37735@xxxxxxxxx>
>
> The commit message is missing, and this patch seems to be a clean-up
> patch, which is discouraged in
> Documentation/process/maintainer-netdev.rst. Also, this document says:
> Use of ``guard()`` is discouraged within any function longer than 20 lines
>
> > ---
> > drivers/net/ethernet/intel/ice/ice_lib.c | 3 +--
> > 1 file changed, 1 insertion(+), 2 deletions(-)
> >
> > diff --git a/drivers/net/ethernet/intel/ice/ice_lib.c b/drivers/net/ethernet/intel/ice/ice_lib.c
> > index 9e08db376d3d..c695df442822 100644
> > --- a/drivers/net/ethernet/intel/ice/ice_lib.c
> > +++ b/drivers/net/ethernet/intel/ice/ice_lib.c
> > @@ -457,7 +457,7 @@ void ice_vsi_free(struct ice_vsi *vsi)
> > return;
> > }
> >
> > - mutex_lock(&pf->sw_mutex);
> > + guard(mutex)(&pf->sw_mutex);
> > /* updates the PF for this cleared VSI */
> >
> > pf->vsi[vsi->idx] = NULL;
> > @@ -466,7 +466,6 @@ void ice_vsi_free(struct ice_vsi *vsi)
> > ice_vsi_free_stats(vsi);
> > ice_vsi_free_arrays(vsi);
> > mutex_destroy(&vsi->xdp_state_lock);
> > - mutex_unlock(&pf->sw_mutex);
> > devm_kfree(dev, vsi);
>
> This also extends the critical section, as devm_kfree() is now called
> while holding pf->sw_mutex.

This is exactly why guard() is bad and should not be used.

Andrew