Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

Input: pxrc - simplify mutex handling with guard macro

Use the guard(mutex) macro for handle mutex lock/unlocks.

Signed-off-by: Marcus Folkesson <marcus.folkesson@gmail.com>
Link: https://lore.kernel.org/r/20231202-pxrc-guard-v3-1-2ca8bc8cf689@gmail.com
Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>

authored by

Marcus Folkesson and committed by
Dmitry Torokhov
90948416 d3e09f57

+18 -24
+18 -24
drivers/input/joystick/pxrc.c
··· 5 5 * Copyright (C) 2018 Marcus Folkesson <marcus.folkesson@gmail.com> 6 6 */ 7 7 8 - #include <linux/kernel.h> 8 + #include <linux/cleanup.h> 9 9 #include <linux/errno.h> 10 - #include <linux/slab.h> 10 + #include <linux/input.h> 11 + #include <linux/kernel.h> 11 12 #include <linux/module.h> 13 + #include <linux/mutex.h> 14 + #include <linux/slab.h> 12 15 #include <linux/uaccess.h> 16 + 13 17 #include <linux/usb.h> 14 18 #include <linux/usb/input.h> 15 - #include <linux/mutex.h> 16 - #include <linux/input.h> 17 19 18 20 #define PXRC_VENDOR_ID 0x1781 19 21 #define PXRC_PRODUCT_ID 0x0898 ··· 83 81 static int pxrc_open(struct input_dev *input) 84 82 { 85 83 struct pxrc *pxrc = input_get_drvdata(input); 86 - int retval; 84 + int error; 87 85 88 - mutex_lock(&pxrc->pm_mutex); 89 - retval = usb_submit_urb(pxrc->urb, GFP_KERNEL); 90 - if (retval) { 86 + guard(mutex)(&pxrc->pm_mutex); 87 + error = usb_submit_urb(pxrc->urb, GFP_KERNEL); 88 + if (error) { 91 89 dev_err(&pxrc->intf->dev, 92 90 "%s - usb_submit_urb failed, error: %d\n", 93 - __func__, retval); 94 - retval = -EIO; 95 - goto out; 91 + __func__, error); 92 + return -EIO; 96 93 } 97 94 98 95 pxrc->is_open = true; 99 - 100 - out: 101 - mutex_unlock(&pxrc->pm_mutex); 102 - return retval; 96 + return 0; 103 97 } 104 98 105 99 static void pxrc_close(struct input_dev *input) 106 100 { 107 101 struct pxrc *pxrc = input_get_drvdata(input); 108 102 109 - mutex_lock(&pxrc->pm_mutex); 103 + guard(mutex)(&pxrc->pm_mutex); 110 104 usb_kill_urb(pxrc->urb); 111 105 pxrc->is_open = false; 112 - mutex_unlock(&pxrc->pm_mutex); 113 106 } 114 107 115 108 static void pxrc_free_urb(void *_pxrc) ··· 205 208 { 206 209 struct pxrc *pxrc = usb_get_intfdata(intf); 207 210 208 - mutex_lock(&pxrc->pm_mutex); 211 + guard(mutex)(&pxrc->pm_mutex); 209 212 if (pxrc->is_open) 210 213 usb_kill_urb(pxrc->urb); 211 - mutex_unlock(&pxrc->pm_mutex); 212 214 213 215 return 0; 214 216 } ··· 215 219 static int pxrc_resume(struct usb_interface *intf) 216 220 { 217 221 struct pxrc *pxrc = usb_get_intfdata(intf); 218 - int retval = 0; 219 222 220 - mutex_lock(&pxrc->pm_mutex); 223 + guard(mutex)(&pxrc->pm_mutex); 221 224 if (pxrc->is_open && usb_submit_urb(pxrc->urb, GFP_KERNEL) < 0) 222 - retval = -EIO; 225 + return -EIO; 223 226 224 - mutex_unlock(&pxrc->pm_mutex); 225 - return retval; 227 + return 0; 226 228 } 227 229 228 230 static int pxrc_pre_reset(struct usb_interface *intf)