lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <20250828154057.GA945052@bhelgaas>
Date: Thu, 28 Aug 2025 10:40:57 -0500
From: Bjorn Helgaas <helgaas@...nel.org>
To: Erick Karanja <karanja99erick@...il.com>
Cc: logang@...tatee.com, kurt.schwemmer@...rosemi.com, bhelgaas@...gle.com,
	julia.lawall@...ia.fr, kelvin.cao@...rochip.com,
	wesley.sheng@...rochip.com, stephen.bates@...rosemi.com,
	linux-pci@...r.kernel.org, linux-kernel@...r.kernel.org
Subject: Re: [PATCH] PCI: switchtec: Replace manual locks with guard

On Thu, Aug 28, 2025 at 12:35:55PM +0300, Erick Karanja wrote:
> Replace lock/unlock pairs with guards to simplify and tidy up the code
> 
> Generated-by: Coccinelle SmPL
> 
> Signed-off-by: Erick Karanja <karanja99erick@...il.com>

Applied to pci/switchtec for v6.18, thanks, Erick!

> ---
>  drivers/pci/switch/switchtec.c | 25 ++++++++++++-------------
>  1 file changed, 12 insertions(+), 13 deletions(-)
> 
> diff --git a/drivers/pci/switch/switchtec.c b/drivers/pci/switch/switchtec.c
> index b14dfab04d84..5ff84fb8fb0f 100644
> --- a/drivers/pci/switch/switchtec.c
> +++ b/drivers/pci/switch/switchtec.c
> @@ -269,10 +269,9 @@ static void mrpc_event_work(struct work_struct *work)
>  
>  	dev_dbg(&stdev->dev, "%s\n", __func__);
>  
> -	mutex_lock(&stdev->mrpc_mutex);
> +	guard(mutex)(&stdev->mrpc_mutex);
>  	cancel_delayed_work(&stdev->mrpc_timeout);
>  	mrpc_complete_cmd(stdev);
> -	mutex_unlock(&stdev->mrpc_mutex);
>  }
>  
>  static void mrpc_error_complete_cmd(struct switchtec_dev *stdev)
> @@ -1322,18 +1321,18 @@ static void stdev_kill(struct switchtec_dev *stdev)
>  	cancel_delayed_work_sync(&stdev->mrpc_timeout);
>  
>  	/* Mark the hardware as unavailable and complete all completions */
> -	mutex_lock(&stdev->mrpc_mutex);
> -	stdev->alive = false;
> -
> -	/* Wake up and kill any users waiting on an MRPC request */
> -	list_for_each_entry_safe(stuser, tmpuser, &stdev->mrpc_queue, list) {
> -		stuser->cmd_done = true;
> -		wake_up_interruptible(&stuser->cmd_comp);
> -		list_del_init(&stuser->list);
> -		stuser_put(stuser);
> -	}
> +	scoped_guard (mutex, &stdev->mrpc_mutex) {
> +		stdev->alive = false;
> +
> +		/* Wake up and kill any users waiting on an MRPC request */
> +		list_for_each_entry_safe(stuser, tmpuser, &stdev->mrpc_queue, list) {
> +			stuser->cmd_done = true;
> +			wake_up_interruptible(&stuser->cmd_comp);
> +			list_del_init(&stuser->list);
> +			stuser_put(stuser);
> +		}
>  
> -	mutex_unlock(&stdev->mrpc_mutex);
> +	}
>  
>  	/* Wake up any users waiting on event_wq */
>  	wake_up_interruptible(&stdev->event_wq);
> -- 
> 2.43.0
> 

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ