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] [thread-next>] [day] [month] [year] [list]
Message-ID: <225a9ea6-bc40-4c7c-a8dd-1db7649eaace@gmail.com>
Date: Wed, 4 Sep 2024 21:03:33 +0200
From: Javier Carrasco <javier.carrasco.cruz@...il.com>
To: Dmitry Torokhov <dmitry.torokhov@...il.com>, linux-input@...r.kernel.org
Cc: Michael Hennerich <michael.hennerich@...log.com>,
 Ville Syrjala <syrjala@....fi>,
 Support Opensource <support.opensource@...semi.com>,
 Eddie James <eajames@...ux.ibm.com>, Andrey Moiseev <o2g.org.ru@...il.com>,
 Hans de Goede <hdegoede@...hat.com>, Jeff LaBundy <jeff@...undy.com>,
 linux-kernel@...r.kernel.org,
 Javier Carrasco Cruz <javier.carrasco.cruz@...il.com>
Subject: Re: [PATCH 06/22] Input: kxtj9 - use guard notation when acquiring
 mutex/disabling irq

On 04/09/2024 06:42, Dmitry Torokhov wrote:
> Using guard notation makes the code more compact and error handling
> more robust by ensuring that mutexes are released and interrupts are
> re-enabled in all code paths when control leaves critical section.
> 
> Signed-off-by: Dmitry Torokhov <dmitry.torokhov@...il.com>
> ---
>  drivers/input/misc/kxtj9.c | 14 ++++----------
>  1 file changed, 4 insertions(+), 10 deletions(-)
> 
> diff --git a/drivers/input/misc/kxtj9.c b/drivers/input/misc/kxtj9.c
> index 837682cb2a7d..c6146bcee9f9 100644
> --- a/drivers/input/misc/kxtj9.c
> +++ b/drivers/input/misc/kxtj9.c
> @@ -314,9 +314,8 @@ static ssize_t kxtj9_set_poll(struct device *dev, struct device_attribute *attr,
>  		return error;
>  
>  	/* Lock the device to prevent races with open/close (and itself) */
> -	mutex_lock(&input_dev->mutex);
> -
> -	disable_irq(client->irq);
> +	guard(mutex)(&input_dev->mutex);
> +	guard(disable_irq)(&client->irq);
>  
>  	/*
>  	 * Set current interval to the greater of the minimum interval or
> @@ -326,9 +325,6 @@ static ssize_t kxtj9_set_poll(struct device *dev, struct device_attribute *attr,
>  
>  	kxtj9_update_odr(tj9, tj9->last_poll_interval);
>  
> -	enable_irq(client->irq);
> -	mutex_unlock(&input_dev->mutex);
> -
>  	return count;
>  }
>  
> @@ -504,12 +500,11 @@ static int kxtj9_suspend(struct device *dev)
>  	struct kxtj9_data *tj9 = i2c_get_clientdata(client);
>  	struct input_dev *input_dev = tj9->input_dev;
>  
> -	mutex_lock(&input_dev->mutex);
> +	guard(mutex)(&input_dev->mutex);
>  
>  	if (input_device_enabled(input_dev))
>  		kxtj9_disable(tj9);
>  
> -	mutex_unlock(&input_dev->mutex);
>  	return 0;
>  }
>  
> @@ -519,12 +514,11 @@ static int kxtj9_resume(struct device *dev)
>  	struct kxtj9_data *tj9 = i2c_get_clientdata(client);
>  	struct input_dev *input_dev = tj9->input_dev;
>  
> -	mutex_lock(&input_dev->mutex);
> +	guard(mutex)(&input_dev->mutex);
>  
>  	if (input_device_enabled(input_dev))
>  		kxtj9_enable(tj9);
>  
> -	mutex_unlock(&input_dev->mutex);
>  	return 0;
>  }
>  

Reviewed-by: Javier Carrasco <javier.carrasco.cruz@...il.com>

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ