linux-input.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] Input: bcm5974 - use guard notation when acquiring mutex
@ 2024-08-25  5:29 Dmitry Torokhov
  2024-08-25  9:09 ` rydberg
  2024-08-25 20:02 ` Markus Elfring
  0 siblings, 2 replies; 3+ messages in thread
From: Dmitry Torokhov @ 2024-08-25  5:29 UTC (permalink / raw)
  To: linux-input; +Cc: Henrik Rydberg, Javier Carrasco, Erick Archer, linux-kernel

This 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@gmail.com>
---
 drivers/input/mouse/bcm5974.c | 35 +++++++++++++----------------------
 1 file changed, 13 insertions(+), 22 deletions(-)

diff --git a/drivers/input/mouse/bcm5974.c b/drivers/input/mouse/bcm5974.c
index 10a03a566905..dfdfb59cc8b5 100644
--- a/drivers/input/mouse/bcm5974.c
+++ b/drivers/input/mouse/bcm5974.c
@@ -834,13 +834,11 @@ static int bcm5974_open(struct input_dev *input)
 	if (error)
 		return error;
 
-	mutex_lock(&dev->pm_mutex);
-
-	error = bcm5974_start_traffic(dev);
-	if (!error)
-		dev->opened = 1;
-
-	mutex_unlock(&dev->pm_mutex);
+	scoped_guard(mutex, &dev->pm_mutex) {
+		error = bcm5974_start_traffic(dev);
+		if (!error)
+			dev->opened = 1;
+	}
 
 	if (error)
 		usb_autopm_put_interface(dev->intf);
@@ -852,12 +850,10 @@ static void bcm5974_close(struct input_dev *input)
 {
 	struct bcm5974 *dev = input_get_drvdata(input);
 
-	mutex_lock(&dev->pm_mutex);
-
-	bcm5974_pause_traffic(dev);
-	dev->opened = 0;
-
-	mutex_unlock(&dev->pm_mutex);
+	scoped_guard(mutex, &dev->pm_mutex) {
+		bcm5974_pause_traffic(dev);
+		dev->opened = 0;
+	}
 
 	usb_autopm_put_interface(dev->intf);
 }
@@ -866,29 +862,24 @@ static int bcm5974_suspend(struct usb_interface *iface, pm_message_t message)
 {
 	struct bcm5974 *dev = usb_get_intfdata(iface);
 
-	mutex_lock(&dev->pm_mutex);
+	guard(mutex)(&dev->pm_mutex);
 
 	if (dev->opened)
 		bcm5974_pause_traffic(dev);
 
-	mutex_unlock(&dev->pm_mutex);
-
 	return 0;
 }
 
 static int bcm5974_resume(struct usb_interface *iface)
 {
 	struct bcm5974 *dev = usb_get_intfdata(iface);
-	int error = 0;
 
-	mutex_lock(&dev->pm_mutex);
+	guard(mutex)(&dev->pm_mutex);
 
 	if (dev->opened)
-		error = bcm5974_start_traffic(dev);
+		return bcm5974_start_traffic(dev);
 
-	mutex_unlock(&dev->pm_mutex);
-
-	return error;
+	return 0;
 }
 
 static int bcm5974_probe(struct usb_interface *iface,
-- 
2.46.0.295.g3b9ea8a38a-goog


-- 
Dmitry

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] Input: bcm5974 - use guard notation when acquiring mutex
  2024-08-25  5:29 [PATCH] Input: bcm5974 - use guard notation when acquiring mutex Dmitry Torokhov
@ 2024-08-25  9:09 ` rydberg
  2024-08-25 20:02 ` Markus Elfring
  1 sibling, 0 replies; 3+ messages in thread
From: rydberg @ 2024-08-25  9:09 UTC (permalink / raw)
  To: Dmitry Torokhov; +Cc: linux-input, Javier Carrasco, Erick Archer, linux-kernel

On Sat, Aug 24, 2024 at 10:29:56PM -0700, Dmitry Torokhov wrote:
> This 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@gmail.com>
> ---
>  drivers/input/mouse/bcm5974.c | 35 +++++++++++++----------------------
>  1 file changed, 13 insertions(+), 22 deletions(-)
> 

Thanks Dmitry,

Acked-by: Henrik Rydberg <rydberg@bitmath.org>

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] Input: bcm5974 - use guard notation when acquiring mutex
  2024-08-25  5:29 [PATCH] Input: bcm5974 - use guard notation when acquiring mutex Dmitry Torokhov
  2024-08-25  9:09 ` rydberg
@ 2024-08-25 20:02 ` Markus Elfring
  1 sibling, 0 replies; 3+ messages in thread
From: Markus Elfring @ 2024-08-25 20:02 UTC (permalink / raw)
  To: Dmitry Torokhov, linux-input
  Cc: LKML, Erick Archer, Henrik Rydberg, Javier Carrasco

> This makes the code …

Is there a need to improve such a change description with imperative wordings?
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/process/submitting-patches.rst?h=v6.11-rc5#n94

Regards,
Markus

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2024-08-25 20:02 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-08-25  5:29 [PATCH] Input: bcm5974 - use guard notation when acquiring mutex Dmitry Torokhov
2024-08-25  9:09 ` rydberg
2024-08-25 20:02 ` Markus Elfring

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).