[PATCH 11/22] Input: ibm-panel - use guard notation when acquiring spinlock

Dmitry Torokhov posted 22 patches 1 year, 3 months ago
[PATCH 11/22] Input: ibm-panel - use guard notation when acquiring spinlock
Posted by Dmitry Torokhov 1 year, 3 months ago
Using guard notation makes the code more compact and error handling
more robust by ensuring that locks are released in all code paths
when control leaves critical section.

Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
---
 drivers/input/misc/ibm-panel.c | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)

diff --git a/drivers/input/misc/ibm-panel.c b/drivers/input/misc/ibm-panel.c
index 867ac7aa10d2..aa48f62d7ea0 100644
--- a/drivers/input/misc/ibm-panel.c
+++ b/drivers/input/misc/ibm-panel.c
@@ -77,12 +77,11 @@ static void ibm_panel_process_command(struct ibm_panel *panel)
 static int ibm_panel_i2c_slave_cb(struct i2c_client *client,
 				  enum i2c_slave_event event, u8 *val)
 {
-	unsigned long flags;
 	struct ibm_panel *panel = i2c_get_clientdata(client);
 
 	dev_dbg(&panel->input->dev, "event: %u data: %02x\n", event, *val);
 
-	spin_lock_irqsave(&panel->lock, flags);
+	guard(spinlock_irqsave)(&panel->lock);
 
 	switch (event) {
 	case I2C_SLAVE_STOP:
@@ -114,8 +113,6 @@ static int ibm_panel_i2c_slave_cb(struct i2c_client *client,
 		break;
 	}
 
-	spin_unlock_irqrestore(&panel->lock, flags);
-
 	return 0;
 }
 
-- 
2.46.0.469.g59c65b2a67-goog
Re: [PATCH 11/22] Input: ibm-panel - use guard notation when acquiring spinlock
Posted by Eddie James 1 year, 3 months ago
On 9/3/24 23:47, Dmitry Torokhov wrote:
> Using guard notation makes the code more compact and error handling
> more robust by ensuring that locks are released in all code paths
> when control leaves critical section.


Reviewed-by: Eddie James <eajames@linux.ibm.com>


>
> Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
> ---
>   drivers/input/misc/ibm-panel.c | 5 +----
>   1 file changed, 1 insertion(+), 4 deletions(-)
>
> diff --git a/drivers/input/misc/ibm-panel.c b/drivers/input/misc/ibm-panel.c
> index 867ac7aa10d2..aa48f62d7ea0 100644
> --- a/drivers/input/misc/ibm-panel.c
> +++ b/drivers/input/misc/ibm-panel.c
> @@ -77,12 +77,11 @@ static void ibm_panel_process_command(struct ibm_panel *panel)
>   static int ibm_panel_i2c_slave_cb(struct i2c_client *client,
>   				  enum i2c_slave_event event, u8 *val)
>   {
> -	unsigned long flags;
>   	struct ibm_panel *panel = i2c_get_clientdata(client);
>   
>   	dev_dbg(&panel->input->dev, "event: %u data: %02x\n", event, *val);
>   
> -	spin_lock_irqsave(&panel->lock, flags);
> +	guard(spinlock_irqsave)(&panel->lock);
>   
>   	switch (event) {
>   	case I2C_SLAVE_STOP:
> @@ -114,8 +113,6 @@ static int ibm_panel_i2c_slave_cb(struct i2c_client *client,
>   		break;
>   	}
>   
> -	spin_unlock_irqrestore(&panel->lock, flags);
> -
>   	return 0;
>   }
>
Re: [PATCH 11/22] Input: ibm-panel - use guard notation when acquiring spinlock
Posted by Javier Carrasco 1 year, 3 months ago
On 04/09/2024 06:47, Dmitry Torokhov wrote:
> Using guard notation makes the code more compact and error handling
> more robust by ensuring that locks are released in all code paths
> when control leaves critical section.
> 
> Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
> ---
>  drivers/input/misc/ibm-panel.c | 5 +----
>  1 file changed, 1 insertion(+), 4 deletions(-)
> 
> diff --git a/drivers/input/misc/ibm-panel.c b/drivers/input/misc/ibm-panel.c
> index 867ac7aa10d2..aa48f62d7ea0 100644
> --- a/drivers/input/misc/ibm-panel.c
> +++ b/drivers/input/misc/ibm-panel.c
> @@ -77,12 +77,11 @@ static void ibm_panel_process_command(struct ibm_panel *panel)
>  static int ibm_panel_i2c_slave_cb(struct i2c_client *client,
>  				  enum i2c_slave_event event, u8 *val)
>  {
> -	unsigned long flags;
>  	struct ibm_panel *panel = i2c_get_clientdata(client);
>  
>  	dev_dbg(&panel->input->dev, "event: %u data: %02x\n", event, *val);
>  
> -	spin_lock_irqsave(&panel->lock, flags);
> +	guard(spinlock_irqsave)(&panel->lock);
>  
>  	switch (event) {
>  	case I2C_SLAVE_STOP:
> @@ -114,8 +113,6 @@ static int ibm_panel_i2c_slave_cb(struct i2c_client *client,
>  		break;
>  	}
>  
> -	spin_unlock_irqrestore(&panel->lock, flags);
> -
>  	return 0;
>  }
>  

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