[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <d946c659-7726-4e56-b408-0ad5c2cd7e67@gmail.com>
Date: Wed, 4 Sep 2024 20:47:49 +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
Subject: Re: [PATCH 01/22] Input: ad714x - use guard notation when acquiring
mutex
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 in all code paths
> when control leaves critical section.
>
> Signed-off-by: Dmitry Torokhov <dmitry.torokhov@...il.com>
> ---
> drivers/input/misc/ad714x.c | 12 +++---------
> 1 file changed, 3 insertions(+), 9 deletions(-)
>
> diff --git a/drivers/input/misc/ad714x.c b/drivers/input/misc/ad714x.c
> index 1acd8429c56c..d106f37df6bc 100644
> --- a/drivers/input/misc/ad714x.c
> +++ b/drivers/input/misc/ad714x.c
> @@ -941,7 +941,7 @@ static irqreturn_t ad714x_interrupt_thread(int irq, void *data)
> struct ad714x_chip *ad714x = data;
> int i;
>
> - mutex_lock(&ad714x->mutex);
> + guard(mutex)(&ad714x->mutex);
>
> ad714x->read(ad714x, STG_LOW_INT_STA_REG, &ad714x->l_state, 3);
>
> @@ -954,8 +954,6 @@ static irqreturn_t ad714x_interrupt_thread(int irq, void *data)
> for (i = 0; i < ad714x->hw->touchpad_num; i++)
> ad714x_touchpad_state_machine(ad714x, i);
>
> - mutex_unlock(&ad714x->mutex);
> -
> return IRQ_HANDLED;
> }
>
> @@ -1169,13 +1167,11 @@ static int ad714x_suspend(struct device *dev)
>
> dev_dbg(ad714x->dev, "%s enter\n", __func__);
>
> - mutex_lock(&ad714x->mutex);
> + guard(mutex)(&ad714x->mutex);
>
> data = ad714x->hw->sys_cfg_reg[AD714X_PWR_CTRL] | 0x3;
> ad714x->write(ad714x, AD714X_PWR_CTRL, data);
>
> - mutex_unlock(&ad714x->mutex);
> -
> return 0;
> }
>
> @@ -1184,7 +1180,7 @@ static int ad714x_resume(struct device *dev)
> struct ad714x_chip *ad714x = dev_get_drvdata(dev);
> dev_dbg(ad714x->dev, "%s enter\n", __func__);
>
> - mutex_lock(&ad714x->mutex);
> + guard(mutex)(&ad714x->mutex);
>
> /* resume to non-shutdown mode */
>
> @@ -1197,8 +1193,6 @@ static int ad714x_resume(struct device *dev)
>
> ad714x->read(ad714x, STG_LOW_INT_STA_REG, &ad714x->l_state, 3);
>
> - mutex_unlock(&ad714x->mutex);
> -
> return 0;
> }
>
Reviewed-by: Javier Carrasco <javier.carrasco.cruz@...il.com>
Powered by blists - more mailing lists