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

Merge tag 'input-for-v6.13-rc0' of git://git.kernel.org/pub/scm/linux/kernel/git/dtor/input

Pull input updates from Dmitry Torokhov:

- support for NT36672A touchscreen added to novatek-nvt-ts driver

- a change to ads7846 driver to prevent XPT2046 from locking up

- a change switching platform input dirves back to using remove()
method (from remove_new())

- updates to a number of input drivers to use the new cleanup
facilities (__free(...), guard(), and scoped-guard()) which ensure
that the resources and locks are released properly and automatically

- other assorted driver cleanups and fixes.

* tag 'input-for-v6.13-rc0' of git://git.kernel.org/pub/scm/linux/kernel/git/dtor/input: (109 commits)
Input: mpr121 - use devm_regulator_get_enable_read_voltage()
Input: sun4i-lradc-keys - don't include 'pm_wakeup.h' directly
Input: spear-keyboard - don't include 'pm_wakeup.h' directly
Input: cypress-sf - constify struct i2c_device_id
Input: ads7846 - increase xfer array size in 'struct ser_req'
Input: fix the input_event struct documentation
Input: i8042 - fix typo dublicate to duplicate
Input: ads7846 - add dummy command register clearing cycle
Input: cs40l50 - fix wrong usage of INIT_WORK()
Input: introduce notion of passive observers for input handlers
Input: maple_keyb - use guard notation when acquiring mutex
Input: locomokbd - use guard notation when acquiring spinlock
Input: hilkbd - use guard notation when acquiring spinlock
Input: synaptics-rmi4 - switch to using cleanup functions in F34
Input: synaptics - fix a typo
dt-bindings: input: rotary-encoder: Fix "rotary-encoder,rollover" type
Input: omap-keypad - use guard notation when acquiring mutex
Input: imagis - fix warning regarding 'imagis_3038_data' being unused
Input: userio - remove unneeded semicolon
Input: sparcspkr - use cleanup facility for device_node
...

+1530 -1862
+1
Documentation/devicetree/bindings/input/mediatek,pmic-keys.yaml
··· 28 28 - mediatek,mt6331-keys 29 29 - mediatek,mt6357-keys 30 30 - mediatek,mt6358-keys 31 + - mediatek,mt6359-keys 31 32 - mediatek,mt6397-keys 32 33 33 34 power-off-time-sec: true
+1 -1
Documentation/devicetree/bindings/input/rotary-encoder.yaml
··· 41 41 device, hence no steps need to be passed. 42 42 43 43 rotary-encoder,rollover: 44 - $ref: /schemas/types.yaml#/definitions/int32 44 + $ref: /schemas/types.yaml#/definitions/flag 45 45 description: 46 46 Automatic rollover when the rotary value becomes 47 47 greater than the specified steps or smaller than 0. For absolute axis only.
+62
Documentation/devicetree/bindings/input/touchscreen/novatek,nvt-ts.yaml
··· 1 + # SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) 2 + %YAML 1.2 3 + --- 4 + $id: http://devicetree.org/schemas/input/touchscreen/novatek,nvt-ts.yaml# 5 + $schema: http://devicetree.org/meta-schemas/core.yaml# 6 + 7 + title: Novatek NVT Touchscreen Controller 8 + 9 + maintainers: 10 + - Hans de Goede <hdegoede@redhat.com> 11 + 12 + allOf: 13 + - $ref: touchscreen.yaml# 14 + 15 + properties: 16 + compatible: 17 + enum: 18 + - novatek,nt11205-ts 19 + - novatek,nt36672a-ts 20 + 21 + reg: 22 + maxItems: 1 23 + 24 + interrupts: 25 + maxItems: 1 26 + 27 + reset-gpios: 28 + maxItems: 1 29 + 30 + vcc-supply: true 31 + iovcc-supply: true 32 + 33 + required: 34 + - compatible 35 + - reg 36 + - interrupts 37 + 38 + unevaluatedProperties: false 39 + 40 + examples: 41 + - | 42 + #include <dt-bindings/gpio/gpio.h> 43 + #include <dt-bindings/interrupt-controller/arm-gic.h> 44 + i2c { 45 + #address-cells = <1>; 46 + #size-cells = <0>; 47 + touchscreen@1 { 48 + compatible = "novatek,nt36672a-ts"; 49 + reg = <0x01>; 50 + interrupts-extended = <&tlmm 31 IRQ_TYPE_EDGE_RISING>; 51 + reset-gpios = <&tlmm 32 GPIO_ACTIVE_LOW>; 52 + vcc-supply = <&vreg_l22a_2p85>; 53 + iovcc-supply = <&vreg_l14a_1p8>; 54 + pinctrl-0 = <&ts_int_default &ts_reset_default>; 55 + pinctrl-1 = <&ts_int_sleep &ts_reset_sleep>; 56 + pinctrl-names = "default", "sleep"; 57 + touchscreen-size-x = <1080>; 58 + touchscreen-size-y = <2246>; 59 + }; 60 + }; 61 + 62 + ...
+1 -1
Documentation/input/input.rst
··· 264 264 struct timeval time; 265 265 unsigned short type; 266 266 unsigned short code; 267 - unsigned int value; 267 + int value; 268 268 }; 269 269 270 270 ``time`` is the timestamp, it returns the time at which the event happened.
+1
MAINTAINERS
··· 16570 16570 M: Hans de Goede <hdegoede@redhat.com> 16571 16571 L: linux-input@vger.kernel.org 16572 16572 S: Maintained 16573 + F: Documentation/devicetree/bindings/input/touchscreen/novatek,nvt-ts.yaml 16573 16574 F: drivers/input/touchscreen/novatek-nvt-ts.c 16574 16575 16575 16576 NSDEPS
+10 -5
drivers/input/input.c
··· 605 605 606 606 handle->open++; 607 607 608 + if (handle->handler->passive_observer) 609 + goto out; 610 + 608 611 if (dev->users++ || dev->inhibited) { 609 612 /* 610 613 * Device is already opened and/or inhibited, ··· 671 668 672 669 __input_release_device(handle); 673 670 674 - if (!--dev->users && !dev->inhibited) { 675 - if (dev->poller) 676 - input_dev_poller_stop(dev->poller); 677 - if (dev->close) 678 - dev->close(dev); 671 + if (!handle->handler->passive_observer) { 672 + if (!--dev->users && !dev->inhibited) { 673 + if (dev->poller) 674 + input_dev_poller_stop(dev->poller); 675 + if (dev->close) 676 + dev->close(dev); 677 + } 679 678 } 680 679 681 680 if (!--handle->open) {
+14 -16
drivers/input/joystick/db9.c
··· 505 505 { 506 506 struct db9 *db9 = input_get_drvdata(dev); 507 507 struct parport *port = db9->pd->port; 508 - int err; 509 508 510 - err = mutex_lock_interruptible(&db9->mutex); 511 - if (err) 512 - return err; 513 - 514 - if (!db9->used++) { 515 - parport_claim(db9->pd); 516 - parport_write_data(port, 0xff); 517 - if (db9_modes[db9->mode].reverse) { 518 - parport_data_reverse(port); 519 - parport_write_control(port, DB9_NORMAL); 509 + scoped_guard(mutex_intr, &db9->mutex) { 510 + if (!db9->used++) { 511 + parport_claim(db9->pd); 512 + parport_write_data(port, 0xff); 513 + if (db9_modes[db9->mode].reverse) { 514 + parport_data_reverse(port); 515 + parport_write_control(port, DB9_NORMAL); 516 + } 517 + mod_timer(&db9->timer, jiffies + DB9_REFRESH_TIME); 520 518 } 521 - mod_timer(&db9->timer, jiffies + DB9_REFRESH_TIME); 519 + 520 + return 0; 522 521 } 523 522 524 - mutex_unlock(&db9->mutex); 525 - return 0; 523 + return -EINTR; 526 524 } 527 525 528 526 static void db9_close(struct input_dev *dev) ··· 528 530 struct db9 *db9 = input_get_drvdata(dev); 529 531 struct parport *port = db9->pd->port; 530 532 531 - mutex_lock(&db9->mutex); 533 + guard(mutex)(&db9->mutex); 534 + 532 535 if (!--db9->used) { 533 536 del_timer_sync(&db9->timer); 534 537 parport_write_control(port, 0x00); 535 538 parport_data_forward(port); 536 539 parport_release(db9->pd); 537 540 } 538 - mutex_unlock(&db9->mutex); 539 541 } 540 542 541 543 static void db9_attach(struct parport *pp)
+10 -12
drivers/input/joystick/gamecon.c
··· 765 765 static int gc_open(struct input_dev *dev) 766 766 { 767 767 struct gc *gc = input_get_drvdata(dev); 768 - int err; 769 768 770 - err = mutex_lock_interruptible(&gc->mutex); 771 - if (err) 772 - return err; 769 + scoped_guard(mutex_intr, &gc->mutex) { 770 + if (!gc->used++) { 771 + parport_claim(gc->pd); 772 + parport_write_control(gc->pd->port, 0x04); 773 + mod_timer(&gc->timer, jiffies + GC_REFRESH_TIME); 774 + } 773 775 774 - if (!gc->used++) { 775 - parport_claim(gc->pd); 776 - parport_write_control(gc->pd->port, 0x04); 777 - mod_timer(&gc->timer, jiffies + GC_REFRESH_TIME); 776 + return 0; 778 777 } 779 778 780 - mutex_unlock(&gc->mutex); 781 - return 0; 779 + return -EINTR; 782 780 } 783 781 784 782 static void gc_close(struct input_dev *dev) 785 783 { 786 784 struct gc *gc = input_get_drvdata(dev); 787 785 788 - mutex_lock(&gc->mutex); 786 + guard(mutex)(&gc->mutex); 787 + 789 788 if (!--gc->used) { 790 789 del_timer_sync(&gc->timer); 791 790 parport_write_control(gc->pd->port, 0x00); 792 791 parport_release(gc->pd); 793 792 } 794 - mutex_unlock(&gc->mutex); 795 793 } 796 794 797 795 static int gc_setup_pad(struct gc *gc, int idx, int pad_type)
+22 -26
drivers/input/joystick/iforce/iforce-ff.c
··· 21 21 unsigned char data[3]; 22 22 23 23 if (!no_alloc) { 24 - mutex_lock(&iforce->mem_mutex); 25 - if (allocate_resource(&(iforce->device_memory), mod_chunk, 2, 26 - iforce->device_memory.start, iforce->device_memory.end, 2L, 27 - NULL, NULL)) { 28 - mutex_unlock(&iforce->mem_mutex); 24 + guard(mutex)(&iforce->mem_mutex); 25 + 26 + if (allocate_resource(&iforce->device_memory, mod_chunk, 2, 27 + iforce->device_memory.start, 28 + iforce->device_memory.end, 29 + 2L, NULL, NULL)) 29 30 return -ENOSPC; 30 - } 31 - mutex_unlock(&iforce->mem_mutex); 32 31 } 33 32 34 33 data[0] = LO(mod_chunk->start); ··· 53 54 period = TIME_SCALE(period); 54 55 55 56 if (!no_alloc) { 56 - mutex_lock(&iforce->mem_mutex); 57 - if (allocate_resource(&(iforce->device_memory), mod_chunk, 0x0c, 58 - iforce->device_memory.start, iforce->device_memory.end, 2L, 59 - NULL, NULL)) { 60 - mutex_unlock(&iforce->mem_mutex); 57 + guard(mutex)(&iforce->mem_mutex); 58 + 59 + if (allocate_resource(&iforce->device_memory, mod_chunk, 0x0c, 60 + iforce->device_memory.start, 61 + iforce->device_memory.end, 62 + 2L, NULL, NULL)) 61 63 return -ENOSPC; 62 - } 63 - mutex_unlock(&iforce->mem_mutex); 64 64 } 65 65 66 66 data[0] = LO(mod_chunk->start); ··· 92 94 fade_duration = TIME_SCALE(fade_duration); 93 95 94 96 if (!no_alloc) { 95 - mutex_lock(&iforce->mem_mutex); 97 + guard(mutex)(&iforce->mem_mutex); 98 + 96 99 if (allocate_resource(&(iforce->device_memory), mod_chunk, 0x0e, 97 - iforce->device_memory.start, iforce->device_memory.end, 2L, 98 - NULL, NULL)) { 99 - mutex_unlock(&iforce->mem_mutex); 100 + iforce->device_memory.start, 101 + iforce->device_memory.end, 102 + 2L, NULL, NULL)) 100 103 return -ENOSPC; 101 - } 102 - mutex_unlock(&iforce->mem_mutex); 103 104 } 104 105 105 106 data[0] = LO(mod_chunk->start); ··· 128 131 unsigned char data[10]; 129 132 130 133 if (!no_alloc) { 131 - mutex_lock(&iforce->mem_mutex); 134 + guard(mutex)(&iforce->mem_mutex); 135 + 132 136 if (allocate_resource(&(iforce->device_memory), mod_chunk, 8, 133 - iforce->device_memory.start, iforce->device_memory.end, 2L, 134 - NULL, NULL)) { 135 - mutex_unlock(&iforce->mem_mutex); 137 + iforce->device_memory.start, 138 + iforce->device_memory.end, 139 + 2L, NULL, NULL)) 136 140 return -ENOSPC; 137 - } 138 - mutex_unlock(&iforce->mem_mutex); 139 141 } 140 142 141 143 data[0] = LO(mod_chunk->start);
+22 -29
drivers/input/joystick/iforce/iforce-packets.c
··· 31 31 int c; 32 32 int empty; 33 33 int head, tail; 34 - unsigned long flags; 35 34 36 35 /* 37 36 * Update head and tail of xmit buffer 38 37 */ 39 - spin_lock_irqsave(&iforce->xmit_lock, flags); 38 + scoped_guard(spinlock_irqsave, &iforce->xmit_lock) { 39 + head = iforce->xmit.head; 40 + tail = iforce->xmit.tail; 40 41 41 - head = iforce->xmit.head; 42 - tail = iforce->xmit.tail; 42 + if (CIRC_SPACE(head, tail, XMIT_SIZE) < n + 2) { 43 + dev_warn(&iforce->dev->dev, 44 + "not enough space in xmit buffer to send new packet\n"); 45 + return -1; 46 + } 43 47 44 - 45 - if (CIRC_SPACE(head, tail, XMIT_SIZE) < n+2) { 46 - dev_warn(&iforce->dev->dev, 47 - "not enough space in xmit buffer to send new packet\n"); 48 - spin_unlock_irqrestore(&iforce->xmit_lock, flags); 49 - return -1; 50 - } 51 - 52 - empty = head == tail; 53 - XMIT_INC(iforce->xmit.head, n+2); 48 + empty = head == tail; 49 + XMIT_INC(iforce->xmit.head, n + 2); 54 50 55 51 /* 56 52 * Store packet in xmit buffer 57 53 */ 58 - iforce->xmit.buf[head] = HI(cmd); 59 - XMIT_INC(head, 1); 60 - iforce->xmit.buf[head] = LO(cmd); 61 - XMIT_INC(head, 1); 54 + iforce->xmit.buf[head] = HI(cmd); 55 + XMIT_INC(head, 1); 56 + iforce->xmit.buf[head] = LO(cmd); 57 + XMIT_INC(head, 1); 62 58 63 - c = CIRC_SPACE_TO_END(head, tail, XMIT_SIZE); 64 - if (n < c) c=n; 59 + c = CIRC_SPACE_TO_END(head, tail, XMIT_SIZE); 60 + if (n < c) 61 + c = n; 65 62 66 - memcpy(&iforce->xmit.buf[head], 67 - data, 68 - c); 69 - if (n != c) { 70 - memcpy(&iforce->xmit.buf[0], 71 - data + c, 72 - n - c); 63 + memcpy(&iforce->xmit.buf[head], data, c); 64 + if (n != c) 65 + memcpy(&iforce->xmit.buf[0], data + c, n - c); 66 + 67 + XMIT_INC(head, n); 73 68 } 74 - XMIT_INC(head, n); 75 69 76 - spin_unlock_irqrestore(&iforce->xmit_lock, flags); 77 70 /* 78 71 * If necessary, start the transmission 79 72 */
+15 -21
drivers/input/joystick/iforce/iforce-serio.c
··· 28 28 iforce); 29 29 unsigned char cs; 30 30 int i; 31 - unsigned long flags; 32 31 33 32 if (test_and_set_bit(IFORCE_XMIT_RUNNING, iforce->xmit_flags)) { 34 33 set_bit(IFORCE_XMIT_AGAIN, iforce->xmit_flags); 35 34 return; 36 35 } 37 36 38 - spin_lock_irqsave(&iforce->xmit_lock, flags); 37 + guard(spinlock_irqsave)(&iforce->xmit_lock); 39 38 40 - again: 41 - if (iforce->xmit.head == iforce->xmit.tail) { 42 - iforce_clear_xmit_and_wake(iforce); 43 - spin_unlock_irqrestore(&iforce->xmit_lock, flags); 44 - return; 45 - } 39 + do { 40 + if (iforce->xmit.head == iforce->xmit.tail) 41 + break; 46 42 47 - cs = 0x2b; 43 + cs = 0x2b; 48 44 49 - serio_write(iforce_serio->serio, 0x2b); 45 + serio_write(iforce_serio->serio, 0x2b); 50 46 51 - serio_write(iforce_serio->serio, iforce->xmit.buf[iforce->xmit.tail]); 52 - cs ^= iforce->xmit.buf[iforce->xmit.tail]; 53 - XMIT_INC(iforce->xmit.tail, 1); 54 - 55 - for (i=iforce->xmit.buf[iforce->xmit.tail]; i >= 0; --i) { 56 47 serio_write(iforce_serio->serio, 57 48 iforce->xmit.buf[iforce->xmit.tail]); 58 49 cs ^= iforce->xmit.buf[iforce->xmit.tail]; 59 50 XMIT_INC(iforce->xmit.tail, 1); 60 - } 61 51 62 - serio_write(iforce_serio->serio, cs); 52 + for (i = iforce->xmit.buf[iforce->xmit.tail]; i >= 0; --i) { 53 + serio_write(iforce_serio->serio, 54 + iforce->xmit.buf[iforce->xmit.tail]); 55 + cs ^= iforce->xmit.buf[iforce->xmit.tail]; 56 + XMIT_INC(iforce->xmit.tail, 1); 57 + } 63 58 64 - if (test_and_clear_bit(IFORCE_XMIT_AGAIN, iforce->xmit_flags)) 65 - goto again; 59 + serio_write(iforce_serio->serio, cs); 60 + 61 + } while (test_and_clear_bit(IFORCE_XMIT_AGAIN, iforce->xmit_flags)); 66 62 67 63 iforce_clear_xmit_and_wake(iforce); 68 - 69 - spin_unlock_irqrestore(&iforce->xmit_lock, flags); 70 64 } 71 65 72 66 static int iforce_serio_get_id(struct iforce *iforce, u8 id,
+6 -7
drivers/input/joystick/iforce/iforce-usb.c
··· 25 25 struct iforce_usb *iforce_usb = container_of(iforce, struct iforce_usb, 26 26 iforce); 27 27 int n, c; 28 - unsigned long flags; 29 28 30 - spin_lock_irqsave(&iforce->xmit_lock, flags); 29 + guard(spinlock_irqsave)(&iforce->xmit_lock); 31 30 32 31 if (iforce->xmit.head == iforce->xmit.tail) { 33 32 iforce_clear_xmit_and_wake(iforce); 34 - spin_unlock_irqrestore(&iforce->xmit_lock, flags); 35 33 return; 36 34 } 37 35 ··· 43 45 44 46 /* Copy rest of data then */ 45 47 c = CIRC_CNT_TO_END(iforce->xmit.head, iforce->xmit.tail, XMIT_SIZE); 46 - if (n < c) c=n; 48 + if (n < c) 49 + c = n; 47 50 48 51 memcpy(iforce_usb->out->transfer_buffer + 1, 49 52 &iforce->xmit.buf[iforce->xmit.tail], ··· 52 53 if (n != c) { 53 54 memcpy(iforce_usb->out->transfer_buffer + 1 + c, 54 55 &iforce->xmit.buf[0], 55 - n-c); 56 + n - c); 56 57 } 57 58 XMIT_INC(iforce->xmit.tail, n); 58 59 59 - if ( (n=usb_submit_urb(iforce_usb->out, GFP_ATOMIC)) ) { 60 + n=usb_submit_urb(iforce_usb->out, GFP_ATOMIC); 61 + if (n) { 60 62 dev_warn(&iforce_usb->intf->dev, 61 63 "usb_submit_urb failed %d\n", n); 62 64 iforce_clear_xmit_and_wake(iforce); ··· 66 66 /* The IFORCE_XMIT_RUNNING bit is not cleared here. That's intended. 67 67 * As long as the urb completion handler is not called, the transmiting 68 68 * is considered to be running */ 69 - spin_unlock_irqrestore(&iforce->xmit_lock, flags); 70 69 } 71 70 72 71 static void iforce_usb_xmit(struct iforce *iforce)
+14 -17
drivers/input/joystick/n64joy.c
··· 191 191 static int n64joy_open(struct input_dev *dev) 192 192 { 193 193 struct n64joy_priv *priv = input_get_drvdata(dev); 194 - int err; 195 194 196 - err = mutex_lock_interruptible(&priv->n64joy_mutex); 197 - if (err) 198 - return err; 195 + scoped_guard(mutex_intr, &priv->n64joy_mutex) { 196 + if (!priv->n64joy_opened) { 197 + /* 198 + * We could use the vblank irq, but it's not important 199 + * if the poll point slightly changes. 200 + */ 201 + timer_setup(&priv->timer, n64joy_poll, 0); 202 + mod_timer(&priv->timer, jiffies + msecs_to_jiffies(16)); 203 + } 199 204 200 - if (!priv->n64joy_opened) { 201 - /* 202 - * We could use the vblank irq, but it's not important if 203 - * the poll point slightly changes. 204 - */ 205 - timer_setup(&priv->timer, n64joy_poll, 0); 206 - mod_timer(&priv->timer, jiffies + msecs_to_jiffies(16)); 205 + priv->n64joy_opened++; 206 + return 0; 207 207 } 208 208 209 - priv->n64joy_opened++; 210 - 211 - mutex_unlock(&priv->n64joy_mutex); 212 - return err; 209 + return -EINTR; 213 210 } 214 211 215 212 static void n64joy_close(struct input_dev *dev) 216 213 { 217 214 struct n64joy_priv *priv = input_get_drvdata(dev); 218 215 219 - mutex_lock(&priv->n64joy_mutex); 216 + guard(mutex)(&priv->n64joy_mutex); 217 + 220 218 if (!--priv->n64joy_opened) 221 219 del_timer_sync(&priv->timer); 222 - mutex_unlock(&priv->n64joy_mutex); 223 220 } 224 221 225 222 static const u64 __initconst scandata[] ____cacheline_aligned = {
+10 -12
drivers/input/joystick/turbografx.c
··· 103 103 static int tgfx_open(struct input_dev *dev) 104 104 { 105 105 struct tgfx *tgfx = input_get_drvdata(dev); 106 - int err; 107 106 108 - err = mutex_lock_interruptible(&tgfx->sem); 109 - if (err) 110 - return err; 107 + scoped_guard(mutex_intr, &tgfx->sem) { 108 + if (!tgfx->used++) { 109 + parport_claim(tgfx->pd); 110 + parport_write_control(tgfx->pd->port, 0x04); 111 + mod_timer(&tgfx->timer, jiffies + TGFX_REFRESH_TIME); 112 + } 111 113 112 - if (!tgfx->used++) { 113 - parport_claim(tgfx->pd); 114 - parport_write_control(tgfx->pd->port, 0x04); 115 - mod_timer(&tgfx->timer, jiffies + TGFX_REFRESH_TIME); 114 + return 0; 116 115 } 117 116 118 - mutex_unlock(&tgfx->sem); 119 - return 0; 117 + return -EINTR; 120 118 } 121 119 122 120 static void tgfx_close(struct input_dev *dev) 123 121 { 124 122 struct tgfx *tgfx = input_get_drvdata(dev); 125 123 126 - mutex_lock(&tgfx->sem); 124 + guard(mutex)(&tgfx->sem); 125 + 127 126 if (!--tgfx->used) { 128 127 del_timer_sync(&tgfx->timer); 129 128 parport_write_control(tgfx->pd->port, 0x00); 130 129 parport_release(tgfx->pd); 131 130 } 132 - mutex_unlock(&tgfx->sem); 133 131 } 134 132 135 133
+34 -65
drivers/input/joystick/xpad.c
··· 1292 1292 struct device *dev = &xpad->intf->dev; 1293 1293 int status = urb->status; 1294 1294 int error; 1295 - unsigned long flags; 1296 1295 1297 - spin_lock_irqsave(&xpad->odata_lock, flags); 1296 + guard(spinlock_irqsave)(&xpad->odata_lock); 1298 1297 1299 1298 switch (status) { 1300 1299 case 0: ··· 1327 1328 xpad->irq_out_active = false; 1328 1329 } 1329 1330 } 1330 - 1331 - spin_unlock_irqrestore(&xpad->odata_lock, flags); 1332 1331 } 1333 1332 1334 1333 static int xpad_init_output(struct usb_interface *intf, struct usb_xpad *xpad, ··· 1391 1394 { 1392 1395 struct xpad_output_packet *packet = 1393 1396 &xpad->out_packets[XPAD_OUT_CMD_IDX]; 1394 - unsigned long flags; 1395 - int retval; 1396 1397 1397 - spin_lock_irqsave(&xpad->odata_lock, flags); 1398 + guard(spinlock_irqsave)(&xpad->odata_lock); 1398 1399 1399 1400 packet->data[0] = 0x08; 1400 1401 packet->data[1] = 0x00; ··· 1411 1416 1412 1417 /* Reset the sequence so we send out presence first */ 1413 1418 xpad->last_out_packet = -1; 1414 - retval = xpad_try_sending_next_out_packet(xpad); 1415 - 1416 - spin_unlock_irqrestore(&xpad->odata_lock, flags); 1417 - 1418 - return retval; 1419 + return xpad_try_sending_next_out_packet(xpad); 1419 1420 } 1420 1421 1421 1422 static int xpad_start_xbox_one(struct usb_xpad *xpad) 1422 1423 { 1423 - unsigned long flags; 1424 - int retval; 1424 + int error; 1425 1425 1426 1426 if (usb_ifnum_to_if(xpad->udev, GIP_WIRED_INTF_AUDIO)) { 1427 1427 /* ··· 1425 1435 * Controller for Series X|S (0x20d6:0x200e) to report the 1426 1436 * guide button. 1427 1437 */ 1428 - retval = usb_set_interface(xpad->udev, 1429 - GIP_WIRED_INTF_AUDIO, 0); 1430 - if (retval) 1438 + error = usb_set_interface(xpad->udev, 1439 + GIP_WIRED_INTF_AUDIO, 0); 1440 + if (error) 1431 1441 dev_warn(&xpad->dev->dev, 1432 1442 "unable to disable audio interface: %d\n", 1433 - retval); 1443 + error); 1434 1444 } 1435 1445 1436 - spin_lock_irqsave(&xpad->odata_lock, flags); 1446 + guard(spinlock_irqsave)(&xpad->odata_lock); 1437 1447 1438 1448 /* 1439 1449 * Begin the init sequence by attempting to send a packet. ··· 1441 1451 * sending any packets from the output ring. 1442 1452 */ 1443 1453 xpad->init_seq = 0; 1444 - retval = xpad_try_sending_next_out_packet(xpad); 1445 - 1446 - spin_unlock_irqrestore(&xpad->odata_lock, flags); 1447 - 1448 - return retval; 1454 + return xpad_try_sending_next_out_packet(xpad); 1449 1455 } 1450 1456 1451 1457 static void xpadone_ack_mode_report(struct usb_xpad *xpad, u8 seq_num) 1452 1458 { 1453 - unsigned long flags; 1454 1459 struct xpad_output_packet *packet = 1455 1460 &xpad->out_packets[XPAD_OUT_CMD_IDX]; 1456 1461 static const u8 mode_report_ack[] = { ··· 1453 1468 0x00, GIP_CMD_VIRTUAL_KEY, GIP_OPT_INTERNAL, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00 1454 1469 }; 1455 1470 1456 - spin_lock_irqsave(&xpad->odata_lock, flags); 1471 + guard(spinlock_irqsave)(&xpad->odata_lock); 1457 1472 1458 1473 packet->len = sizeof(mode_report_ack); 1459 1474 memcpy(packet->data, mode_report_ack, packet->len); ··· 1463 1478 /* Reset the sequence so we send out the ack now */ 1464 1479 xpad->last_out_packet = -1; 1465 1480 xpad_try_sending_next_out_packet(xpad); 1466 - 1467 - spin_unlock_irqrestore(&xpad->odata_lock, flags); 1468 1481 } 1469 1482 1470 1483 #ifdef CONFIG_JOYSTICK_XPAD_FF ··· 1472 1489 struct xpad_output_packet *packet = &xpad->out_packets[XPAD_OUT_FF_IDX]; 1473 1490 __u16 strong; 1474 1491 __u16 weak; 1475 - int retval; 1476 - unsigned long flags; 1477 1492 1478 1493 if (effect->type != FF_RUMBLE) 1479 1494 return 0; ··· 1479 1498 strong = effect->u.rumble.strong_magnitude; 1480 1499 weak = effect->u.rumble.weak_magnitude; 1481 1500 1482 - spin_lock_irqsave(&xpad->odata_lock, flags); 1501 + guard(spinlock_irqsave)(&xpad->odata_lock); 1483 1502 1484 1503 switch (xpad->xtype) { 1485 1504 case XTYPE_XBOX: ··· 1545 1564 dev_dbg(&xpad->dev->dev, 1546 1565 "%s - rumble command sent to unsupported xpad type: %d\n", 1547 1566 __func__, xpad->xtype); 1548 - retval = -EINVAL; 1549 - goto out; 1567 + return -EINVAL; 1550 1568 } 1551 1569 1552 - retval = xpad_try_sending_next_out_packet(xpad); 1553 - 1554 - out: 1555 - spin_unlock_irqrestore(&xpad->odata_lock, flags); 1556 - return retval; 1570 + return xpad_try_sending_next_out_packet(xpad); 1557 1571 } 1558 1572 1559 1573 static int xpad_init_ff(struct usb_xpad *xpad) ··· 1601 1625 { 1602 1626 struct xpad_output_packet *packet = 1603 1627 &xpad->out_packets[XPAD_OUT_LED_IDX]; 1604 - unsigned long flags; 1605 1628 1606 1629 command %= 16; 1607 1630 1608 - spin_lock_irqsave(&xpad->odata_lock, flags); 1631 + guard(spinlock_irqsave)(&xpad->odata_lock); 1609 1632 1610 1633 switch (xpad->xtype) { 1611 1634 case XTYPE_XBOX360: ··· 1634 1659 } 1635 1660 1636 1661 xpad_try_sending_next_out_packet(xpad); 1637 - 1638 - spin_unlock_irqrestore(&xpad->odata_lock, flags); 1639 1662 } 1640 1663 1641 1664 /* ··· 1758 1785 1759 1786 static void xpad360w_poweroff_controller(struct usb_xpad *xpad) 1760 1787 { 1761 - unsigned long flags; 1762 1788 struct xpad_output_packet *packet = 1763 1789 &xpad->out_packets[XPAD_OUT_CMD_IDX]; 1764 1790 1765 - spin_lock_irqsave(&xpad->odata_lock, flags); 1791 + guard(spinlock_irqsave)(&xpad->odata_lock); 1766 1792 1767 1793 packet->data[0] = 0x00; 1768 1794 packet->data[1] = 0x00; ··· 1781 1809 /* Reset the sequence so we send out poweroff now */ 1782 1810 xpad->last_out_packet = -1; 1783 1811 xpad_try_sending_next_out_packet(xpad); 1784 - 1785 - spin_unlock_irqrestore(&xpad->odata_lock, flags); 1786 1812 } 1787 1813 1788 1814 static int xpad360w_start_input(struct usb_xpad *xpad) ··· 2204 2234 if (auto_poweroff && xpad->pad_present) 2205 2235 xpad360w_poweroff_controller(xpad); 2206 2236 } else { 2207 - mutex_lock(&input->mutex); 2237 + guard(mutex)(&input->mutex); 2238 + 2208 2239 if (input_device_enabled(input)) 2209 2240 xpad_stop_input(xpad); 2210 - mutex_unlock(&input->mutex); 2211 2241 } 2212 2242 2213 2243 xpad_stop_output(xpad); ··· 2219 2249 { 2220 2250 struct usb_xpad *xpad = usb_get_intfdata(intf); 2221 2251 struct input_dev *input = xpad->dev; 2222 - int retval = 0; 2223 2252 2224 - if (xpad->xtype == XTYPE_XBOX360W) { 2225 - retval = xpad360w_start_input(xpad); 2226 - } else { 2227 - mutex_lock(&input->mutex); 2228 - if (input_device_enabled(input)) { 2229 - retval = xpad_start_input(xpad); 2230 - } else if (xpad->xtype == XTYPE_XBOXONE) { 2231 - /* 2232 - * Even if there are no users, we'll send Xbox One pads 2233 - * the startup sequence so they don't sit there and 2234 - * blink until somebody opens the input device again. 2235 - */ 2236 - retval = xpad_start_xbox_one(xpad); 2237 - } 2238 - mutex_unlock(&input->mutex); 2253 + if (xpad->xtype == XTYPE_XBOX360W) 2254 + return xpad360w_start_input(xpad); 2255 + 2256 + guard(mutex)(&input->mutex); 2257 + 2258 + if (input_device_enabled(input)) 2259 + return xpad_start_input(xpad); 2260 + 2261 + if (xpad->xtype == XTYPE_XBOXONE) { 2262 + /* 2263 + * Even if there are no users, we'll send Xbox One pads 2264 + * the startup sequence so they don't sit there and 2265 + * blink until somebody opens the input device again. 2266 + */ 2267 + return xpad_start_xbox_one(xpad); 2239 2268 } 2240 2269 2241 - return retval; 2270 + return 0; 2242 2271 } 2243 2272 2244 2273 static struct usb_driver xpad_driver = {
+1 -1
drivers/input/keyboard/adp5520-keys.c
··· 181 181 .name = "adp5520-keys", 182 182 }, 183 183 .probe = adp5520_keys_probe, 184 - .remove_new = adp5520_keys_remove, 184 + .remove = adp5520_keys_remove, 185 185 }; 186 186 module_platform_driver(adp5520_keys_driver); 187 187
+18 -21
drivers/input/keyboard/adp5589-keys.c
··· 411 411 unsigned int bank = kpad->var->bank(kpad->gpiomap[off]); 412 412 unsigned int bit = kpad->var->bit(kpad->gpiomap[off]); 413 413 414 - mutex_lock(&kpad->gpio_lock); 414 + guard(mutex)(&kpad->gpio_lock); 415 415 416 416 if (val) 417 417 kpad->dat_out[bank] |= bit; ··· 420 420 421 421 adp5589_write(kpad->client, kpad->var->reg(ADP5589_GPO_DATA_OUT_A) + 422 422 bank, kpad->dat_out[bank]); 423 - 424 - mutex_unlock(&kpad->gpio_lock); 425 423 } 426 424 427 425 static int adp5589_gpio_direction_input(struct gpio_chip *chip, unsigned off) ··· 427 429 struct adp5589_kpad *kpad = gpiochip_get_data(chip); 428 430 unsigned int bank = kpad->var->bank(kpad->gpiomap[off]); 429 431 unsigned int bit = kpad->var->bit(kpad->gpiomap[off]); 430 - int ret; 431 432 432 - mutex_lock(&kpad->gpio_lock); 433 + guard(mutex)(&kpad->gpio_lock); 433 434 434 435 kpad->dir[bank] &= ~bit; 435 - ret = adp5589_write(kpad->client, 436 - kpad->var->reg(ADP5589_GPIO_DIRECTION_A) + bank, 437 - kpad->dir[bank]); 438 - 439 - mutex_unlock(&kpad->gpio_lock); 440 - 441 - return ret; 436 + return adp5589_write(kpad->client, 437 + kpad->var->reg(ADP5589_GPIO_DIRECTION_A) + bank, 438 + kpad->dir[bank]); 442 439 } 443 440 444 441 static int adp5589_gpio_direction_output(struct gpio_chip *chip, ··· 442 449 struct adp5589_kpad *kpad = gpiochip_get_data(chip); 443 450 unsigned int bank = kpad->var->bank(kpad->gpiomap[off]); 444 451 unsigned int bit = kpad->var->bit(kpad->gpiomap[off]); 445 - int ret; 452 + int error; 446 453 447 - mutex_lock(&kpad->gpio_lock); 454 + guard(mutex)(&kpad->gpio_lock); 448 455 449 456 kpad->dir[bank] |= bit; 450 457 ··· 453 460 else 454 461 kpad->dat_out[bank] &= ~bit; 455 462 456 - ret = adp5589_write(kpad->client, kpad->var->reg(ADP5589_GPO_DATA_OUT_A) 457 - + bank, kpad->dat_out[bank]); 458 - ret |= adp5589_write(kpad->client, 459 - kpad->var->reg(ADP5589_GPIO_DIRECTION_A) + bank, 460 - kpad->dir[bank]); 463 + error = adp5589_write(kpad->client, 464 + kpad->var->reg(ADP5589_GPO_DATA_OUT_A) + bank, 465 + kpad->dat_out[bank]); 466 + if (error) 467 + return error; 461 468 462 - mutex_unlock(&kpad->gpio_lock); 469 + error = adp5589_write(kpad->client, 470 + kpad->var->reg(ADP5589_GPIO_DIRECTION_A) + bank, 471 + kpad->dir[bank]); 472 + if (error) 473 + return error; 463 474 464 - return ret; 475 + return 0; 465 476 } 466 477 467 478 static int adp5589_build_gpiomap(struct adp5589_kpad *kpad,
+18 -54
drivers/input/keyboard/applespi.c
··· 717 717 static void applespi_msg_complete(struct applespi_data *applespi, 718 718 bool is_write_msg, bool is_read_compl) 719 719 { 720 - unsigned long flags; 721 - 722 - spin_lock_irqsave(&applespi->cmd_msg_lock, flags); 720 + guard(spinlock_irqsave)(&applespi->cmd_msg_lock); 723 721 724 722 if (is_read_compl) 725 723 applespi->read_active = false; ··· 731 733 applespi->cmd_msg_queued = 0; 732 734 applespi_send_cmd_msg(applespi); 733 735 } 734 - 735 - spin_unlock_irqrestore(&applespi->cmd_msg_lock, flags); 736 736 } 737 737 738 738 static void applespi_async_write_complete(void *context) ··· 884 888 885 889 static void applespi_init(struct applespi_data *applespi, bool is_resume) 886 890 { 887 - unsigned long flags; 888 - 889 - spin_lock_irqsave(&applespi->cmd_msg_lock, flags); 891 + guard(spinlock_irqsave)(&applespi->cmd_msg_lock); 890 892 891 893 if (is_resume) 892 894 applespi->want_mt_init_cmd = true; 893 895 else 894 896 applespi->want_tp_info_cmd = true; 895 897 applespi_send_cmd_msg(applespi); 896 - 897 - spin_unlock_irqrestore(&applespi->cmd_msg_lock, flags); 898 898 } 899 899 900 900 static int applespi_set_capsl_led(struct applespi_data *applespi, 901 901 bool capslock_on) 902 902 { 903 - unsigned long flags; 904 - int sts; 905 - 906 - spin_lock_irqsave(&applespi->cmd_msg_lock, flags); 903 + guard(spinlock_irqsave)(&applespi->cmd_msg_lock); 907 904 908 905 applespi->want_cl_led_on = capslock_on; 909 - sts = applespi_send_cmd_msg(applespi); 910 - 911 - spin_unlock_irqrestore(&applespi->cmd_msg_lock, flags); 912 - 913 - return sts; 906 + return applespi_send_cmd_msg(applespi); 914 907 } 915 908 916 909 static void applespi_set_bl_level(struct led_classdev *led_cdev, ··· 907 922 { 908 923 struct applespi_data *applespi = 909 924 container_of(led_cdev, struct applespi_data, backlight_info); 910 - unsigned long flags; 911 925 912 - spin_lock_irqsave(&applespi->cmd_msg_lock, flags); 926 + guard(spinlock_irqsave)(&applespi->cmd_msg_lock); 913 927 914 928 if (value == 0) { 915 929 applespi->want_bl_level = value; ··· 924 940 } 925 941 926 942 applespi_send_cmd_msg(applespi); 927 - 928 - spin_unlock_irqrestore(&applespi->cmd_msg_lock, flags); 929 943 } 930 944 931 945 static int applespi_event(struct input_dev *dev, unsigned int type, ··· 1409 1427 /* process packet header */ 1410 1428 if (!applespi_verify_crc(applespi, applespi->rx_buffer, 1411 1429 APPLESPI_PACKET_SIZE)) { 1412 - unsigned long flags; 1413 - 1414 - spin_lock_irqsave(&applespi->cmd_msg_lock, flags); 1430 + guard(spinlock_irqsave)(&applespi->cmd_msg_lock); 1415 1431 1416 1432 if (applespi->drain) { 1417 1433 applespi->read_active = false; ··· 1417 1437 1418 1438 wake_up_all(&applespi->drain_complete); 1419 1439 } 1420 - 1421 - spin_unlock_irqrestore(&applespi->cmd_msg_lock, flags); 1422 1440 1423 1441 return; 1424 1442 } ··· 1550 1572 { 1551 1573 struct applespi_data *applespi = context; 1552 1574 int sts; 1553 - unsigned long flags; 1554 1575 1555 1576 trace_applespi_irq_received(ET_RD_IRQ, PT_READ); 1556 1577 1557 - spin_lock_irqsave(&applespi->cmd_msg_lock, flags); 1578 + guard(spinlock_irqsave)(&applespi->cmd_msg_lock); 1558 1579 1559 1580 if (!applespi->suspended) { 1560 1581 sts = applespi_async(applespi, &applespi->rd_m, ··· 1565 1588 else 1566 1589 applespi->read_active = true; 1567 1590 } 1568 - 1569 - spin_unlock_irqrestore(&applespi->cmd_msg_lock, flags); 1570 1591 1571 1592 return ACPI_INTERRUPT_HANDLED; 1572 1593 } ··· 1793 1818 1794 1819 static void applespi_drain_writes(struct applespi_data *applespi) 1795 1820 { 1796 - unsigned long flags; 1797 - 1798 - spin_lock_irqsave(&applespi->cmd_msg_lock, flags); 1821 + guard(spinlock_irqsave)(&applespi->cmd_msg_lock); 1799 1822 1800 1823 applespi->drain = true; 1801 1824 wait_event_lock_irq(applespi->drain_complete, !applespi->write_active, 1802 1825 applespi->cmd_msg_lock); 1803 - 1804 - spin_unlock_irqrestore(&applespi->cmd_msg_lock, flags); 1805 1826 } 1806 1827 1807 1828 static void applespi_drain_reads(struct applespi_data *applespi) 1808 1829 { 1809 - unsigned long flags; 1810 - 1811 - spin_lock_irqsave(&applespi->cmd_msg_lock, flags); 1830 + guard(spinlock_irqsave)(&applespi->cmd_msg_lock); 1812 1831 1813 1832 wait_event_lock_irq(applespi->drain_complete, !applespi->read_active, 1814 1833 applespi->cmd_msg_lock); 1815 1834 1816 1835 applespi->suspended = true; 1817 - 1818 - spin_unlock_irqrestore(&applespi->cmd_msg_lock, flags); 1819 1836 } 1820 1837 1821 1838 static void applespi_remove(struct spi_device *spi) ··· 1874 1907 struct spi_device *spi = to_spi_device(dev); 1875 1908 struct applespi_data *applespi = spi_get_drvdata(spi); 1876 1909 acpi_status acpi_sts; 1877 - unsigned long flags; 1878 1910 1879 1911 /* ensure our flags and state reflect a newly resumed device */ 1880 - spin_lock_irqsave(&applespi->cmd_msg_lock, flags); 1912 + scoped_guard(spinlock_irqsave, &applespi->cmd_msg_lock) { 1913 + applespi->drain = false; 1914 + applespi->have_cl_led_on = false; 1915 + applespi->have_bl_level = 0; 1916 + applespi->cmd_msg_queued = 0; 1917 + applespi->read_active = false; 1918 + applespi->write_active = false; 1881 1919 1882 - applespi->drain = false; 1883 - applespi->have_cl_led_on = false; 1884 - applespi->have_bl_level = 0; 1885 - applespi->cmd_msg_queued = 0; 1886 - applespi->read_active = false; 1887 - applespi->write_active = false; 1888 - 1889 - applespi->suspended = false; 1890 - 1891 - spin_unlock_irqrestore(&applespi->cmd_msg_lock, flags); 1920 + applespi->suspended = false; 1921 + } 1892 1922 1893 1923 /* switch on the SPI interface */ 1894 1924 applespi_enable_spi(applespi);
+4 -4
drivers/input/keyboard/atkbd.c
··· 713 713 714 714 static inline void atkbd_enable(struct atkbd *atkbd) 715 715 { 716 - serio_pause_rx(atkbd->ps2dev.serio); 716 + guard(serio_pause_rx)(atkbd->ps2dev.serio); 717 + 717 718 atkbd->enabled = true; 718 - serio_continue_rx(atkbd->ps2dev.serio); 719 719 } 720 720 721 721 /* ··· 725 725 726 726 static inline void atkbd_disable(struct atkbd *atkbd) 727 727 { 728 - serio_pause_rx(atkbd->ps2dev.serio); 728 + guard(serio_pause_rx)(atkbd->ps2dev.serio); 729 + 729 730 atkbd->enabled = false; 730 - serio_continue_rx(atkbd->ps2dev.serio); 731 731 } 732 732 733 733 static int atkbd_activate(struct atkbd *atkbd)
+4 -8
drivers/input/keyboard/cap11xx.c
··· 416 416 static int cap11xx_init_leds(struct device *dev, 417 417 struct cap11xx_priv *priv, int num_leds) 418 418 { 419 - struct device_node *node = dev->of_node, *child; 419 + struct device_node *node = dev->of_node; 420 420 struct cap11xx_led *led; 421 421 int cnt = of_get_child_count(node); 422 422 int error; ··· 445 445 if (error) 446 446 return error; 447 447 448 - for_each_child_of_node(node, child) { 448 + for_each_child_of_node_scoped(node, child) { 449 449 u32 reg; 450 450 451 451 led->cdev.name = ··· 458 458 led->cdev.brightness = LED_OFF; 459 459 460 460 error = of_property_read_u32(child, "reg", &reg); 461 - if (error != 0 || reg >= num_leds) { 462 - of_node_put(child); 461 + if (error != 0 || reg >= num_leds) 463 462 return -EINVAL; 464 - } 465 463 466 464 led->reg = reg; 467 465 led->priv = priv; 468 466 469 467 error = devm_led_classdev_register(dev, &led->cdev); 470 - if (error) { 471 - of_node_put(child); 468 + if (error) 472 469 return error; 473 - } 474 470 475 471 priv->num_leds++; 476 472 led++;
+1 -1
drivers/input/keyboard/cros_ec_keyb.c
··· 770 770 771 771 static struct platform_driver cros_ec_keyb_driver = { 772 772 .probe = cros_ec_keyb_probe, 773 - .remove_new = cros_ec_keyb_remove, 773 + .remove = cros_ec_keyb_remove, 774 774 .driver = { 775 775 .name = "cros-ec-keyb", 776 776 .dev_groups = cros_ec_keyb_groups,
+1 -1
drivers/input/keyboard/cypress-sf.c
··· 208 208 static DEFINE_SIMPLE_DEV_PM_OPS(cypress_sf_pm_ops, 209 209 cypress_sf_suspend, cypress_sf_resume); 210 210 211 - static struct i2c_device_id cypress_sf_id_table[] = { 211 + static const struct i2c_device_id cypress_sf_id_table[] = { 212 212 { CYPRESS_SF_DEV_NAME }, 213 213 { } 214 214 };
+3 -7
drivers/input/keyboard/ep93xx_keypad.c
··· 168 168 struct ep93xx_keypad *keypad = platform_get_drvdata(pdev); 169 169 struct input_dev *input_dev = keypad->input_dev; 170 170 171 - mutex_lock(&input_dev->mutex); 171 + guard(mutex)(&input_dev->mutex); 172 172 173 173 if (keypad->enabled) { 174 174 clk_disable(keypad->clk); 175 175 keypad->enabled = false; 176 176 } 177 - 178 - mutex_unlock(&input_dev->mutex); 179 177 180 178 return 0; 181 179 } ··· 184 186 struct ep93xx_keypad *keypad = platform_get_drvdata(pdev); 185 187 struct input_dev *input_dev = keypad->input_dev; 186 188 187 - mutex_lock(&input_dev->mutex); 189 + guard(mutex)(&input_dev->mutex); 188 190 189 191 if (input_device_enabled(input_dev)) { 190 192 if (!keypad->enabled) { ··· 193 195 keypad->enabled = true; 194 196 } 195 197 } 196 - 197 - mutex_unlock(&input_dev->mutex); 198 198 199 199 return 0; 200 200 } ··· 285 289 .of_match_table = ep93xx_keypad_of_ids, 286 290 }, 287 291 .probe = ep93xx_keypad_probe, 288 - .remove_new = ep93xx_keypad_remove, 292 + .remove = ep93xx_keypad_remove, 289 293 }; 290 294 module_platform_driver(ep93xx_keypad_driver); 291 295
+1 -3
drivers/input/keyboard/hilkbd.c
··· 180 180 /* send a command to the HIL */ 181 181 static void hil_do(unsigned char cmd, unsigned char *data, unsigned int len) 182 182 { 183 - unsigned long flags; 183 + guard(spinlock_irqsave)(&hil_dev.lock); 184 184 185 - spin_lock_irqsave(&hil_dev.lock, flags); 186 185 while (hil_busy()) 187 186 /* wait */; 188 187 hil_command(cmd); ··· 190 191 /* wait */; 191 192 hil_write_data(*(data++)); 192 193 } 193 - spin_unlock_irqrestore(&hil_dev.lock, flags); 194 194 } 195 195 196 196
+11 -16
drivers/input/keyboard/imx_keypad.c
··· 521 521 struct input_dev *input_dev = kbd->input_dev; 522 522 unsigned short reg_val = readw(kbd->mmio_base + KPSR); 523 523 524 - /* imx kbd can wake up system even clock is disabled */ 525 - mutex_lock(&input_dev->mutex); 526 - 527 - if (input_device_enabled(input_dev)) 528 - clk_disable_unprepare(kbd->clk); 529 - 530 - mutex_unlock(&input_dev->mutex); 524 + scoped_guard(mutex, &input_dev->mutex) { 525 + /* imx kbd can wake up system even clock is disabled */ 526 + if (input_device_enabled(input_dev)) 527 + clk_disable_unprepare(kbd->clk); 528 + } 531 529 532 530 if (device_may_wakeup(&pdev->dev)) { 533 531 if (reg_val & KBD_STAT_KPKD) ··· 545 547 struct platform_device *pdev = to_platform_device(dev); 546 548 struct imx_keypad *kbd = platform_get_drvdata(pdev); 547 549 struct input_dev *input_dev = kbd->input_dev; 548 - int ret = 0; 550 + int error; 549 551 550 552 if (device_may_wakeup(&pdev->dev)) 551 553 disable_irq_wake(kbd->irq); 552 554 553 - mutex_lock(&input_dev->mutex); 555 + guard(mutex)(&input_dev->mutex); 554 556 555 557 if (input_device_enabled(input_dev)) { 556 - ret = clk_prepare_enable(kbd->clk); 557 - if (ret) 558 - goto err_clk; 558 + error = clk_prepare_enable(kbd->clk); 559 + if (error) 560 + return error; 559 561 } 560 562 561 - err_clk: 562 - mutex_unlock(&input_dev->mutex); 563 - 564 - return ret; 563 + return 0; 565 564 } 566 565 567 566 static const struct dev_pm_ops imx_kbd_pm_ops = {
+5 -7
drivers/input/keyboard/ipaq-micro-keys.c
··· 54 54 55 55 static void micro_key_start(struct ipaq_micro_keys *keys) 56 56 { 57 - spin_lock(&keys->micro->lock); 57 + guard(spinlock)(&keys->micro->lock); 58 + 58 59 keys->micro->key = micro_key_receive; 59 60 keys->micro->key_data = keys; 60 - spin_unlock(&keys->micro->lock); 61 61 } 62 62 63 63 static void micro_key_stop(struct ipaq_micro_keys *keys) 64 64 { 65 - spin_lock(&keys->micro->lock); 65 + guard(spinlock)(&keys->micro->lock); 66 + 66 67 keys->micro->key = NULL; 67 68 keys->micro->key_data = NULL; 68 - spin_unlock(&keys->micro->lock); 69 69 } 70 70 71 71 static int micro_key_open(struct input_dev *input) ··· 141 141 struct ipaq_micro_keys *keys = dev_get_drvdata(dev); 142 142 struct input_dev *input = keys->input; 143 143 144 - mutex_lock(&input->mutex); 144 + guard(mutex)(&input->mutex); 145 145 146 146 if (input_device_enabled(input)) 147 147 micro_key_start(keys); 148 - 149 - mutex_unlock(&input->mutex); 150 148 151 149 return 0; 152 150 }
+1 -1
drivers/input/keyboard/iqs62x-keys.c
··· 323 323 .name = "iqs62x-keys", 324 324 }, 325 325 .probe = iqs62x_keys_probe, 326 - .remove_new = iqs62x_keys_remove, 326 + .remove = iqs62x_keys_remove, 327 327 }; 328 328 module_platform_driver(iqs62x_keys_platform_driver); 329 329
+22 -27
drivers/input/keyboard/lm8323.c
··· 350 350 351 351 static void pwm_done(struct lm8323_pwm *pwm) 352 352 { 353 - mutex_lock(&pwm->lock); 353 + guard(mutex)(&pwm->lock); 354 + 354 355 pwm->running = false; 355 356 if (pwm->desired_brightness != pwm->brightness) 356 357 schedule_work(&pwm->work); 357 - mutex_unlock(&pwm->lock); 358 358 } 359 359 360 360 /* ··· 367 367 u8 ints; 368 368 int i; 369 369 370 - mutex_lock(&lm->lock); 370 + guard(mutex)(&lm->lock); 371 371 372 372 while ((lm8323_read(lm, LM8323_CMD_READ_INT, &ints, 1) == 1) && ints) { 373 373 if (likely(ints & INT_KEYPAD)) ··· 393 393 } 394 394 } 395 395 } 396 - 397 - mutex_unlock(&lm->lock); 398 396 399 397 return IRQ_HANDLED; 400 398 } ··· 443 445 u16 pwm_cmds[3]; 444 446 int num_cmds = 0; 445 447 446 - mutex_lock(&pwm->lock); 448 + guard(mutex)(&pwm->lock); 447 449 448 450 /* 449 451 * Do nothing if we're already at the requested level, ··· 452 454 * finishes. 453 455 */ 454 456 if (pwm->running || pwm->desired_brightness == pwm->brightness) 455 - goto out; 457 + return; 456 458 457 459 kill = (pwm->desired_brightness == 0); 458 460 up = (pwm->desired_brightness > pwm->brightness); ··· 487 489 488 490 lm8323_write_pwm(pwm, kill, num_cmds, pwm_cmds); 489 491 pwm->brightness = pwm->desired_brightness; 490 - 491 - out: 492 - mutex_unlock(&pwm->lock); 493 492 } 494 493 495 494 static void lm8323_pwm_set_brightness(struct led_classdev *led_cdev, ··· 495 500 struct lm8323_pwm *pwm = cdev_to_pwm(led_cdev); 496 501 struct lm8323_chip *lm = pwm->chip; 497 502 498 - mutex_lock(&pwm->lock); 499 - pwm->desired_brightness = brightness; 500 - mutex_unlock(&pwm->lock); 503 + scoped_guard(mutex, &pwm->lock) { 504 + pwm->desired_brightness = brightness; 505 + } 501 506 502 507 if (in_interrupt()) { 503 508 schedule_work(&pwm->work); ··· 505 510 /* 506 511 * Schedule PWM work as usual unless we are going into suspend 507 512 */ 508 - mutex_lock(&lm->lock); 509 - if (likely(!lm->pm_suspend)) 510 - schedule_work(&pwm->work); 511 - else 512 - lm8323_pwm_work(&pwm->work); 513 - mutex_unlock(&lm->lock); 513 + scoped_guard(mutex, &lm->lock) { 514 + if (likely(!lm->pm_suspend)) 515 + schedule_work(&pwm->work); 516 + else 517 + lm8323_pwm_work(&pwm->work); 518 + } 514 519 } 515 520 } 516 521 ··· 603 608 if (ret) 604 609 return ret; 605 610 606 - mutex_lock(&lm->lock); 611 + guard(mutex)(&lm->lock); 612 + 607 613 lm->kp_enabled = !i; 608 - mutex_unlock(&lm->lock); 609 614 610 615 return count; 611 616 } ··· 753 758 irq_set_irq_wake(client->irq, 0); 754 759 disable_irq(client->irq); 755 760 756 - mutex_lock(&lm->lock); 757 - lm->pm_suspend = true; 758 - mutex_unlock(&lm->lock); 761 + scoped_guard(mutex, &lm->lock) { 762 + lm->pm_suspend = true; 763 + } 759 764 760 765 for (i = 0; i < 3; i++) 761 766 if (lm->pwm[i].enabled) ··· 770 775 struct lm8323_chip *lm = i2c_get_clientdata(client); 771 776 int i; 772 777 773 - mutex_lock(&lm->lock); 774 - lm->pm_suspend = false; 775 - mutex_unlock(&lm->lock); 778 + scoped_guard(mutex, &lm->lock) { 779 + lm->pm_suspend = false; 780 + } 776 781 777 782 for (i = 0; i < 3; i++) 778 783 if (lm->pwm[i].enabled)
+1 -4
drivers/input/keyboard/locomokbd.c
··· 112 112 static void locomokbd_scankeyboard(struct locomokbd *locomokbd) 113 113 { 114 114 unsigned int row, col, rowd; 115 - unsigned long flags; 116 115 unsigned int num_pressed; 117 116 unsigned long membase = locomokbd->base; 118 117 119 - spin_lock_irqsave(&locomokbd->lock, flags); 118 + guard(spinlock_irqsave)(&locomokbd->lock); 120 119 121 120 locomokbd_charge_all(membase); 122 121 ··· 166 167 mod_timer(&locomokbd->timer, jiffies + SCAN_INTERVAL); 167 168 else 168 169 locomokbd->count_cancel = 0; 169 - 170 - spin_unlock_irqrestore(&locomokbd->lock, flags); 171 170 } 172 171 173 172 /*
+9 -9
drivers/input/keyboard/lpc32xx-keys.c
··· 262 262 struct lpc32xx_kscan_drv *kscandat = platform_get_drvdata(pdev); 263 263 struct input_dev *input = kscandat->input; 264 264 265 - mutex_lock(&input->mutex); 265 + guard(mutex)(&input->mutex); 266 266 267 267 if (input_device_enabled(input)) { 268 268 /* Clear IRQ and disable clock */ ··· 270 270 clk_disable_unprepare(kscandat->clk); 271 271 } 272 272 273 - mutex_unlock(&input->mutex); 274 273 return 0; 275 274 } 276 275 ··· 278 279 struct platform_device *pdev = to_platform_device(dev); 279 280 struct lpc32xx_kscan_drv *kscandat = platform_get_drvdata(pdev); 280 281 struct input_dev *input = kscandat->input; 281 - int retval = 0; 282 + int error; 282 283 283 - mutex_lock(&input->mutex); 284 + guard(mutex)(&input->mutex); 284 285 285 286 if (input_device_enabled(input)) { 286 287 /* Enable clock and clear IRQ */ 287 - retval = clk_prepare_enable(kscandat->clk); 288 - if (retval == 0) 289 - writel(1, LPC32XX_KS_IRQ(kscandat->kscan_base)); 288 + error = clk_prepare_enable(kscandat->clk); 289 + if (error) 290 + return error; 291 + 292 + writel(1, LPC32XX_KS_IRQ(kscandat->kscan_base)); 290 293 } 291 294 292 - mutex_unlock(&input->mutex); 293 - return retval; 295 + return 0; 294 296 } 295 297 296 298 static DEFINE_SIMPLE_DEV_PM_OPS(lpc32xx_kscan_pm_ops, lpc32xx_kscan_suspend,
+2 -7
drivers/input/keyboard/maple_keyb.c
··· 132 132 * We should always get the lock because the only 133 133 * time it may be locked is if the driver is in the cleanup phase. 134 134 */ 135 - if (likely(mutex_trylock(&maple_keyb_mutex))) { 136 - 135 + scoped_guard(mutex_try, &maple_keyb_mutex) { 137 136 if (buf[1] == mapledev->function) { 138 137 memcpy(kbd->new, buf + 2, 8); 139 138 dc_scan_kbd(kbd); 140 139 } 141 - 142 - mutex_unlock(&maple_keyb_mutex); 143 140 } 144 141 } 145 142 ··· 208 211 struct maple_device *mdev = to_maple_dev(dev); 209 212 struct dc_kbd *kbd = maple_get_drvdata(mdev); 210 213 211 - mutex_lock(&maple_keyb_mutex); 214 + guard(mutex)(&maple_keyb_mutex); 212 215 213 216 input_unregister_device(kbd->dev); 214 217 kfree(kbd); 215 218 216 219 maple_set_drvdata(mdev, NULL); 217 - 218 - mutex_unlock(&maple_keyb_mutex); 219 220 return 0; 220 221 } 221 222
+8 -11
drivers/input/keyboard/matrix_keypad.c
··· 17 17 #include <linux/jiffies.h> 18 18 #include <linux/module.h> 19 19 #include <linux/gpio.h> 20 - #include <linux/gpio/consumer.h> 21 20 #include <linux/input/matrix_keypad.h> 22 21 #include <linux/slab.h> 23 22 #include <linux/of.h> ··· 157 158 activate_all_cols(keypad, true); 158 159 159 160 /* Enable IRQs again */ 160 - spin_lock_irq(&keypad->lock); 161 - keypad->scan_pending = false; 162 - enable_row_irqs(keypad); 163 - spin_unlock_irq(&keypad->lock); 161 + scoped_guard(spinlock_irq, &keypad->lock) { 162 + keypad->scan_pending = false; 163 + enable_row_irqs(keypad); 164 + } 164 165 } 165 166 166 167 static irqreturn_t matrix_keypad_interrupt(int irq, void *id) 167 168 { 168 169 struct matrix_keypad *keypad = id; 169 - unsigned long flags; 170 170 171 - spin_lock_irqsave(&keypad->lock, flags); 171 + guard(spinlock_irqsave)(&keypad->lock); 172 172 173 173 /* 174 174 * See if another IRQ beaten us to it and scheduled the ··· 183 185 msecs_to_jiffies(keypad->debounce_ms)); 184 186 185 187 out: 186 - spin_unlock_irqrestore(&keypad->lock, flags); 187 188 return IRQ_HANDLED; 188 189 } 189 190 ··· 206 209 { 207 210 struct matrix_keypad *keypad = input_get_drvdata(dev); 208 211 209 - spin_lock_irq(&keypad->lock); 210 - keypad->stopped = true; 211 - spin_unlock_irq(&keypad->lock); 212 + scoped_guard(spinlock_irq, &keypad->lock) { 213 + keypad->stopped = true; 214 + } 212 215 213 216 flush_delayed_work(&keypad->work); 214 217 /*
+3 -42
drivers/input/keyboard/mpr121_touchkey.c
··· 82 82 { AUTO_CONFIG_CTRL_ADDR, 0x0b }, 83 83 }; 84 84 85 - static void mpr121_vdd_supply_disable(void *data) 86 - { 87 - struct regulator *vdd_supply = data; 88 - 89 - regulator_disable(vdd_supply); 90 - } 91 - 92 - static struct regulator *mpr121_vdd_supply_init(struct device *dev) 93 - { 94 - struct regulator *vdd_supply; 95 - int err; 96 - 97 - vdd_supply = devm_regulator_get(dev, "vdd"); 98 - if (IS_ERR(vdd_supply)) { 99 - dev_err(dev, "failed to get vdd regulator: %ld\n", 100 - PTR_ERR(vdd_supply)); 101 - return vdd_supply; 102 - } 103 - 104 - err = regulator_enable(vdd_supply); 105 - if (err) { 106 - dev_err(dev, "failed to enable vdd regulator: %d\n", err); 107 - return ERR_PTR(err); 108 - } 109 - 110 - err = devm_add_action_or_reset(dev, mpr121_vdd_supply_disable, 111 - vdd_supply); 112 - if (err) { 113 - dev_err(dev, "failed to add disable regulator action: %d\n", 114 - err); 115 - return ERR_PTR(err); 116 - } 117 - 118 - return vdd_supply; 119 - } 120 - 121 85 static void mpr_touchkey_report(struct input_dev *dev) 122 86 { 123 87 struct mpr121_touchkey *mpr121 = input_get_drvdata(dev); ··· 197 233 static int mpr_touchkey_probe(struct i2c_client *client) 198 234 { 199 235 struct device *dev = &client->dev; 200 - struct regulator *vdd_supply; 201 236 int vdd_uv; 202 237 struct mpr121_touchkey *mpr121; 203 238 struct input_dev *input_dev; ··· 204 241 int error; 205 242 int i; 206 243 207 - vdd_supply = mpr121_vdd_supply_init(dev); 208 - if (IS_ERR(vdd_supply)) 209 - return PTR_ERR(vdd_supply); 210 - 211 - vdd_uv = regulator_get_voltage(vdd_supply); 244 + vdd_uv = devm_regulator_get_enable_read_voltage(dev, "vdd"); 245 + if (vdd_uv < 0) 246 + return dev_err_probe(dev, vdd_uv, "failed to get vdd voltage\n"); 212 247 213 248 mpr121 = devm_kzalloc(dev, sizeof(*mpr121), GFP_KERNEL); 214 249 if (!mpr121)
+5 -12
drivers/input/keyboard/mtk-pmic-keys.c
··· 307 307 int error, index = 0; 308 308 unsigned int keycount; 309 309 struct mt6397_chip *pmic_chip = dev_get_drvdata(pdev->dev.parent); 310 - struct device_node *node = pdev->dev.of_node, *child; 310 + struct device_node *node = pdev->dev.of_node; 311 311 static const char *const irqnames[] = { "powerkey", "homekey" }; 312 312 static const char *const irqnames_r[] = { "powerkey_r", "homekey_r" }; 313 313 struct mtk_pmic_keys *keys; ··· 343 343 return -EINVAL; 344 344 } 345 345 346 - for_each_child_of_node(node, child) { 346 + for_each_child_of_node_scoped(node, child) { 347 347 keys->keys[index].regs = &mtk_pmic_regs->keys_regs[index]; 348 348 349 349 keys->keys[index].irq = 350 350 platform_get_irq_byname(pdev, irqnames[index]); 351 - if (keys->keys[index].irq < 0) { 352 - of_node_put(child); 351 + if (keys->keys[index].irq < 0) 353 352 return keys->keys[index].irq; 354 - } 355 353 356 354 if (of_device_is_compatible(node, "mediatek,mt6358-keys")) { 357 355 keys->keys[index].irq_r = platform_get_irq_byname(pdev, 358 356 irqnames_r[index]); 359 357 360 - if (keys->keys[index].irq_r < 0) { 361 - of_node_put(child); 358 + if (keys->keys[index].irq_r < 0) 362 359 return keys->keys[index].irq_r; 363 - } 364 360 } 365 361 366 362 error = of_property_read_u32(child, ··· 365 369 dev_err(keys->dev, 366 370 "failed to read key:%d linux,keycode property: %d\n", 367 371 index, error); 368 - of_node_put(child); 369 372 return error; 370 373 } 371 374 ··· 372 377 keys->keys[index].wakeup = true; 373 378 374 379 error = mtk_pmic_key_setup(keys, &keys->keys[index]); 375 - if (error) { 376 - of_node_put(child); 380 + if (error) 377 381 return error; 378 - } 379 382 380 383 index++; 381 384 }
+9 -9
drivers/input/keyboard/omap-keypad.c
··· 156 156 if ((state != 1) && (state != 0)) 157 157 return -EINVAL; 158 158 159 - mutex_lock(&kp_enable_mutex); 160 - if (state != kp_enable) { 161 - if (state) 162 - enable_irq(omap_kp->irq); 163 - else 164 - disable_irq(omap_kp->irq); 165 - kp_enable = state; 159 + scoped_guard(mutex, &kp_enable_mutex) { 160 + if (state != kp_enable) { 161 + if (state) 162 + enable_irq(omap_kp->irq); 163 + else 164 + disable_irq(omap_kp->irq); 165 + kp_enable = state; 166 + } 166 167 } 167 - mutex_unlock(&kp_enable_mutex); 168 168 169 169 return strnlen(buf, count); 170 170 } ··· 290 290 291 291 static struct platform_driver omap_kp_driver = { 292 292 .probe = omap_kp_probe, 293 - .remove_new = omap_kp_remove, 293 + .remove = omap_kp_remove, 294 294 .driver = { 295 295 .name = "omap-keypad", 296 296 .dev_groups = omap_kp_groups,
+2 -4
drivers/input/keyboard/omap4-keypad.c
··· 144 144 { 145 145 u64 changed; 146 146 147 - mutex_lock(&keypad_data->lock); 147 + guard(mutex)(&keypad_data->lock); 148 148 149 149 changed = keys ^ keypad_data->keys; 150 150 ··· 158 158 omap4_keypad_report_keys(keypad_data, changed & keys, true); 159 159 160 160 keypad_data->keys = keys; 161 - 162 - mutex_unlock(&keypad_data->lock); 163 161 } 164 162 165 163 /* Interrupt handlers */ ··· 485 487 486 488 static struct platform_driver omap4_keypad_driver = { 487 489 .probe = omap4_keypad_probe, 488 - .remove_new = omap4_keypad_remove, 490 + .remove = omap4_keypad_remove, 489 491 .driver = { 490 492 .name = "omap4-keypad", 491 493 .of_match_table = omap_keypad_dt_match,
+2 -6
drivers/input/keyboard/pmic8xxx-keypad.c
··· 630 630 if (device_may_wakeup(dev)) { 631 631 enable_irq_wake(kp->key_sense_irq); 632 632 } else { 633 - mutex_lock(&input_dev->mutex); 633 + guard(mutex)(&input_dev->mutex); 634 634 635 635 if (input_device_enabled(input_dev)) 636 636 pmic8xxx_kp_disable(kp); 637 - 638 - mutex_unlock(&input_dev->mutex); 639 637 } 640 638 641 639 return 0; ··· 648 650 if (device_may_wakeup(dev)) { 649 651 disable_irq_wake(kp->key_sense_irq); 650 652 } else { 651 - mutex_lock(&input_dev->mutex); 653 + guard(mutex)(&input_dev->mutex); 652 654 653 655 if (input_device_enabled(input_dev)) 654 656 pmic8xxx_kp_enable(kp); 655 - 656 - mutex_unlock(&input_dev->mutex); 657 657 } 658 658 659 659 return 0;
+8 -8
drivers/input/keyboard/pxa27x_keypad.c
··· 682 682 struct platform_device *pdev = to_platform_device(dev); 683 683 struct pxa27x_keypad *keypad = platform_get_drvdata(pdev); 684 684 struct input_dev *input_dev = keypad->input_dev; 685 - int ret = 0; 685 + int error; 686 686 687 687 /* 688 688 * If the keypad is used as wake up source, the clock is not turned ··· 691 691 if (device_may_wakeup(&pdev->dev)) { 692 692 disable_irq_wake(keypad->irq); 693 693 } else { 694 - mutex_lock(&input_dev->mutex); 694 + guard(mutex)(&input_dev->mutex); 695 695 696 696 if (input_device_enabled(input_dev)) { 697 697 /* Enable unit clock */ 698 - ret = clk_prepare_enable(keypad->clk); 699 - if (!ret) 700 - pxa27x_keypad_config(keypad); 701 - } 698 + error = clk_prepare_enable(keypad->clk); 699 + if (error) 700 + return error; 702 701 703 - mutex_unlock(&input_dev->mutex); 702 + pxa27x_keypad_config(keypad); 703 + } 704 704 } 705 705 706 - return ret; 706 + return 0; 707 707 } 708 708 709 709 static DEFINE_SIMPLE_DEV_PM_OPS(pxa27x_keypad_pm_ops,
+1 -1
drivers/input/keyboard/samsung-keypad.c
··· 587 587 588 588 static struct platform_driver samsung_keypad_driver = { 589 589 .probe = samsung_keypad_probe, 590 - .remove_new = samsung_keypad_remove, 590 + .remove = samsung_keypad_remove, 591 591 .driver = { 592 592 .name = "samsung-keypad", 593 593 .of_match_table = of_match_ptr(samsung_keypad_dt_match),
+1 -1
drivers/input/keyboard/sh_keysc.c
··· 319 319 320 320 static struct platform_driver sh_keysc_device_driver = { 321 321 .probe = sh_keysc_probe, 322 - .remove_new = sh_keysc_remove, 322 + .remove = sh_keysc_remove, 323 323 .driver = { 324 324 .name = "sh_keysc", 325 325 .pm = pm_sleep_ptr(&sh_keysc_dev_pm_ops),
+2 -7
drivers/input/keyboard/spear-keyboard.c
··· 20 20 #include <linux/module.h> 21 21 #include <linux/of.h> 22 22 #include <linux/platform_device.h> 23 - #include <linux/pm_wakeup.h> 24 23 #include <linux/slab.h> 25 24 #include <linux/types.h> 26 25 #include <linux/platform_data/keyboard-spear.h> ··· 273 274 struct input_dev *input_dev = kbd->input; 274 275 unsigned int rate = 0, mode_ctl_reg, val; 275 276 276 - mutex_lock(&input_dev->mutex); 277 + guard(mutex)(&input_dev->mutex); 277 278 278 279 /* explicitly enable clock as we may program device */ 279 280 clk_enable(kbd->clk); ··· 314 315 /* restore previous clk state */ 315 316 clk_disable(kbd->clk); 316 317 317 - mutex_unlock(&input_dev->mutex); 318 - 319 318 return 0; 320 319 } 321 320 ··· 323 326 struct spear_kbd *kbd = platform_get_drvdata(pdev); 324 327 struct input_dev *input_dev = kbd->input; 325 328 326 - mutex_lock(&input_dev->mutex); 329 + guard(mutex)(&input_dev->mutex); 327 330 328 331 if (device_may_wakeup(&pdev->dev)) { 329 332 if (kbd->irq_wake_enabled) { ··· 338 341 /* restore current configuration */ 339 342 if (input_device_enabled(input_dev)) 340 343 writel_relaxed(kbd->mode_ctl_reg, kbd->io_base + MODE_CTL_REG); 341 - 342 - mutex_unlock(&input_dev->mutex); 343 344 344 345 return 0; 345 346 }
+10 -9
drivers/input/keyboard/st-keyscan.c
··· 216 216 struct st_keyscan *keypad = platform_get_drvdata(pdev); 217 217 struct input_dev *input = keypad->input_dev; 218 218 219 - mutex_lock(&input->mutex); 219 + guard(mutex)(&input->mutex); 220 220 221 221 if (device_may_wakeup(dev)) 222 222 enable_irq_wake(keypad->irq); 223 223 else if (input_device_enabled(input)) 224 224 keyscan_stop(keypad); 225 225 226 - mutex_unlock(&input->mutex); 227 226 return 0; 228 227 } 229 228 ··· 231 232 struct platform_device *pdev = to_platform_device(dev); 232 233 struct st_keyscan *keypad = platform_get_drvdata(pdev); 233 234 struct input_dev *input = keypad->input_dev; 234 - int retval = 0; 235 + int error; 235 236 236 - mutex_lock(&input->mutex); 237 + guard(mutex)(&input->mutex); 237 238 238 - if (device_may_wakeup(dev)) 239 + if (device_may_wakeup(dev)) { 239 240 disable_irq_wake(keypad->irq); 240 - else if (input_device_enabled(input)) 241 - retval = keyscan_start(keypad); 241 + } else if (input_device_enabled(input)) { 242 + error = keyscan_start(keypad); 243 + if (error) 244 + return error; 245 + } 242 246 243 - mutex_unlock(&input->mutex); 244 - return retval; 247 + return 0; 245 248 } 246 249 247 250 static DEFINE_SIMPLE_DEV_PM_OPS(keyscan_dev_pm_ops,
+1 -1
drivers/input/keyboard/stmpe-keypad.c
··· 414 414 static struct platform_driver stmpe_keypad_driver = { 415 415 .driver.name = "stmpe-keypad", 416 416 .probe = stmpe_keypad_probe, 417 - .remove_new = stmpe_keypad_remove, 417 + .remove = stmpe_keypad_remove, 418 418 }; 419 419 module_platform_driver(stmpe_keypad_driver); 420 420
+2 -6
drivers/input/keyboard/sun4i-lradc-keys.c
··· 24 24 #include <linux/of.h> 25 25 #include <linux/platform_device.h> 26 26 #include <linux/pm_wakeirq.h> 27 - #include <linux/pm_wakeup.h> 28 27 #include <linux/property.h> 29 28 #include <linux/regulator/consumer.h> 30 29 #include <linux/reset.h> ··· 201 202 static int sun4i_lradc_load_dt_keymap(struct device *dev, 202 203 struct sun4i_lradc_data *lradc) 203 204 { 204 - struct device_node *np, *pp; 205 + struct device_node *np; 205 206 int i; 206 207 int error; 207 208 ··· 222 223 return -ENOMEM; 223 224 224 225 i = 0; 225 - for_each_child_of_node(np, pp) { 226 + for_each_child_of_node_scoped(np, pp) { 226 227 struct sun4i_lradc_keymap *map = &lradc->chan0_map[i]; 227 228 u32 channel; 228 229 229 230 error = of_property_read_u32(pp, "channel", &channel); 230 231 if (error || channel != 0) { 231 232 dev_err(dev, "%pOFn: Inval channel prop\n", pp); 232 - of_node_put(pp); 233 233 return -EINVAL; 234 234 } 235 235 236 236 error = of_property_read_u32(pp, "voltage", &map->voltage); 237 237 if (error) { 238 238 dev_err(dev, "%pOFn: Inval voltage prop\n", pp); 239 - of_node_put(pp); 240 239 return -EINVAL; 241 240 } 242 241 243 242 error = of_property_read_u32(pp, "linux,code", &map->keycode); 244 243 if (error) { 245 244 dev_err(dev, "%pOFn: Inval linux,code prop\n", pp); 246 - of_node_put(pp); 247 245 return -EINVAL; 248 246 } 249 247
+2 -3
drivers/input/keyboard/sunkbd.c
··· 241 241 242 242 static void sunkbd_enable(struct sunkbd *sunkbd, bool enable) 243 243 { 244 - serio_pause_rx(sunkbd->serio); 245 - sunkbd->enabled = enable; 246 - serio_continue_rx(sunkbd->serio); 244 + scoped_guard(serio_pause_rx, sunkbd->serio) 245 + sunkbd->enabled = enable; 247 246 248 247 if (!enable) { 249 248 wake_up_interruptible(&sunkbd->wait);
+1 -1
drivers/input/misc/88pm80x_onkey.c
··· 141 141 .pm = &pm80x_onkey_pm_ops, 142 142 }, 143 143 .probe = pm80x_onkey_probe, 144 - .remove_new = pm80x_onkey_remove, 144 + .remove = pm80x_onkey_remove, 145 145 }; 146 146 147 147 module_platform_driver(pm80x_onkey_driver);
+3 -9
drivers/input/misc/ad714x.c
··· 941 941 struct ad714x_chip *ad714x = data; 942 942 int i; 943 943 944 - mutex_lock(&ad714x->mutex); 944 + guard(mutex)(&ad714x->mutex); 945 945 946 946 ad714x->read(ad714x, STG_LOW_INT_STA_REG, &ad714x->l_state, 3); 947 947 ··· 953 953 ad714x_wheel_state_machine(ad714x, i); 954 954 for (i = 0; i < ad714x->hw->touchpad_num; i++) 955 955 ad714x_touchpad_state_machine(ad714x, i); 956 - 957 - mutex_unlock(&ad714x->mutex); 958 956 959 957 return IRQ_HANDLED; 960 958 } ··· 1167 1169 1168 1170 dev_dbg(ad714x->dev, "%s enter\n", __func__); 1169 1171 1170 - mutex_lock(&ad714x->mutex); 1172 + guard(mutex)(&ad714x->mutex); 1171 1173 1172 1174 data = ad714x->hw->sys_cfg_reg[AD714X_PWR_CTRL] | 0x3; 1173 1175 ad714x->write(ad714x, AD714X_PWR_CTRL, data); 1174 - 1175 - mutex_unlock(&ad714x->mutex); 1176 1176 1177 1177 return 0; 1178 1178 } ··· 1180 1184 struct ad714x_chip *ad714x = dev_get_drvdata(dev); 1181 1185 dev_dbg(ad714x->dev, "%s enter\n", __func__); 1182 1186 1183 - mutex_lock(&ad714x->mutex); 1187 + guard(mutex)(&ad714x->mutex); 1184 1188 1185 1189 /* resume to non-shutdown mode */ 1186 1190 ··· 1192 1196 */ 1193 1197 1194 1198 ad714x->read(ad714x, STG_LOW_INT_STA_REG, &ad714x->l_state, 3); 1195 - 1196 - mutex_unlock(&ad714x->mutex); 1197 1199 1198 1200 return 0; 1199 1201 }
+19 -38
drivers/input/misc/ati_remote2.c
··· 244 244 if (r) { 245 245 dev_err(&ar2->intf[0]->dev, 246 246 "%s(): usb_autopm_get_interface() = %d\n", __func__, r); 247 - goto fail1; 247 + return r; 248 248 } 249 249 250 - mutex_lock(&ati_remote2_mutex); 250 + scoped_guard(mutex, &ati_remote2_mutex) { 251 + if (!(ar2->flags & ATI_REMOTE2_SUSPENDED)) { 252 + r = ati_remote2_submit_urbs(ar2); 253 + if (r) 254 + break; 255 + } 251 256 252 - if (!(ar2->flags & ATI_REMOTE2_SUSPENDED)) { 253 - r = ati_remote2_submit_urbs(ar2); 254 - if (r) 255 - goto fail2; 257 + ar2->flags |= ATI_REMOTE2_OPENED; 256 258 } 257 - 258 - ar2->flags |= ATI_REMOTE2_OPENED; 259 - 260 - mutex_unlock(&ati_remote2_mutex); 261 259 262 260 usb_autopm_put_interface(ar2->intf[0]); 263 261 264 - return 0; 265 - 266 - fail2: 267 - mutex_unlock(&ati_remote2_mutex); 268 - usb_autopm_put_interface(ar2->intf[0]); 269 - fail1: 270 262 return r; 271 263 } 272 264 ··· 268 276 269 277 dev_dbg(&ar2->intf[0]->dev, "%s()\n", __func__); 270 278 271 - mutex_lock(&ati_remote2_mutex); 279 + guard(mutex)(&ati_remote2_mutex); 272 280 273 281 if (!(ar2->flags & ATI_REMOTE2_SUSPENDED)) 274 282 ati_remote2_kill_urbs(ar2); 275 283 276 284 ar2->flags &= ~ATI_REMOTE2_OPENED; 277 - 278 - mutex_unlock(&ati_remote2_mutex); 279 285 } 280 286 281 287 static void ati_remote2_input_mouse(struct ati_remote2 *ar2) ··· 703 713 return r; 704 714 } 705 715 706 - mutex_lock(&ati_remote2_mutex); 707 - 708 - if (mask != ar2->channel_mask) { 709 - r = ati_remote2_setup(ar2, mask); 710 - if (!r) 711 - ar2->channel_mask = mask; 716 + scoped_guard(mutex, &ati_remote2_mutex) { 717 + if (mask != ar2->channel_mask) { 718 + r = ati_remote2_setup(ar2, mask); 719 + if (!r) 720 + ar2->channel_mask = mask; 721 + } 712 722 } 713 - 714 - mutex_unlock(&ati_remote2_mutex); 715 723 716 724 usb_autopm_put_interface(ar2->intf[0]); 717 725 ··· 880 892 881 893 dev_dbg(&ar2->intf[0]->dev, "%s()\n", __func__); 882 894 883 - mutex_lock(&ati_remote2_mutex); 895 + guard(mutex)(&ati_remote2_mutex); 884 896 885 897 if (ar2->flags & ATI_REMOTE2_OPENED) 886 898 ati_remote2_kill_urbs(ar2); 887 899 888 900 ar2->flags |= ATI_REMOTE2_SUSPENDED; 889 - 890 - mutex_unlock(&ati_remote2_mutex); 891 901 892 902 return 0; 893 903 } ··· 903 917 904 918 dev_dbg(&ar2->intf[0]->dev, "%s()\n", __func__); 905 919 906 - mutex_lock(&ati_remote2_mutex); 920 + guard(mutex)(&ati_remote2_mutex); 907 921 908 922 if (ar2->flags & ATI_REMOTE2_OPENED) 909 923 r = ati_remote2_submit_urbs(ar2); 910 924 911 925 if (!r) 912 926 ar2->flags &= ~ATI_REMOTE2_SUSPENDED; 913 - 914 - mutex_unlock(&ati_remote2_mutex); 915 927 916 928 return r; 917 929 } ··· 927 943 928 944 dev_dbg(&ar2->intf[0]->dev, "%s()\n", __func__); 929 945 930 - mutex_lock(&ati_remote2_mutex); 946 + guard(mutex)(&ati_remote2_mutex); 931 947 932 948 r = ati_remote2_setup(ar2, ar2->channel_mask); 933 949 if (r) 934 - goto out; 950 + return r; 935 951 936 952 if (ar2->flags & ATI_REMOTE2_OPENED) 937 953 r = ati_remote2_submit_urbs(ar2); 938 954 939 955 if (!r) 940 956 ar2->flags &= ~ATI_REMOTE2_SUSPENDED; 941 - 942 - out: 943 - mutex_unlock(&ati_remote2_mutex); 944 957 945 958 return r; 946 959 }
+78 -87
drivers/input/misc/cm109.c
··· 355 355 __func__, error); 356 356 } 357 357 358 + static void cm109_submit_ctl(struct cm109_dev *dev) 359 + { 360 + int error; 361 + 362 + guard(spinlock_irqsave)(&dev->ctl_submit_lock); 363 + 364 + dev->irq_urb_pending = 0; 365 + 366 + if (unlikely(dev->shutdown)) 367 + return; 368 + 369 + if (dev->buzzer_state) 370 + dev->ctl_data->byte[HID_OR0] |= BUZZER_ON; 371 + else 372 + dev->ctl_data->byte[HID_OR0] &= ~BUZZER_ON; 373 + 374 + dev->ctl_data->byte[HID_OR1] = dev->keybit; 375 + dev->ctl_data->byte[HID_OR2] = dev->keybit; 376 + 377 + dev->buzzer_pending = 0; 378 + dev->ctl_urb_pending = 1; 379 + 380 + error = usb_submit_urb(dev->urb_ctl, GFP_ATOMIC); 381 + if (error) 382 + dev_err(&dev->intf->dev, 383 + "%s: usb_submit_urb (urb_ctl) failed %d\n", 384 + __func__, error); 385 + } 386 + 358 387 /* 359 388 * IRQ handler 360 389 */ ··· 391 362 { 392 363 struct cm109_dev *dev = urb->context; 393 364 const int status = urb->status; 394 - int error; 395 - unsigned long flags; 396 365 397 366 dev_dbg(&dev->intf->dev, "### URB IRQ: [0x%02x 0x%02x 0x%02x 0x%02x] keybit=0x%02x\n", 398 367 dev->irq_data->byte[0], ··· 428 401 } 429 402 430 403 out: 431 - 432 - spin_lock_irqsave(&dev->ctl_submit_lock, flags); 433 - 434 - dev->irq_urb_pending = 0; 435 - 436 - if (likely(!dev->shutdown)) { 437 - 438 - if (dev->buzzer_state) 439 - dev->ctl_data->byte[HID_OR0] |= BUZZER_ON; 440 - else 441 - dev->ctl_data->byte[HID_OR0] &= ~BUZZER_ON; 442 - 443 - dev->ctl_data->byte[HID_OR1] = dev->keybit; 444 - dev->ctl_data->byte[HID_OR2] = dev->keybit; 445 - 446 - dev->buzzer_pending = 0; 447 - dev->ctl_urb_pending = 1; 448 - 449 - error = usb_submit_urb(dev->urb_ctl, GFP_ATOMIC); 450 - if (error) 451 - dev_err(&dev->intf->dev, 452 - "%s: usb_submit_urb (urb_ctl) failed %d\n", 453 - __func__, error); 454 - } 455 - 456 - spin_unlock_irqrestore(&dev->ctl_submit_lock, flags); 404 + cm109_submit_ctl(dev); 457 405 } 458 406 459 407 static void cm109_urb_ctl_callback(struct urb *urb) ··· 436 434 struct cm109_dev *dev = urb->context; 437 435 const int status = urb->status; 438 436 int error; 439 - unsigned long flags; 440 437 441 438 dev_dbg(&dev->intf->dev, "### URB CTL: [0x%02x 0x%02x 0x%02x 0x%02x]\n", 442 439 dev->ctl_data->byte[0], ··· 450 449 __func__, status); 451 450 } 452 451 453 - spin_lock_irqsave(&dev->ctl_submit_lock, flags); 452 + guard(spinlock_irqsave)(&dev->ctl_submit_lock); 454 453 455 454 dev->ctl_urb_pending = 0; 456 455 457 - if (likely(!dev->shutdown)) { 456 + if (unlikely(dev->shutdown)) 457 + return; 458 458 459 - if (dev->buzzer_pending || status) { 460 - dev->buzzer_pending = 0; 461 - dev->ctl_urb_pending = 1; 462 - cm109_submit_buzz_toggle(dev); 463 - } else if (likely(!dev->irq_urb_pending)) { 464 - /* ask for key data */ 465 - dev->irq_urb_pending = 1; 466 - error = usb_submit_urb(dev->urb_irq, GFP_ATOMIC); 467 - if (error) 468 - dev_err(&dev->intf->dev, 469 - "%s: usb_submit_urb (urb_irq) failed %d\n", 470 - __func__, error); 471 - } 459 + if (dev->buzzer_pending || status) { 460 + dev->buzzer_pending = 0; 461 + dev->ctl_urb_pending = 1; 462 + cm109_submit_buzz_toggle(dev); 463 + } else if (likely(!dev->irq_urb_pending)) { 464 + /* ask for key data */ 465 + dev->irq_urb_pending = 1; 466 + error = usb_submit_urb(dev->urb_irq, GFP_ATOMIC); 467 + if (error) 468 + dev_err(&dev->intf->dev, 469 + "%s: usb_submit_urb (urb_irq) failed %d\n", 470 + __func__, error); 472 471 } 473 - 474 - spin_unlock_irqrestore(&dev->ctl_submit_lock, flags); 475 472 } 476 473 477 474 static void cm109_toggle_buzzer_async(struct cm109_dev *dev) 478 475 { 479 - unsigned long flags; 480 - 481 - spin_lock_irqsave(&dev->ctl_submit_lock, flags); 476 + guard(spinlock_irqsave)(&dev->ctl_submit_lock); 482 477 483 478 if (dev->ctl_urb_pending) { 484 479 /* URB completion will resubmit */ ··· 483 486 dev->ctl_urb_pending = 1; 484 487 cm109_submit_buzz_toggle(dev); 485 488 } 486 - 487 - spin_unlock_irqrestore(&dev->ctl_submit_lock, flags); 488 489 } 489 490 490 491 static void cm109_toggle_buzzer_sync(struct cm109_dev *dev, int on) ··· 551 556 return error; 552 557 } 553 558 554 - mutex_lock(&dev->pm_mutex); 559 + scoped_guard(mutex, &dev->pm_mutex) { 560 + dev->buzzer_state = 0; 561 + dev->key_code = -1; /* no keys pressed */ 562 + dev->keybit = 0xf; 555 563 556 - dev->buzzer_state = 0; 557 - dev->key_code = -1; /* no keys pressed */ 558 - dev->keybit = 0xf; 564 + /* issue INIT */ 565 + dev->ctl_data->byte[HID_OR0] = HID_OR_GPO_BUZ_SPDIF; 566 + dev->ctl_data->byte[HID_OR1] = dev->keybit; 567 + dev->ctl_data->byte[HID_OR2] = dev->keybit; 568 + dev->ctl_data->byte[HID_OR3] = 0x00; 559 569 560 - /* issue INIT */ 561 - dev->ctl_data->byte[HID_OR0] = HID_OR_GPO_BUZ_SPDIF; 562 - dev->ctl_data->byte[HID_OR1] = dev->keybit; 563 - dev->ctl_data->byte[HID_OR2] = dev->keybit; 564 - dev->ctl_data->byte[HID_OR3] = 0x00; 565 - 566 - dev->ctl_urb_pending = 1; 567 - error = usb_submit_urb(dev->urb_ctl, GFP_KERNEL); 568 - if (error) { 569 - dev->ctl_urb_pending = 0; 570 - dev_err(&dev->intf->dev, "%s: usb_submit_urb (urb_ctl) failed %d\n", 571 - __func__, error); 572 - } else { 573 - dev->open = 1; 570 + dev->ctl_urb_pending = 1; 571 + error = usb_submit_urb(dev->urb_ctl, GFP_KERNEL); 572 + if (!error) { 573 + dev->open = 1; 574 + return 0; 575 + } 574 576 } 575 577 576 - mutex_unlock(&dev->pm_mutex); 578 + dev->ctl_urb_pending = 0; 579 + usb_autopm_put_interface(dev->intf); 577 580 578 - if (error) 579 - usb_autopm_put_interface(dev->intf); 581 + dev_err(&dev->intf->dev, "%s: usb_submit_urb (urb_ctl) failed %d\n", 582 + __func__, error); 580 583 581 584 return error; 582 585 } ··· 583 590 { 584 591 struct cm109_dev *dev = input_get_drvdata(idev); 585 592 586 - mutex_lock(&dev->pm_mutex); 587 - 588 - /* 589 - * Once we are here event delivery is stopped so we 590 - * don't need to worry about someone starting buzzer 591 - * again 592 - */ 593 - cm109_stop_traffic(dev); 594 - dev->open = 0; 595 - 596 - mutex_unlock(&dev->pm_mutex); 593 + scoped_guard(mutex, &dev->pm_mutex) { 594 + /* 595 + * Once we are here event delivery is stopped so we 596 + * don't need to worry about someone starting buzzer 597 + * again 598 + */ 599 + cm109_stop_traffic(dev); 600 + dev->open = 0; 601 + } 597 602 598 603 usb_autopm_put_interface(dev->intf); 599 604 } ··· 814 823 815 824 dev_info(&intf->dev, "cm109: usb_suspend (event=%d)\n", message.event); 816 825 817 - mutex_lock(&dev->pm_mutex); 826 + guard(mutex)(&dev->pm_mutex); 827 + 818 828 cm109_stop_traffic(dev); 819 - mutex_unlock(&dev->pm_mutex); 820 829 821 830 return 0; 822 831 } ··· 827 836 828 837 dev_info(&intf->dev, "cm109: usb_resume\n"); 829 838 830 - mutex_lock(&dev->pm_mutex); 839 + guard(mutex)(&dev->pm_mutex); 840 + 831 841 cm109_restore_state(dev); 832 - mutex_unlock(&dev->pm_mutex); 833 842 834 843 return 0; 835 844 }
+4 -12
drivers/input/misc/cma3000_d0x.c
··· 217 217 { 218 218 struct cma3000_accl_data *data = input_get_drvdata(input_dev); 219 219 220 - mutex_lock(&data->mutex); 220 + guard(mutex)(&data->mutex); 221 221 222 222 if (!data->suspended) 223 223 cma3000_poweron(data); 224 224 225 225 data->opened = true; 226 - 227 - mutex_unlock(&data->mutex); 228 226 229 227 return 0; 230 228 } ··· 231 233 { 232 234 struct cma3000_accl_data *data = input_get_drvdata(input_dev); 233 235 234 - mutex_lock(&data->mutex); 236 + guard(mutex)(&data->mutex); 235 237 236 238 if (!data->suspended) 237 239 cma3000_poweroff(data); 238 240 239 241 data->opened = false; 240 - 241 - mutex_unlock(&data->mutex); 242 242 } 243 243 244 244 void cma3000_suspend(struct cma3000_accl_data *data) 245 245 { 246 - mutex_lock(&data->mutex); 246 + guard(mutex)(&data->mutex); 247 247 248 248 if (!data->suspended && data->opened) 249 249 cma3000_poweroff(data); 250 250 251 251 data->suspended = true; 252 - 253 - mutex_unlock(&data->mutex); 254 252 } 255 253 EXPORT_SYMBOL(cma3000_suspend); 256 254 257 255 258 256 void cma3000_resume(struct cma3000_accl_data *data) 259 257 { 260 - mutex_lock(&data->mutex); 258 + guard(mutex)(&data->mutex); 261 259 262 260 if (data->suspended && data->opened) 263 261 cma3000_poweron(data); 264 262 265 263 data->suspended = false; 266 - 267 - mutex_unlock(&data->mutex); 268 264 } 269 265 EXPORT_SYMBOL(cma3000_resume); 270 266
+4 -2
drivers/input/misc/cs40l50-vibra.c
··· 334 334 work_data.custom_len = effect->u.periodic.custom_len; 335 335 work_data.vib = vib; 336 336 work_data.effect = effect; 337 - INIT_WORK(&work_data.work, cs40l50_add_worker); 337 + INIT_WORK_ONSTACK(&work_data.work, cs40l50_add_worker); 338 338 339 339 /* Push to the workqueue to serialize with playbacks */ 340 340 queue_work(vib->vib_wq, &work_data.work); 341 341 flush_work(&work_data.work); 342 + destroy_work_on_stack(&work_data.work); 342 343 343 344 kfree(work_data.custom_data); 344 345 ··· 468 467 work_data.vib = vib; 469 468 work_data.effect = &dev->ff->effects[effect_id]; 470 469 471 - INIT_WORK(&work_data.work, cs40l50_erase_worker); 470 + INIT_WORK_ONSTACK(&work_data.work, cs40l50_erase_worker); 472 471 473 472 /* Push to workqueue to serialize with playbacks */ 474 473 queue_work(vib->vib_wq, &work_data.work); 475 474 flush_work(&work_data.work); 475 + destroy_work_on_stack(&work_data.work); 476 476 477 477 return work_data.error; 478 478 }
+12 -14
drivers/input/misc/da7280.c
··· 1263 1263 { 1264 1264 struct da7280_haptic *haptics = dev_get_drvdata(dev); 1265 1265 1266 - mutex_lock(&haptics->input_dev->mutex); 1266 + guard(mutex)(&haptics->input_dev->mutex); 1267 1267 1268 1268 /* 1269 1269 * Make sure no new requests will be submitted while device is 1270 1270 * suspended. 1271 1271 */ 1272 - spin_lock_irq(&haptics->input_dev->event_lock); 1273 - haptics->suspended = true; 1274 - spin_unlock_irq(&haptics->input_dev->event_lock); 1272 + scoped_guard(spinlock_irq, &haptics->input_dev->event_lock) { 1273 + haptics->suspended = true; 1274 + } 1275 1275 1276 1276 da7280_haptic_stop(haptics); 1277 - 1278 - mutex_unlock(&haptics->input_dev->mutex); 1279 1277 1280 1278 return 0; 1281 1279 } ··· 1281 1283 static int da7280_resume(struct device *dev) 1282 1284 { 1283 1285 struct da7280_haptic *haptics = dev_get_drvdata(dev); 1284 - int retval; 1286 + int error; 1285 1287 1286 - mutex_lock(&haptics->input_dev->mutex); 1288 + guard(mutex)(&haptics->input_dev->mutex); 1287 1289 1288 - retval = da7280_haptic_start(haptics); 1289 - if (!retval) { 1290 - spin_lock_irq(&haptics->input_dev->event_lock); 1290 + error = da7280_haptic_start(haptics); 1291 + if (error) 1292 + return error; 1293 + 1294 + scoped_guard(spinlock_irq, &haptics->input_dev->event_lock) { 1291 1295 haptics->suspended = false; 1292 - spin_unlock_irq(&haptics->input_dev->event_lock); 1293 1296 } 1294 1297 1295 - mutex_unlock(&haptics->input_dev->mutex); 1296 - return retval; 1298 + return 0; 1297 1299 } 1298 1300 1299 1301 #ifdef CONFIG_OF
+2 -2
drivers/input/misc/da9052_onkey.c
··· 140 140 141 141 static struct platform_driver da9052_onkey_driver = { 142 142 .probe = da9052_onkey_probe, 143 - .remove_new = da9052_onkey_remove, 144 - .driver = { 143 + .remove = da9052_onkey_remove, 144 + .driver = { 145 145 .name = "da9052-onkey", 146 146 }, 147 147 };
+2 -2
drivers/input/misc/da9055_onkey.c
··· 145 145 146 146 static struct platform_driver da9055_onkey_driver = { 147 147 .probe = da9055_onkey_probe, 148 - .remove_new = da9055_onkey_remove, 149 - .driver = { 148 + .remove = da9055_onkey_remove, 149 + .driver = { 150 150 .name = "da9055-onkey", 151 151 }, 152 152 };
+24 -26
drivers/input/misc/drv260x.c
··· 537 537 static int drv260x_suspend(struct device *dev) 538 538 { 539 539 struct drv260x_data *haptics = dev_get_drvdata(dev); 540 - int ret = 0; 540 + int error; 541 541 542 - mutex_lock(&haptics->input_dev->mutex); 542 + guard(mutex)(&haptics->input_dev->mutex); 543 543 544 544 if (input_device_enabled(haptics->input_dev)) { 545 - ret = regmap_update_bits(haptics->regmap, 546 - DRV260X_MODE, 547 - DRV260X_STANDBY_MASK, 548 - DRV260X_STANDBY); 549 - if (ret) { 545 + error = regmap_update_bits(haptics->regmap, 546 + DRV260X_MODE, 547 + DRV260X_STANDBY_MASK, 548 + DRV260X_STANDBY); 549 + if (error) { 550 550 dev_err(dev, "Failed to set standby mode\n"); 551 - goto out; 551 + return error; 552 552 } 553 553 554 554 gpiod_set_value(haptics->enable_gpio, 0); 555 555 556 - ret = regulator_disable(haptics->regulator); 557 - if (ret) { 556 + error = regulator_disable(haptics->regulator); 557 + if (error) { 558 558 dev_err(dev, "Failed to disable regulator\n"); 559 559 regmap_update_bits(haptics->regmap, 560 560 DRV260X_MODE, 561 561 DRV260X_STANDBY_MASK, 0); 562 + return error; 562 563 } 563 564 } 564 - out: 565 - mutex_unlock(&haptics->input_dev->mutex); 566 - return ret; 565 + 566 + return 0; 567 567 } 568 568 569 569 static int drv260x_resume(struct device *dev) 570 570 { 571 571 struct drv260x_data *haptics = dev_get_drvdata(dev); 572 - int ret = 0; 572 + int error; 573 573 574 - mutex_lock(&haptics->input_dev->mutex); 574 + guard(mutex)(&haptics->input_dev->mutex); 575 575 576 576 if (input_device_enabled(haptics->input_dev)) { 577 - ret = regulator_enable(haptics->regulator); 578 - if (ret) { 577 + error = regulator_enable(haptics->regulator); 578 + if (error) { 579 579 dev_err(dev, "Failed to enable regulator\n"); 580 - goto out; 580 + return error; 581 581 } 582 582 583 - ret = regmap_update_bits(haptics->regmap, 584 - DRV260X_MODE, 585 - DRV260X_STANDBY_MASK, 0); 586 - if (ret) { 583 + error = regmap_update_bits(haptics->regmap, 584 + DRV260X_MODE, 585 + DRV260X_STANDBY_MASK, 0); 586 + if (error) { 587 587 dev_err(dev, "Failed to unset standby mode\n"); 588 588 regulator_disable(haptics->regulator); 589 - goto out; 589 + return error; 590 590 } 591 591 592 592 gpiod_set_value(haptics->enable_gpio, 1); 593 593 } 594 594 595 - out: 596 - mutex_unlock(&haptics->input_dev->mutex); 597 - return ret; 595 + return 0; 598 596 } 599 597 600 598 static DEFINE_SIMPLE_DEV_PM_OPS(drv260x_pm_ops, drv260x_suspend, drv260x_resume);
+22 -24
drivers/input/misc/drv2665.c
··· 15 15 #include <linux/delay.h> 16 16 #include <linux/regulator/consumer.h> 17 17 18 - /* Contol registers */ 18 + /* Control registers */ 19 19 #define DRV2665_STATUS 0x00 20 20 #define DRV2665_CTRL_1 0x01 21 21 #define DRV2665_CTRL_2 0x02 ··· 225 225 static int drv2665_suspend(struct device *dev) 226 226 { 227 227 struct drv2665_data *haptics = dev_get_drvdata(dev); 228 - int ret = 0; 228 + int error; 229 229 230 - mutex_lock(&haptics->input_dev->mutex); 230 + guard(mutex)(&haptics->input_dev->mutex); 231 231 232 232 if (input_device_enabled(haptics->input_dev)) { 233 - ret = regmap_update_bits(haptics->regmap, DRV2665_CTRL_2, 234 - DRV2665_STANDBY, DRV2665_STANDBY); 235 - if (ret) { 233 + error = regmap_update_bits(haptics->regmap, DRV2665_CTRL_2, 234 + DRV2665_STANDBY, DRV2665_STANDBY); 235 + if (error) { 236 236 dev_err(dev, "Failed to set standby mode\n"); 237 237 regulator_disable(haptics->regulator); 238 - goto out; 238 + return error; 239 239 } 240 240 241 - ret = regulator_disable(haptics->regulator); 242 - if (ret) { 241 + error = regulator_disable(haptics->regulator); 242 + if (error) { 243 243 dev_err(dev, "Failed to disable regulator\n"); 244 244 regmap_update_bits(haptics->regmap, 245 245 DRV2665_CTRL_2, 246 246 DRV2665_STANDBY, 0); 247 + return error; 247 248 } 248 249 } 249 - out: 250 - mutex_unlock(&haptics->input_dev->mutex); 251 - return ret; 250 + 251 + return 0; 252 252 } 253 253 254 254 static int drv2665_resume(struct device *dev) 255 255 { 256 256 struct drv2665_data *haptics = dev_get_drvdata(dev); 257 - int ret = 0; 257 + int error; 258 258 259 - mutex_lock(&haptics->input_dev->mutex); 259 + guard(mutex)(&haptics->input_dev->mutex); 260 260 261 261 if (input_device_enabled(haptics->input_dev)) { 262 - ret = regulator_enable(haptics->regulator); 263 - if (ret) { 262 + error = regulator_enable(haptics->regulator); 263 + if (error) { 264 264 dev_err(dev, "Failed to enable regulator\n"); 265 - goto out; 265 + return error; 266 266 } 267 267 268 - ret = regmap_update_bits(haptics->regmap, DRV2665_CTRL_2, 269 - DRV2665_STANDBY, 0); 270 - if (ret) { 268 + error = regmap_update_bits(haptics->regmap, DRV2665_CTRL_2, 269 + DRV2665_STANDBY, 0); 270 + if (error) { 271 271 dev_err(dev, "Failed to unset standby mode\n"); 272 272 regulator_disable(haptics->regulator); 273 - goto out; 273 + return error; 274 274 } 275 275 276 276 } 277 277 278 - out: 279 - mutex_unlock(&haptics->input_dev->mutex); 280 - return ret; 278 + return 0; 281 279 } 282 280 283 281 static DEFINE_SIMPLE_DEV_PM_OPS(drv2665_pm_ops, drv2665_suspend, drv2665_resume);
+22 -24
drivers/input/misc/drv2667.c
··· 16 16 #include <linux/delay.h> 17 17 #include <linux/regulator/consumer.h> 18 18 19 - /* Contol registers */ 19 + /* Control registers */ 20 20 #define DRV2667_STATUS 0x00 21 21 #define DRV2667_CTRL_1 0x01 22 22 #define DRV2667_CTRL_2 0x02 ··· 402 402 static int drv2667_suspend(struct device *dev) 403 403 { 404 404 struct drv2667_data *haptics = dev_get_drvdata(dev); 405 - int ret = 0; 405 + int error; 406 406 407 - mutex_lock(&haptics->input_dev->mutex); 407 + guard(mutex)(&haptics->input_dev->mutex); 408 408 409 409 if (input_device_enabled(haptics->input_dev)) { 410 - ret = regmap_update_bits(haptics->regmap, DRV2667_CTRL_2, 411 - DRV2667_STANDBY, DRV2667_STANDBY); 412 - if (ret) { 410 + error = regmap_update_bits(haptics->regmap, DRV2667_CTRL_2, 411 + DRV2667_STANDBY, DRV2667_STANDBY); 412 + if (error) { 413 413 dev_err(dev, "Failed to set standby mode\n"); 414 414 regulator_disable(haptics->regulator); 415 - goto out; 415 + return error; 416 416 } 417 417 418 - ret = regulator_disable(haptics->regulator); 419 - if (ret) { 418 + error = regulator_disable(haptics->regulator); 419 + if (error) { 420 420 dev_err(dev, "Failed to disable regulator\n"); 421 421 regmap_update_bits(haptics->regmap, 422 422 DRV2667_CTRL_2, 423 423 DRV2667_STANDBY, 0); 424 + return error; 424 425 } 425 426 } 426 - out: 427 - mutex_unlock(&haptics->input_dev->mutex); 428 - return ret; 427 + 428 + return 0; 429 429 } 430 430 431 431 static int drv2667_resume(struct device *dev) 432 432 { 433 433 struct drv2667_data *haptics = dev_get_drvdata(dev); 434 - int ret = 0; 434 + int error; 435 435 436 - mutex_lock(&haptics->input_dev->mutex); 436 + guard(mutex)(&haptics->input_dev->mutex); 437 437 438 438 if (input_device_enabled(haptics->input_dev)) { 439 - ret = regulator_enable(haptics->regulator); 440 - if (ret) { 439 + error = regulator_enable(haptics->regulator); 440 + if (error) { 441 441 dev_err(dev, "Failed to enable regulator\n"); 442 - goto out; 442 + return error; 443 443 } 444 444 445 - ret = regmap_update_bits(haptics->regmap, DRV2667_CTRL_2, 446 - DRV2667_STANDBY, 0); 447 - if (ret) { 445 + error = regmap_update_bits(haptics->regmap, DRV2667_CTRL_2, 446 + DRV2667_STANDBY, 0); 447 + if (error) { 448 448 dev_err(dev, "Failed to unset standby mode\n"); 449 449 regulator_disable(haptics->regulator); 450 - goto out; 450 + return error; 451 451 } 452 452 453 453 } 454 454 455 - out: 456 - mutex_unlock(&haptics->input_dev->mutex); 457 - return ret; 455 + return 0; 458 456 } 459 457 460 458 static DEFINE_SIMPLE_DEV_PM_OPS(drv2667_pm_ops, drv2667_suspend, drv2667_resume);
+1 -4
drivers/input/misc/ibm-panel.c
··· 77 77 static int ibm_panel_i2c_slave_cb(struct i2c_client *client, 78 78 enum i2c_slave_event event, u8 *val) 79 79 { 80 - unsigned long flags; 81 80 struct ibm_panel *panel = i2c_get_clientdata(client); 82 81 83 82 dev_dbg(&panel->input->dev, "event: %u data: %02x\n", event, *val); 84 83 85 - spin_lock_irqsave(&panel->lock, flags); 84 + guard(spinlock_irqsave)(&panel->lock); 86 85 87 86 switch (event) { 88 87 case I2C_SLAVE_STOP: ··· 112 113 default: 113 114 break; 114 115 } 115 - 116 - spin_unlock_irqrestore(&panel->lock, flags); 117 116 118 117 return 0; 119 118 }
+7 -19
drivers/input/misc/ideapad_slidebar.c
··· 23 23 * 24 24 * The value is in byte range, however, I only figured out 25 25 * how bits 0b10011001 work. Some other bits, probably, 26 - * are meaningfull too. 26 + * are meaningful too. 27 27 * 28 28 * Possible states: 29 29 * ··· 95 95 96 96 static u8 slidebar_pos_get(void) 97 97 { 98 - u8 res; 99 - unsigned long flags; 98 + guard(spinlock_irqsave)(&io_lock); 100 99 101 - spin_lock_irqsave(&io_lock, flags); 102 100 outb(0xf4, 0xff29); 103 101 outb(0xbf, 0xff2a); 104 - res = inb(0xff2b); 105 - spin_unlock_irqrestore(&io_lock, flags); 106 - 107 - return res; 102 + return inb(0xff2b); 108 103 } 109 104 110 105 static u8 slidebar_mode_get(void) 111 106 { 112 - u8 res; 113 - unsigned long flags; 107 + guard(spinlock_irqsave)(&io_lock); 114 108 115 - spin_lock_irqsave(&io_lock, flags); 116 109 outb(0xf7, 0xff29); 117 110 outb(0x8b, 0xff2a); 118 - res = inb(0xff2b); 119 - spin_unlock_irqrestore(&io_lock, flags); 120 - 121 - return res; 111 + return inb(0xff2b); 122 112 } 123 113 124 114 static void slidebar_mode_set(u8 mode) 125 115 { 126 - unsigned long flags; 116 + guard(spinlock_irqsave)(&io_lock); 127 117 128 - spin_lock_irqsave(&io_lock, flags); 129 118 outb(0xf7, 0xff29); 130 119 outb(0x8b, 0xff2a); 131 120 outb(mode, 0xff2b); 132 - spin_unlock_irqrestore(&io_lock, flags); 133 121 } 134 122 135 123 static bool slidebar_i8042_filter(unsigned char data, unsigned char str, ··· 255 267 .driver = { 256 268 .name = "ideapad_slidebar", 257 269 }, 258 - .remove_new = ideapad_remove, 270 + .remove = ideapad_remove, 259 271 }; 260 272 261 273 static int __init ideapad_dmi_check(const struct dmi_system_id *id)
+1 -1
drivers/input/misc/ims-pcu.c
··· 739 739 { 740 740 int error; 741 741 742 - /* Execute jump to the bootoloader */ 742 + /* Execute jump to the bootloader */ 743 743 error = ims_pcu_execute_command(pcu, JUMP_TO_BTLDR, NULL, 0); 744 744 if (error) { 745 745 dev_err(pcu->dev,
+19 -36
drivers/input/misc/iqs269a.c
··· 365 365 if (mode > IQS269_CHx_ENG_A_ATI_MODE_MAX) 366 366 return -EINVAL; 367 367 368 - mutex_lock(&iqs269->lock); 368 + guard(mutex)(&iqs269->lock); 369 369 370 370 engine_a = be16_to_cpu(ch_reg[ch_num].engine_a); 371 371 ··· 374 374 375 375 ch_reg[ch_num].engine_a = cpu_to_be16(engine_a); 376 376 iqs269->ati_current = false; 377 - 378 - mutex_unlock(&iqs269->lock); 379 377 380 378 return 0; 381 379 } ··· 387 389 if (ch_num >= IQS269_NUM_CH) 388 390 return -EINVAL; 389 391 390 - mutex_lock(&iqs269->lock); 392 + guard(mutex)(&iqs269->lock); 393 + 391 394 engine_a = be16_to_cpu(ch_reg[ch_num].engine_a); 392 - mutex_unlock(&iqs269->lock); 393 395 394 396 engine_a &= IQS269_CHx_ENG_A_ATI_MODE_MASK; 395 397 *mode = (engine_a >> IQS269_CHx_ENG_A_ATI_MODE_SHIFT); ··· 427 429 return -EINVAL; 428 430 } 429 431 430 - mutex_lock(&iqs269->lock); 432 + guard(mutex)(&iqs269->lock); 431 433 432 434 engine_b = be16_to_cpu(ch_reg[ch_num].engine_b); 433 435 ··· 436 438 437 439 ch_reg[ch_num].engine_b = cpu_to_be16(engine_b); 438 440 iqs269->ati_current = false; 439 - 440 - mutex_unlock(&iqs269->lock); 441 441 442 442 return 0; 443 443 } ··· 449 453 if (ch_num >= IQS269_NUM_CH) 450 454 return -EINVAL; 451 455 452 - mutex_lock(&iqs269->lock); 456 + guard(mutex)(&iqs269->lock); 457 + 453 458 engine_b = be16_to_cpu(ch_reg[ch_num].engine_b); 454 - mutex_unlock(&iqs269->lock); 455 459 456 460 switch (engine_b & IQS269_CHx_ENG_B_ATI_BASE_MASK) { 457 461 case IQS269_CHx_ENG_B_ATI_BASE_75: ··· 487 491 if (target > IQS269_CHx_ENG_B_ATI_TARGET_MAX) 488 492 return -EINVAL; 489 493 490 - mutex_lock(&iqs269->lock); 494 + guard(mutex)(&iqs269->lock); 491 495 492 496 engine_b = be16_to_cpu(ch_reg[ch_num].engine_b); 493 497 ··· 496 500 497 501 ch_reg[ch_num].engine_b = cpu_to_be16(engine_b); 498 502 iqs269->ati_current = false; 499 - 500 - mutex_unlock(&iqs269->lock); 501 503 502 504 return 0; 503 505 } ··· 509 515 if (ch_num >= IQS269_NUM_CH) 510 516 return -EINVAL; 511 517 512 - mutex_lock(&iqs269->lock); 513 - engine_b = be16_to_cpu(ch_reg[ch_num].engine_b); 514 - mutex_unlock(&iqs269->lock); 518 + guard(mutex)(&iqs269->lock); 515 519 520 + engine_b = be16_to_cpu(ch_reg[ch_num].engine_b); 516 521 *target = (engine_b & IQS269_CHx_ENG_B_ATI_TARGET_MASK) * 32; 517 522 518 523 return 0; ··· 550 557 const struct fwnode_handle *ch_node) 551 558 { 552 559 struct i2c_client *client = iqs269->client; 553 - struct fwnode_handle *ev_node; 554 560 struct iqs269_ch_reg *ch_reg; 555 561 u16 engine_a, engine_b; 556 562 unsigned int reg, val; ··· 726 734 } 727 735 728 736 for (i = 0; i < ARRAY_SIZE(iqs269_events); i++) { 729 - ev_node = fwnode_get_named_child_node(ch_node, 730 - iqs269_events[i].name); 737 + struct fwnode_handle *ev_node __free(fwnode_handle) = 738 + fwnode_get_named_child_node(ch_node, 739 + iqs269_events[i].name); 731 740 if (!ev_node) 732 741 continue; 733 742 ··· 737 744 dev_err(&client->dev, 738 745 "Invalid channel %u threshold: %u\n", 739 746 reg, val); 740 - fwnode_handle_put(ev_node); 741 747 return -EINVAL; 742 748 } 743 749 ··· 750 758 dev_err(&client->dev, 751 759 "Invalid channel %u hysteresis: %u\n", 752 760 reg, val); 753 - fwnode_handle_put(ev_node); 754 761 return -EINVAL; 755 762 } 756 763 ··· 765 774 } 766 775 767 776 error = fwnode_property_read_u32(ev_node, "linux,code", &val); 768 - fwnode_handle_put(ev_node); 769 777 if (error == -EINVAL) { 770 778 continue; 771 779 } else if (error) { ··· 1189 1199 { 1190 1200 int error; 1191 1201 1192 - mutex_lock(&iqs269->lock); 1202 + guard(mutex)(&iqs269->lock); 1193 1203 1194 1204 /* 1195 1205 * Early revisions of silicon require the following workaround in order ··· 1200 1210 error = regmap_multi_reg_write(iqs269->regmap, iqs269_tws_init, 1201 1211 ARRAY_SIZE(iqs269_tws_init)); 1202 1212 if (error) 1203 - goto err_mutex; 1213 + return error; 1204 1214 } 1205 1215 1206 1216 error = regmap_update_bits(iqs269->regmap, IQS269_HALL_UI, 1207 1217 IQS269_HALL_UI_ENABLE, 1208 1218 iqs269->hall_enable ? ~0 : 0); 1209 1219 if (error) 1210 - goto err_mutex; 1220 + return error; 1211 1221 1212 1222 error = regmap_raw_write(iqs269->regmap, IQS269_SYS_SETTINGS, 1213 1223 &iqs269->sys_reg, sizeof(iqs269->sys_reg)); 1214 1224 if (error) 1215 - goto err_mutex; 1225 + return error; 1216 1226 1217 1227 /* 1218 1228 * The following delay gives the device time to deassert its RDY output ··· 1222 1232 1223 1233 iqs269->ati_current = true; 1224 1234 1225 - err_mutex: 1226 - mutex_unlock(&iqs269->lock); 1227 - 1228 - return error; 1235 + return 0; 1229 1236 } 1230 1237 1231 1238 static int iqs269_input_init(struct iqs269_private *iqs269) ··· 1567 1580 if (error) 1568 1581 return error; 1569 1582 1570 - mutex_lock(&iqs269->lock); 1583 + guard(mutex)(&iqs269->lock); 1571 1584 1572 1585 iqs269->hall_enable = val; 1573 1586 iqs269->ati_current = false; 1574 - 1575 - mutex_unlock(&iqs269->lock); 1576 1587 1577 1588 return count; 1578 1589 } ··· 1628 1643 if (val > 0xFF) 1629 1644 return -EINVAL; 1630 1645 1631 - mutex_lock(&iqs269->lock); 1646 + guard(mutex)(&iqs269->lock); 1632 1647 1633 1648 ch_reg[iqs269->ch_num].rx_enable = val; 1634 1649 iqs269->ati_current = false; 1635 - 1636 - mutex_unlock(&iqs269->lock); 1637 1650 1638 1651 return count; 1639 1652 }
+6 -16
drivers/input/misc/iqs626a.c
··· 462 462 { 463 463 struct iqs626_sys_reg *sys_reg = &iqs626->sys_reg; 464 464 struct i2c_client *client = iqs626->client; 465 - struct fwnode_handle *ev_node; 466 465 const char *ev_name; 467 466 u8 *thresh, *hyst; 468 467 unsigned int val; ··· 500 501 if (!iqs626_channels[ch_id].events[i]) 501 502 continue; 502 503 504 + struct fwnode_handle *ev_node __free(fwnode_handle) = NULL; 503 505 if (ch_id == IQS626_CH_TP_2 || ch_id == IQS626_CH_TP_3) { 504 506 /* 505 507 * Trackpad touch events are simply described under the ··· 530 530 dev_err(&client->dev, 531 531 "Invalid input type: %u\n", 532 532 val); 533 - fwnode_handle_put(ev_node); 534 533 return -EINVAL; 535 534 } 536 535 ··· 544 545 dev_err(&client->dev, 545 546 "Invalid %s channel hysteresis: %u\n", 546 547 fwnode_get_name(ch_node), val); 547 - fwnode_handle_put(ev_node); 548 548 return -EINVAL; 549 549 } 550 550 ··· 564 566 dev_err(&client->dev, 565 567 "Invalid %s channel threshold: %u\n", 566 568 fwnode_get_name(ch_node), val); 567 - fwnode_handle_put(ev_node); 568 569 return -EINVAL; 569 570 } 570 571 ··· 572 575 else 573 576 *(thresh + iqs626_events[i].th_offs) = val; 574 577 } 575 - 576 - fwnode_handle_put(ev_node); 577 578 } 578 579 579 580 return 0; ··· 769 774 for (i = 0; i < iqs626_channels[ch_id].num_ch; i++) { 770 775 u8 *ati_base = &sys_reg->tp_grp_reg.ch_reg_tp[i].ati_base; 771 776 u8 *thresh = &sys_reg->tp_grp_reg.ch_reg_tp[i].thresh; 772 - struct fwnode_handle *tc_node; 773 777 char tc_name[10]; 774 778 775 779 snprintf(tc_name, sizeof(tc_name), "channel-%d", i); 776 780 777 - tc_node = fwnode_get_named_child_node(ch_node, tc_name); 781 + struct fwnode_handle *tc_node __free(fwnode_handle) = 782 + fwnode_get_named_child_node(ch_node, tc_name); 778 783 if (!tc_node) 779 784 continue; 780 785 ··· 785 790 dev_err(&client->dev, 786 791 "Invalid %s %s ATI base: %u\n", 787 792 fwnode_get_name(ch_node), tc_name, val); 788 - fwnode_handle_put(tc_node); 789 793 return -EINVAL; 790 794 } 791 795 ··· 797 803 dev_err(&client->dev, 798 804 "Invalid %s %s threshold: %u\n", 799 805 fwnode_get_name(ch_node), tc_name, val); 800 - fwnode_handle_put(tc_node); 801 806 return -EINVAL; 802 807 } 803 808 804 809 *thresh = val; 805 810 } 806 - 807 - fwnode_handle_put(tc_node); 808 811 } 809 812 810 813 if (!fwnode_property_present(ch_node, "linux,keycodes")) ··· 1224 1233 { 1225 1234 struct iqs626_sys_reg *sys_reg = &iqs626->sys_reg; 1226 1235 struct i2c_client *client = iqs626->client; 1227 - struct fwnode_handle *ch_node; 1228 1236 unsigned int val; 1229 1237 int error, i; 1230 1238 u16 general; ··· 1365 1375 sys_reg->active = 0; 1366 1376 1367 1377 for (i = 0; i < ARRAY_SIZE(iqs626_channels); i++) { 1368 - ch_node = device_get_named_child_node(&client->dev, 1369 - iqs626_channels[i].name); 1378 + struct fwnode_handle *ch_node __free(fwnode_handle) = 1379 + device_get_named_child_node(&client->dev, 1380 + iqs626_channels[i].name); 1370 1381 if (!ch_node) 1371 1382 continue; 1372 1383 1373 1384 error = iqs626_parse_channel(iqs626, ch_node, i); 1374 - fwnode_handle_put(ch_node); 1375 1385 if (error) 1376 1386 return error; 1377 1387
+14 -16
drivers/input/misc/iqs7222.c
··· 2385 2385 for (i = 0; i < ARRAY_SIZE(iqs7222_kp_events); i++) { 2386 2386 const char *event_name = iqs7222_kp_events[i].name; 2387 2387 u16 event_enable = iqs7222_kp_events[i].enable; 2388 - struct fwnode_handle *event_node; 2389 2388 2390 - event_node = fwnode_get_named_child_node(chan_node, event_name); 2389 + struct fwnode_handle *event_node __free(fwnode_handle) = 2390 + fwnode_get_named_child_node(chan_node, event_name); 2391 2391 if (!event_node) 2392 2392 continue; 2393 2393 ··· 2408 2408 dev_err(&client->dev, 2409 2409 "Invalid %s press timeout: %u\n", 2410 2410 fwnode_get_name(event_node), val); 2411 - fwnode_handle_put(event_node); 2412 2411 return -EINVAL; 2413 2412 } 2414 2413 ··· 2417 2418 dev_err(&client->dev, 2418 2419 "Failed to read %s press timeout: %d\n", 2419 2420 fwnode_get_name(event_node), error); 2420 - fwnode_handle_put(event_node); 2421 2421 return error; 2422 2422 } 2423 2423 ··· 2427 2429 dev_desc->touch_link - (i ? 0 : 2), 2428 2430 &iqs7222->kp_type[chan_index][i], 2429 2431 &iqs7222->kp_code[chan_index][i]); 2430 - fwnode_handle_put(event_node); 2431 2432 if (error) 2432 2433 return error; 2433 2434 ··· 2601 2604 2602 2605 for (i = 0; i < ARRAY_SIZE(iqs7222_sl_events); i++) { 2603 2606 const char *event_name = iqs7222_sl_events[i].name; 2604 - struct fwnode_handle *event_node; 2605 2607 enum iqs7222_reg_key_id reg_key; 2606 2608 2607 - event_node = fwnode_get_named_child_node(sldr_node, event_name); 2609 + struct fwnode_handle *event_node __free(fwnode_handle) = 2610 + fwnode_get_named_child_node(sldr_node, event_name); 2608 2611 if (!event_node) 2609 2612 continue; 2610 2613 ··· 2636 2639 : sldr_setup[4 + reg_offset], 2637 2640 NULL, 2638 2641 &iqs7222->sl_code[sldr_index][i]); 2639 - fwnode_handle_put(event_node); 2640 2642 if (error) 2641 2643 return error; 2642 2644 ··· 2738 2742 2739 2743 for (i = 0; i < ARRAY_SIZE(iqs7222_tp_events); i++) { 2740 2744 const char *event_name = iqs7222_tp_events[i].name; 2741 - struct fwnode_handle *event_node; 2742 2745 2743 - event_node = fwnode_get_named_child_node(tpad_node, event_name); 2746 + struct fwnode_handle *event_node __free(fwnode_handle) = 2747 + fwnode_get_named_child_node(tpad_node, event_name); 2744 2748 if (!event_node) 2745 2749 continue; 2746 2750 ··· 2756 2760 iqs7222_tp_events[i].link, 1566, 2757 2761 NULL, 2758 2762 &iqs7222->tp_code[i]); 2759 - fwnode_handle_put(event_node); 2760 2763 if (error) 2761 2764 return error; 2762 2765 ··· 2813 2818 int reg_grp_index) 2814 2819 { 2815 2820 struct i2c_client *client = iqs7222->client; 2816 - struct fwnode_handle *reg_grp_node; 2817 2821 int error; 2818 2822 2823 + struct fwnode_handle *reg_grp_node __free(fwnode_handle) = NULL; 2819 2824 if (iqs7222_reg_grp_names[reg_grp]) { 2820 2825 char reg_grp_name[16]; 2821 2826 ··· 2833 2838 2834 2839 error = iqs7222_parse_props(iqs7222, reg_grp_node, reg_grp_index, 2835 2840 reg_grp, IQS7222_REG_KEY_NONE); 2841 + if (error) 2842 + return error; 2836 2843 2837 - if (!error && iqs7222_parse_extra[reg_grp]) 2844 + if (iqs7222_parse_extra[reg_grp]) { 2838 2845 error = iqs7222_parse_extra[reg_grp](iqs7222, reg_grp_node, 2839 2846 reg_grp_index); 2847 + if (error) 2848 + return error; 2849 + } 2840 2850 2841 - fwnode_handle_put(reg_grp_node); 2842 - 2843 - return error; 2851 + return 0; 2844 2852 } 2845 2853 2846 2854 static int iqs7222_parse_all(struct iqs7222_private *iqs7222)
+5 -11
drivers/input/misc/kxtj9.c
··· 25 25 /* CONTROL REGISTER 1 BITS */ 26 26 #define PC1_OFF 0x7F 27 27 #define PC1_ON (1 << 7) 28 - /* Data ready funtion enable bit: set during probe if using irq mode */ 28 + /* Data ready function enable bit: set during probe if using irq mode */ 29 29 #define DRDYE (1 << 5) 30 30 /* DATA CONTROL REGISTER BITS */ 31 31 #define ODR12_5F 0 ··· 314 314 return error; 315 315 316 316 /* Lock the device to prevent races with open/close (and itself) */ 317 - mutex_lock(&input_dev->mutex); 318 - 319 - disable_irq(client->irq); 317 + guard(mutex)(&input_dev->mutex); 318 + guard(disable_irq)(&client->irq); 320 319 321 320 /* 322 321 * Set current interval to the greater of the minimum interval or ··· 324 325 tj9->last_poll_interval = max(interval, tj9->pdata.min_interval); 325 326 326 327 kxtj9_update_odr(tj9, tj9->last_poll_interval); 327 - 328 - enable_irq(client->irq); 329 - mutex_unlock(&input_dev->mutex); 330 328 331 329 return count; 332 330 } ··· 500 504 struct kxtj9_data *tj9 = i2c_get_clientdata(client); 501 505 struct input_dev *input_dev = tj9->input_dev; 502 506 503 - mutex_lock(&input_dev->mutex); 507 + guard(mutex)(&input_dev->mutex); 504 508 505 509 if (input_device_enabled(input_dev)) 506 510 kxtj9_disable(tj9); 507 511 508 - mutex_unlock(&input_dev->mutex); 509 512 return 0; 510 513 } 511 514 ··· 514 519 struct kxtj9_data *tj9 = i2c_get_clientdata(client); 515 520 struct input_dev *input_dev = tj9->input_dev; 516 521 517 - mutex_lock(&input_dev->mutex); 522 + guard(mutex)(&input_dev->mutex); 518 523 519 524 if (input_device_enabled(input_dev)) 520 525 kxtj9_enable(tj9); 521 526 522 - mutex_unlock(&input_dev->mutex); 523 527 return 0; 524 528 } 525 529
+1 -1
drivers/input/misc/m68kspkr.c
··· 95 95 .name = "m68kspkr", 96 96 }, 97 97 .probe = m68kspkr_probe, 98 - .remove_new = m68kspkr_remove, 98 + .remove = m68kspkr_remove, 99 99 .shutdown = m68kspkr_shutdown, 100 100 }; 101 101
+6 -11
drivers/input/misc/max8997_haptic.c
··· 153 153 { 154 154 int error; 155 155 156 - mutex_lock(&chip->mutex); 156 + guard(mutex)(&chip->mutex); 157 157 158 158 error = max8997_haptic_set_duty_cycle(chip); 159 159 if (error) { 160 160 dev_err(chip->dev, "set_pwm_cycle failed, error: %d\n", error); 161 - goto out; 161 + return; 162 162 } 163 163 164 164 if (!chip->enabled) { 165 165 error = regulator_enable(chip->regulator); 166 166 if (error) { 167 167 dev_err(chip->dev, "Failed to enable regulator\n"); 168 - goto out; 168 + return; 169 169 } 170 170 max8997_haptic_configure(chip); 171 171 if (chip->mode == MAX8997_EXTERNAL_MODE) { ··· 173 173 if (error) { 174 174 dev_err(chip->dev, "Failed to enable PWM\n"); 175 175 regulator_disable(chip->regulator); 176 - goto out; 176 + return; 177 177 } 178 178 } 179 179 chip->enabled = true; 180 180 } 181 - 182 - out: 183 - mutex_unlock(&chip->mutex); 184 181 } 185 182 186 183 static void max8997_haptic_disable(struct max8997_haptic *chip) 187 184 { 188 - mutex_lock(&chip->mutex); 185 + guard(mutex)(&chip->mutex); 189 186 190 187 if (chip->enabled) { 191 188 chip->enabled = false; ··· 191 194 pwm_disable(chip->pwm); 192 195 regulator_disable(chip->regulator); 193 196 } 194 - 195 - mutex_unlock(&chip->mutex); 196 197 } 197 198 198 199 static void max8997_haptic_play_effect_work(struct work_struct *work) ··· 384 389 .pm = pm_sleep_ptr(&max8997_haptic_pm_ops), 385 390 }, 386 391 .probe = max8997_haptic_probe, 387 - .remove_new = max8997_haptic_remove, 392 + .remove = max8997_haptic_remove, 388 393 .id_table = max8997_haptic_id, 389 394 }; 390 395 module_platform_driver(max8997_haptic_driver);
+1 -1
drivers/input/misc/mc13783-pwrbutton.c
··· 253 253 254 254 static struct platform_driver mc13783_pwrbutton_driver = { 255 255 .probe = mc13783_pwrbutton_probe, 256 - .remove_new = mc13783_pwrbutton_remove, 256 + .remove = mc13783_pwrbutton_remove, 257 257 .driver = { 258 258 .name = "mc13783-pwrbutton", 259 259 },
+1 -1
drivers/input/misc/palmas-pwrbutton.c
··· 310 310 311 311 static struct platform_driver palmas_pwron_driver = { 312 312 .probe = palmas_pwron_probe, 313 - .remove_new = palmas_pwron_remove, 313 + .remove = palmas_pwron_remove, 314 314 .driver = { 315 315 .name = "palmas_pwrbutton", 316 316 .of_match_table = of_match_ptr(of_palmas_pwr_match),
+1 -1
drivers/input/misc/pcap_keys.c
··· 112 112 113 113 static struct platform_driver pcap_keys_device_driver = { 114 114 .probe = pcap_keys_probe, 115 - .remove_new = pcap_keys_remove, 115 + .remove = pcap_keys_remove, 116 116 .driver = { 117 117 .name = "pcap-keys", 118 118 }
+1 -1
drivers/input/misc/pcf50633-input.c
··· 103 103 .name = "pcf50633-input", 104 104 }, 105 105 .probe = pcf50633_input_probe, 106 - .remove_new = pcf50633_input_remove, 106 + .remove = pcf50633_input_remove, 107 107 }; 108 108 module_platform_driver(pcf50633_input_driver); 109 109
+1 -1
drivers/input/misc/pcspkr.c
··· 127 127 .pm = &pcspkr_pm_ops, 128 128 }, 129 129 .probe = pcspkr_probe, 130 - .remove_new = pcspkr_remove, 130 + .remove = pcspkr_remove, 131 131 .shutdown = pcspkr_shutdown, 132 132 }; 133 133 module_platform_driver(pcspkr_platform_driver);
+1 -1
drivers/input/misc/pm8941-pwrkey.c
··· 465 465 466 466 static struct platform_driver pm8941_pwrkey_driver = { 467 467 .probe = pm8941_pwrkey_probe, 468 - .remove_new = pm8941_pwrkey_remove, 468 + .remove = pm8941_pwrkey_remove, 469 469 .driver = { 470 470 .name = "pm8941-pwrkey", 471 471 .pm = pm_sleep_ptr(&pm8941_pwr_key_pm_ops),
+2 -9
drivers/input/misc/powermate.c
··· 194 194 static void powermate_config_complete(struct urb *urb) 195 195 { 196 196 struct powermate_device *pm = urb->context; 197 - unsigned long flags; 198 197 199 198 if (urb->status) 200 199 printk(KERN_ERR "powermate: config urb returned %d\n", urb->status); 201 200 202 - spin_lock_irqsave(&pm->lock, flags); 201 + guard(spinlock_irqsave)(&pm->lock); 203 202 powermate_sync_state(pm); 204 - spin_unlock_irqrestore(&pm->lock, flags); 205 203 } 206 204 207 205 /* Set the LED up as described and begin the sync with the hardware if required */ 208 206 static void powermate_pulse_led(struct powermate_device *pm, int static_brightness, int pulse_speed, 209 207 int pulse_table, int pulse_asleep, int pulse_awake) 210 208 { 211 - unsigned long flags; 212 - 213 209 if (pulse_speed < 0) 214 210 pulse_speed = 0; 215 211 if (pulse_table < 0) ··· 218 222 pulse_asleep = !!pulse_asleep; 219 223 pulse_awake = !!pulse_awake; 220 224 221 - 222 - spin_lock_irqsave(&pm->lock, flags); 225 + guard(spinlock_irqsave)(&pm->lock); 223 226 224 227 /* mark state updates which are required */ 225 228 if (static_brightness != pm->static_brightness) { ··· 240 245 } 241 246 242 247 powermate_sync_state(pm); 243 - 244 - spin_unlock_irqrestore(&pm->lock, flags); 245 248 } 246 249 247 250 /* Callback from the Input layer when an event arrives from userspace to configure the LED */
+6 -6
drivers/input/misc/pwm-beeper.c
··· 203 203 * beeper->suspended, but to ensure that pwm_beeper_event 204 204 * does not re-submit work once flag is set. 205 205 */ 206 - spin_lock_irq(&beeper->input->event_lock); 207 - beeper->suspended = true; 208 - spin_unlock_irq(&beeper->input->event_lock); 206 + scoped_guard(spinlock_irq, &beeper->input->event_lock) { 207 + beeper->suspended = true; 208 + } 209 209 210 210 pwm_beeper_stop(beeper); 211 211 ··· 216 216 { 217 217 struct pwm_beeper *beeper = dev_get_drvdata(dev); 218 218 219 - spin_lock_irq(&beeper->input->event_lock); 220 - beeper->suspended = false; 221 - spin_unlock_irq(&beeper->input->event_lock); 219 + scoped_guard(spinlock_irq, &beeper->input->event_lock) { 220 + beeper->suspended = false; 221 + } 222 222 223 223 /* Let worker figure out if we should resume beeping */ 224 224 schedule_work(&beeper->work);
+8 -16
drivers/input/misc/regulator-haptic.c
··· 83 83 struct regulator_haptic *haptic = container_of(work, 84 84 struct regulator_haptic, work); 85 85 86 - mutex_lock(&haptic->mutex); 86 + guard(mutex)(&haptic->mutex); 87 87 88 88 if (!haptic->suspended) 89 89 regulator_haptic_set_voltage(haptic, haptic->magnitude); 90 - 91 - mutex_unlock(&haptic->mutex); 92 90 } 93 91 94 92 static int regulator_haptic_play_effect(struct input_dev *input, void *data, ··· 203 205 { 204 206 struct platform_device *pdev = to_platform_device(dev); 205 207 struct regulator_haptic *haptic = platform_get_drvdata(pdev); 206 - int error; 207 208 208 - error = mutex_lock_interruptible(&haptic->mutex); 209 - if (error) 210 - return error; 209 + scoped_guard(mutex_intr, &haptic->mutex) { 210 + regulator_haptic_set_voltage(haptic, 0); 211 + haptic->suspended = true; 211 212 212 - regulator_haptic_set_voltage(haptic, 0); 213 + return 0; 214 + } 213 215 214 - haptic->suspended = true; 215 - 216 - mutex_unlock(&haptic->mutex); 217 - 218 - return 0; 216 + return -EINTR; 219 217 } 220 218 221 219 static int regulator_haptic_resume(struct device *dev) ··· 220 226 struct regulator_haptic *haptic = platform_get_drvdata(pdev); 221 227 unsigned int magnitude; 222 228 223 - mutex_lock(&haptic->mutex); 229 + guard(mutex)(&haptic->mutex); 224 230 225 231 haptic->suspended = false; 226 232 227 233 magnitude = READ_ONCE(haptic->magnitude); 228 234 if (magnitude) 229 235 regulator_haptic_set_voltage(haptic, magnitude); 230 - 231 - mutex_unlock(&haptic->mutex); 232 236 233 237 return 0; 234 238 }
+8 -15
drivers/input/misc/rotary_encoder.c
··· 106 106 struct rotary_encoder *encoder = dev_id; 107 107 unsigned int state; 108 108 109 - mutex_lock(&encoder->access_mutex); 109 + guard(mutex)(&encoder->access_mutex); 110 110 111 111 state = rotary_encoder_get_state(encoder); 112 112 ··· 129 129 break; 130 130 } 131 131 132 - mutex_unlock(&encoder->access_mutex); 133 - 134 132 return IRQ_HANDLED; 135 133 } 136 134 ··· 137 139 struct rotary_encoder *encoder = dev_id; 138 140 unsigned int state; 139 141 140 - mutex_lock(&encoder->access_mutex); 142 + guard(mutex)(&encoder->access_mutex); 141 143 142 144 state = rotary_encoder_get_state(encoder); 143 145 ··· 150 152 } 151 153 } 152 154 153 - mutex_unlock(&encoder->access_mutex); 154 - 155 155 return IRQ_HANDLED; 156 156 } 157 157 ··· 158 162 struct rotary_encoder *encoder = dev_id; 159 163 unsigned int state; 160 164 161 - mutex_lock(&encoder->access_mutex); 165 + guard(mutex)(&encoder->access_mutex); 162 166 163 167 state = rotary_encoder_get_state(encoder); 164 168 165 - if ((encoder->last_stable + 1) % 4 == state) 169 + if ((encoder->last_stable + 1) % 4 == state) { 166 170 encoder->dir = 1; 167 - else if (encoder->last_stable == (state + 1) % 4) 171 + rotary_encoder_report_event(encoder); 172 + } else if (encoder->last_stable == (state + 1) % 4) { 168 173 encoder->dir = -1; 169 - else 170 - goto out; 174 + rotary_encoder_report_event(encoder); 175 + } 171 176 172 - rotary_encoder_report_event(encoder); 173 - 174 - out: 175 177 encoder->last_stable = state; 176 - mutex_unlock(&encoder->access_mutex); 177 178 178 179 return IRQ_HANDLED; 179 180 }
+2 -2
drivers/input/misc/soc_button_array.c
··· 515 515 }; 516 516 517 517 /* 518 - * Button info for Microsoft Surface 3 (non pro), this is indentical to 518 + * Button info for Microsoft Surface 3 (non pro), this is identical to 519 519 * the PNP0C40 info except that the home button is active-high. 520 520 * 521 521 * The Surface 3 Pro also has a MSHW0028 ACPI device, but that uses a custom ··· 612 612 613 613 static struct platform_driver soc_button_driver = { 614 614 .probe = soc_button_probe, 615 - .remove_new = soc_button_remove, 615 + .remove = soc_button_remove, 616 616 .driver = { 617 617 .name = KBUILD_MODNAME, 618 618 .acpi_match_table = ACPI_PTR(soc_button_acpi_match),
+19 -40
drivers/input/misc/sparcspkr.c
··· 69 69 struct sparcspkr_state *state = dev_get_drvdata(dev->dev.parent); 70 70 struct bbc_beep_info *info = &state->u.bbc; 71 71 unsigned int count = 0; 72 - unsigned long flags; 73 72 74 73 if (type != EV_SND) 75 74 return -1; ··· 84 85 85 86 count = bbc_count_to_reg(info, count); 86 87 87 - spin_lock_irqsave(&state->lock, flags); 88 + guard(spinlock_irqsave)(&state->lock); 88 89 89 90 if (count) { 90 91 sbus_writeb(0x01, info->regs + 0); ··· 96 97 sbus_writeb(0x00, info->regs + 0); 97 98 } 98 99 99 - spin_unlock_irqrestore(&state->lock, flags); 100 - 101 100 return 0; 102 101 } 103 102 ··· 104 107 struct sparcspkr_state *state = dev_get_drvdata(dev->dev.parent); 105 108 struct grover_beep_info *info = &state->u.grover; 106 109 unsigned int count = 0; 107 - unsigned long flags; 108 110 109 111 if (type != EV_SND) 110 112 return -1; ··· 117 121 if (value > 20 && value < 32767) 118 122 count = 1193182 / value; 119 123 120 - spin_lock_irqsave(&state->lock, flags); 124 + guard(spinlock_irqsave)(&state->lock); 121 125 122 126 if (count) { 123 127 /* enable counter 2 */ ··· 131 135 /* disable counter 2 */ 132 136 sbus_writeb(sbus_readb(info->enable_reg) & 0xFC, info->enable_reg); 133 137 } 134 - 135 - spin_unlock_irqrestore(&state->lock, flags); 136 138 137 139 return 0; 138 140 } ··· 182 188 { 183 189 struct sparcspkr_state *state; 184 190 struct bbc_beep_info *info; 185 - struct device_node *dp; 186 - int err = -ENOMEM; 191 + int err; 187 192 188 - state = kzalloc(sizeof(*state), GFP_KERNEL); 193 + state = devm_kzalloc(&op->dev, sizeof(*state), GFP_KERNEL); 189 194 if (!state) 190 - goto out_err; 195 + return -ENOMEM; 191 196 192 197 state->name = "Sparc BBC Speaker"; 193 198 state->event = bbc_spkr_event; 194 199 spin_lock_init(&state->lock); 195 200 196 - dp = of_find_node_by_path("/"); 197 - err = -ENODEV; 201 + struct device_node *dp __free(device_node) = of_find_node_by_path("/"); 198 202 if (!dp) 199 - goto out_free; 203 + return -ENODEV; 200 204 201 205 info = &state->u.bbc; 202 206 info->clock_freq = of_getintprop_default(dp, "clock-frequency", 0); 203 - of_node_put(dp); 204 207 if (!info->clock_freq) 205 - goto out_free; 208 + return -ENODEV; 206 209 207 210 info->regs = of_ioremap(&op->resource[0], 0, 6, "bbc beep"); 208 211 if (!info->regs) 209 - goto out_free; 212 + return -ENODEV; 210 213 211 214 platform_set_drvdata(op, state); 212 215 213 216 err = sparcspkr_probe(&op->dev); 214 - if (err) 215 - goto out_clear_drvdata; 217 + if (err) { 218 + of_iounmap(&op->resource[0], info->regs, 6); 219 + return err; 220 + } 216 221 217 222 return 0; 218 - 219 - out_clear_drvdata: 220 - of_iounmap(&op->resource[0], info->regs, 6); 221 - 222 - out_free: 223 - kfree(state); 224 - out_err: 225 - return err; 226 223 } 227 224 228 225 static void bbc_remove(struct platform_device *op) ··· 228 243 input_unregister_device(input_dev); 229 244 230 245 of_iounmap(&op->resource[0], info->regs, 6); 231 - 232 - kfree(state); 233 246 } 234 247 235 248 static const struct of_device_id bbc_beep_match[] = { ··· 245 262 .of_match_table = bbc_beep_match, 246 263 }, 247 264 .probe = bbc_beep_probe, 248 - .remove_new = bbc_remove, 265 + .remove = bbc_remove, 249 266 .shutdown = sparcspkr_shutdown, 250 267 }; 251 268 ··· 255 272 struct grover_beep_info *info; 256 273 int err = -ENOMEM; 257 274 258 - state = kzalloc(sizeof(*state), GFP_KERNEL); 275 + state = devm_kzalloc(&op->dev, sizeof(*state), GFP_KERNEL); 259 276 if (!state) 260 - goto out_err; 277 + return err; 261 278 262 279 state->name = "Sparc Grover Speaker"; 263 280 state->event = grover_spkr_event; ··· 266 283 info = &state->u.grover; 267 284 info->freq_regs = of_ioremap(&op->resource[2], 0, 2, "grover beep freq"); 268 285 if (!info->freq_regs) 269 - goto out_free; 286 + return err; 270 287 271 288 info->enable_reg = of_ioremap(&op->resource[3], 0, 1, "grover beep enable"); 272 289 if (!info->enable_reg) ··· 285 302 286 303 out_unmap_freq_regs: 287 304 of_iounmap(&op->resource[2], info->freq_regs, 2); 288 - out_free: 289 - kfree(state); 290 - out_err: 305 + 291 306 return err; 292 307 } 293 308 ··· 302 321 303 322 of_iounmap(&op->resource[3], info->enable_reg, 1); 304 323 of_iounmap(&op->resource[2], info->freq_regs, 2); 305 - 306 - kfree(state); 307 324 } 308 325 309 326 static const struct of_device_id grover_beep_match[] = { ··· 319 340 .of_match_table = grover_beep_match, 320 341 }, 321 342 .probe = grover_beep_probe, 322 - .remove_new = grover_remove, 343 + .remove = grover_remove, 323 344 .shutdown = sparcspkr_shutdown, 324 345 }; 325 346
+1 -1
drivers/input/misc/tps65219-pwrbutton.c
··· 137 137 138 138 static struct platform_driver tps65219_pb_driver = { 139 139 .probe = tps65219_pb_probe, 140 - .remove_new = tps65219_pb_remove, 140 + .remove = tps65219_pb_remove, 141 141 .driver = { 142 142 .name = "tps65219_pwrbutton", 143 143 },
+3 -8
drivers/input/misc/twl4030-vibra.c
··· 165 165 166 166 static bool twl4030_vibra_check_coexist(struct device_node *parent) 167 167 { 168 - struct device_node *node; 168 + struct device_node *node __free(device_node) = 169 + of_get_child_by_name(parent, "codec"); 169 170 170 - node = of_get_child_by_name(parent, "codec"); 171 - if (node) { 172 - of_node_put(node); 173 - return true; 174 - } 175 - 176 - return false; 171 + return node != NULL; 177 172 } 178 173 179 174 static int twl4030_vibra_probe(struct platform_device *pdev)
+2 -6
drivers/input/misc/twl6040-vibra.c
··· 229 229 static int twl6040_vibra_probe(struct platform_device *pdev) 230 230 { 231 231 struct device *twl6040_core_dev = pdev->dev.parent; 232 - struct device_node *twl6040_core_node; 233 232 struct vibra_info *info; 234 233 int vddvibl_uV = 0; 235 234 int vddvibr_uV = 0; 236 235 int error; 237 236 238 - twl6040_core_node = of_get_child_by_name(twl6040_core_dev->of_node, 239 - "vibra"); 237 + struct device_node *twl6040_core_node __free(device_node) = 238 + of_get_child_by_name(twl6040_core_dev->of_node, "vibra"); 240 239 if (!twl6040_core_node) { 241 240 dev_err(&pdev->dev, "parent of node is missing?\n"); 242 241 return -EINVAL; ··· 243 244 244 245 info = devm_kzalloc(&pdev->dev, sizeof(*info), GFP_KERNEL); 245 246 if (!info) { 246 - of_node_put(twl6040_core_node); 247 247 dev_err(&pdev->dev, "couldn't allocate memory\n"); 248 248 return -ENOMEM; 249 249 } ··· 261 263 &info->vibrmotor_res); 262 264 of_property_read_u32(twl6040_core_node, "ti,vddvibl-uV", &vddvibl_uV); 263 265 of_property_read_u32(twl6040_core_node, "ti,vddvibr-uV", &vddvibr_uV); 264 - 265 - of_node_put(twl6040_core_node); 266 266 267 267 if ((!info->vibldrv_res && !info->viblmotor_res) || 268 268 (!info->vibrdrv_res && !info->vibrmotor_res)) {
+2 -2
drivers/input/misc/wistron_btns.c
··· 271 271 { KE_BLUETOOTH, 0x30 }, /* Fn+F10 */ 272 272 { KE_KEY, 0x31, {KEY_MAIL} }, /* mail button */ 273 273 { KE_KEY, 0x36, {KEY_WWW} }, /* www button */ 274 - { KE_WIFI, 0x78 }, /* satelite dish button */ 274 + { KE_WIFI, 0x78 }, /* satellite dish button */ 275 275 { KE_END, FE_WIFI_LED } 276 276 }; 277 277 ··· 1334 1334 .pm = pm_sleep_ptr(&wistron_pm_ops), 1335 1335 }, 1336 1336 .probe = wistron_probe, 1337 - .remove_new = wistron_remove, 1337 + .remove = wistron_remove, 1338 1338 }; 1339 1339 1340 1340 static int __init wb_module_init(void)
+1 -1
drivers/input/misc/wm831x-on.c
··· 134 134 135 135 static struct platform_driver wm831x_on_driver = { 136 136 .probe = wm831x_on_probe, 137 - .remove_new = wm831x_on_remove, 137 + .remove = wm831x_on_remove, 138 138 .driver = { 139 139 .name = "wm831x-on", 140 140 },
+2 -2
drivers/input/misc/yealink.c
··· 377 377 if (len > sizeof(yld->ctl_data->data)) 378 378 len = sizeof(yld->ctl_data->data); 379 379 380 - /* Combine up to <len> consecutive LCD bytes in a singe request 380 + /* Combine up to <len> consecutive LCD bytes in a single request 381 381 */ 382 382 yld->ctl_data->cmd = CMD_LCD; 383 383 yld->ctl_data->offset = cpu_to_be16(ix); ··· 614 614 return show_line(dev, buf, LCD_LINE3_OFFSET, LCD_LINE4_OFFSET); 615 615 } 616 616 617 - /* Writing to /sys/../lineX will set the coresponding LCD line. 617 + /* Writing to /sys/../lineX will set the corresponding LCD line. 618 618 * - Excess characters are ignored. 619 619 * - If less characters are written than allowed, the remaining digits are 620 620 * unchanged.
+1 -3
drivers/input/mouse/alps.c
··· 1585 1585 struct alps_data *priv = from_timer(priv, t, timer); 1586 1586 struct psmouse *psmouse = priv->psmouse; 1587 1587 1588 - serio_pause_rx(psmouse->ps2dev.serio); 1588 + guard(serio_pause_rx)(psmouse->ps2dev.serio); 1589 1589 1590 1590 if (psmouse->pktcnt == psmouse->pktsize) { 1591 1591 ··· 1605 1605 } 1606 1606 psmouse->pktcnt = 0; 1607 1607 } 1608 - 1609 - serio_continue_rx(psmouse->ps2dev.serio); 1610 1608 } 1611 1609 1612 1610 static psmouse_ret_t alps_process_byte(struct psmouse *psmouse)
+1 -1
drivers/input/mouse/amimouse.c
··· 139 139 * triggering a section mismatch warning. 140 140 */ 141 141 static struct platform_driver amimouse_driver __refdata = { 142 - .remove_new = __exit_p(amimouse_remove), 142 + .remove = __exit_p(amimouse_remove), 143 143 .driver = { 144 144 .name = "amiga-mouse", 145 145 },
+2 -3
drivers/input/mouse/byd.c
··· 254 254 struct byd_data *priv = from_timer(priv, t, timer); 255 255 struct psmouse *psmouse = priv->psmouse; 256 256 257 - serio_pause_rx(psmouse->ps2dev.serio); 257 + guard(serio_pause_rx)(psmouse->ps2dev.serio); 258 + 258 259 priv->touch = false; 259 260 260 261 byd_report_input(psmouse); 261 - 262 - serio_continue_rx(psmouse->ps2dev.serio); 263 262 264 263 /* 265 264 * Move cursor back to center of pad when we lose touch - this
+116 -112
drivers/input/mouse/elan_i2c_core.c
··· 541 541 542 542 dev_dbg(&client->dev, "Starting firmware update....\n"); 543 543 544 - disable_irq(client->irq); 544 + guard(disable_irq)(&client->irq); 545 + 545 546 data->in_fw_update = true; 546 547 547 548 retval = __elan_update_firmware(data, fw); ··· 556 555 } 557 556 558 557 data->in_fw_update = false; 559 - enable_irq(client->irq); 560 558 561 559 return retval; 562 560 } ··· 621 621 const char *buf, size_t count) 622 622 { 623 623 struct elan_tp_data *data = dev_get_drvdata(dev); 624 - const struct firmware *fw; 625 - char *fw_name; 626 624 int error; 627 625 const u8 *fw_signature; 628 626 static const u8 signature[] = {0xAA, 0x55, 0xCC, 0x33, 0xFF, 0xFF}; ··· 629 631 return -EINVAL; 630 632 631 633 /* Look for a firmware with the product id appended. */ 632 - fw_name = kasprintf(GFP_KERNEL, ETP_FW_NAME, data->product_id); 634 + const char *fw_name __free(kfree) = 635 + kasprintf(GFP_KERNEL, ETP_FW_NAME, data->product_id); 633 636 if (!fw_name) { 634 637 dev_err(dev, "failed to allocate memory for firmware name\n"); 635 638 return -ENOMEM; 636 639 } 637 640 638 641 dev_info(dev, "requesting fw '%s'\n", fw_name); 642 + const struct firmware *fw __free(firmware) = NULL; 639 643 error = request_firmware(&fw, fw_name, dev); 640 - kfree(fw_name); 641 644 if (error) { 642 645 dev_err(dev, "failed to request firmware: %d\n", error); 643 646 return error; ··· 650 651 dev_err(dev, "signature mismatch (expected %*ph, got %*ph)\n", 651 652 (int)sizeof(signature), signature, 652 653 (int)sizeof(signature), fw_signature); 653 - error = -EBADF; 654 - goto out_release_fw; 654 + return -EBADF; 655 655 } 656 656 657 - error = mutex_lock_interruptible(&data->sysfs_mutex); 658 - if (error) 659 - goto out_release_fw; 657 + scoped_cond_guard(mutex_intr, return -EINTR, &data->sysfs_mutex) { 658 + error = elan_update_firmware(data, fw); 659 + if (error) 660 + return error; 661 + } 660 662 661 - error = elan_update_firmware(data, fw); 662 - 663 - mutex_unlock(&data->sysfs_mutex); 664 - 665 - out_release_fw: 666 - release_firmware(fw); 667 - return error ?: count; 663 + return count; 668 664 } 669 665 670 - static ssize_t calibrate_store(struct device *dev, 671 - struct device_attribute *attr, 672 - const char *buf, size_t count) 666 + static int elan_calibrate(struct elan_tp_data *data) 673 667 { 674 - struct i2c_client *client = to_i2c_client(dev); 675 - struct elan_tp_data *data = i2c_get_clientdata(client); 668 + struct i2c_client *client = data->client; 669 + struct device *dev = &client->dev; 676 670 int tries = 20; 677 671 int retval; 678 672 int error; 679 673 u8 val[ETP_CALIBRATE_MAX_LEN]; 680 674 681 - retval = mutex_lock_interruptible(&data->sysfs_mutex); 682 - if (retval) 683 - return retval; 684 - 685 - disable_irq(client->irq); 675 + guard(disable_irq)(&client->irq); 686 676 687 677 data->mode |= ETP_ENABLE_CALIBRATE; 688 678 retval = data->ops->set_mode(client, data->mode); 689 679 if (retval) { 680 + data->mode &= ~ETP_ENABLE_CALIBRATE; 690 681 dev_err(dev, "failed to enable calibration mode: %d\n", 691 682 retval); 692 - goto out; 683 + return retval; 693 684 } 694 685 695 686 retval = data->ops->calibrate(client); ··· 717 728 if (!retval) 718 729 retval = error; 719 730 } 720 - out: 721 - enable_irq(client->irq); 722 - mutex_unlock(&data->sysfs_mutex); 723 - return retval ?: count; 731 + return retval; 732 + } 733 + 734 + static ssize_t calibrate_store(struct device *dev, 735 + struct device_attribute *attr, 736 + const char *buf, size_t count) 737 + { 738 + struct i2c_client *client = to_i2c_client(dev); 739 + struct elan_tp_data *data = i2c_get_clientdata(client); 740 + int error; 741 + 742 + scoped_cond_guard(mutex_intr, return -EINTR, &data->sysfs_mutex) { 743 + error = elan_calibrate(data); 744 + if (error) 745 + return error; 746 + } 747 + 748 + return count; 724 749 } 725 750 726 751 static ssize_t elan_sysfs_read_mode(struct device *dev, ··· 746 743 int error; 747 744 enum tp_mode mode; 748 745 749 - error = mutex_lock_interruptible(&data->sysfs_mutex); 750 - if (error) 751 - return error; 752 - 753 - error = data->ops->iap_get_mode(data->client, &mode); 754 - 755 - mutex_unlock(&data->sysfs_mutex); 756 - 757 - if (error) 758 - return error; 746 + scoped_cond_guard(mutex_intr, return -EINTR, &data->sysfs_mutex) { 747 + error = data->ops->iap_get_mode(data->client, &mode); 748 + if (error) 749 + return error; 750 + } 759 751 760 752 return sysfs_emit(buf, "%d\n", (int)mode); 761 753 } ··· 781 783 .attrs = elan_sysfs_entries, 782 784 }; 783 785 784 - static ssize_t acquire_store(struct device *dev, struct device_attribute *attr, 785 - const char *buf, size_t count) 786 + static int elan_acquire_baseline(struct elan_tp_data *data) 786 787 { 787 - struct i2c_client *client = to_i2c_client(dev); 788 - struct elan_tp_data *data = i2c_get_clientdata(client); 789 - int error; 788 + struct i2c_client *client = data->client; 789 + struct device *dev = &client->dev; 790 790 int retval; 791 + int error; 791 792 792 - retval = mutex_lock_interruptible(&data->sysfs_mutex); 793 - if (retval) 794 - return retval; 795 - 796 - disable_irq(client->irq); 793 + guard(disable_irq)(&client->irq); 797 794 798 795 data->baseline_ready = false; 799 796 800 797 data->mode |= ETP_ENABLE_CALIBRATE; 801 - retval = data->ops->set_mode(data->client, data->mode); 798 + retval = data->ops->set_mode(client, data->mode); 802 799 if (retval) { 800 + data->mode &= ~ETP_ENABLE_CALIBRATE; 803 801 dev_err(dev, "Failed to enable calibration mode to get baseline: %d\n", 804 802 retval); 805 - goto out; 803 + return retval; 806 804 } 807 805 808 806 msleep(250); 809 807 810 - retval = data->ops->get_baseline_data(data->client, true, 808 + retval = data->ops->get_baseline_data(client, true, 811 809 &data->max_baseline); 812 810 if (retval) { 813 - dev_err(dev, "Failed to read max baseline form device: %d\n", 811 + dev_err(dev, "Failed to read max baseline from device: %d\n", 814 812 retval); 815 813 goto out_disable_calibrate; 816 814 } 817 815 818 - retval = data->ops->get_baseline_data(data->client, false, 816 + retval = data->ops->get_baseline_data(client, false, 819 817 &data->min_baseline); 820 818 if (retval) { 821 - dev_err(dev, "Failed to read min baseline form device: %d\n", 819 + dev_err(dev, "Failed to read min baseline from device: %d\n", 822 820 retval); 823 821 goto out_disable_calibrate; 824 822 } ··· 823 829 824 830 out_disable_calibrate: 825 831 data->mode &= ~ETP_ENABLE_CALIBRATE; 826 - error = data->ops->set_mode(data->client, data->mode); 832 + error = data->ops->set_mode(client, data->mode); 827 833 if (error) { 828 834 dev_err(dev, "Failed to disable calibration mode after acquiring baseline: %d\n", 829 835 error); 830 836 if (!retval) 831 837 retval = error; 832 838 } 833 - out: 834 - enable_irq(client->irq); 835 - mutex_unlock(&data->sysfs_mutex); 836 - return retval ?: count; 839 + 840 + return retval; 841 + } 842 + 843 + static ssize_t acquire_store(struct device *dev, struct device_attribute *attr, 844 + const char *buf, size_t count) 845 + { 846 + struct i2c_client *client = to_i2c_client(dev); 847 + struct elan_tp_data *data = i2c_get_clientdata(client); 848 + int error; 849 + 850 + scoped_cond_guard(mutex_intr, return -EINTR, &data->sysfs_mutex) { 851 + error = elan_acquire_baseline(data); 852 + if (error) 853 + return error; 854 + } 855 + 856 + return count; 837 857 } 838 858 839 859 static ssize_t min_show(struct device *dev, ··· 855 847 { 856 848 struct i2c_client *client = to_i2c_client(dev); 857 849 struct elan_tp_data *data = i2c_get_clientdata(client); 858 - int retval; 859 850 860 - retval = mutex_lock_interruptible(&data->sysfs_mutex); 861 - if (retval) 862 - return retval; 851 + scoped_guard(mutex_intr, &data->sysfs_mutex) { 852 + if (!data->baseline_ready) 853 + return -ENODATA; 863 854 864 - if (!data->baseline_ready) { 865 - retval = -ENODATA; 866 - goto out; 855 + return sysfs_emit(buf, "%d", data->min_baseline); 867 856 } 868 857 869 - retval = sysfs_emit(buf, "%d", data->min_baseline); 870 - 871 - out: 872 - mutex_unlock(&data->sysfs_mutex); 873 - return retval; 858 + return -EINTR; 874 859 } 875 860 876 861 static ssize_t max_show(struct device *dev, ··· 871 870 { 872 871 struct i2c_client *client = to_i2c_client(dev); 873 872 struct elan_tp_data *data = i2c_get_clientdata(client); 874 - int retval; 875 873 876 - retval = mutex_lock_interruptible(&data->sysfs_mutex); 877 - if (retval) 878 - return retval; 874 + scoped_guard(mutex_intr, &data->sysfs_mutex) { 875 + if (!data->baseline_ready) 876 + return -ENODATA; 879 877 880 - if (!data->baseline_ready) { 881 - retval = -ENODATA; 882 - goto out; 878 + return sysfs_emit(buf, "%d", data->max_baseline); 883 879 } 884 880 885 - retval = sysfs_emit(buf, "%d", data->max_baseline); 886 - 887 - out: 888 - mutex_unlock(&data->sysfs_mutex); 889 - return retval; 881 + return -EINTR; 890 882 } 891 - 892 883 893 884 static DEVICE_ATTR_WO(acquire); 894 885 static DEVICE_ATTR_RO(min); ··· 1316 1323 return 0; 1317 1324 } 1318 1325 1326 + static int __elan_suspend(struct elan_tp_data *data) 1327 + { 1328 + struct i2c_client *client = data->client; 1329 + int error; 1330 + 1331 + if (device_may_wakeup(&client->dev)) 1332 + return elan_sleep(data); 1333 + 1334 + /* Touchpad is not a wakeup source */ 1335 + error = elan_set_power(data, false); 1336 + if (error) 1337 + return error; 1338 + 1339 + error = regulator_disable(data->vcc); 1340 + if (error) { 1341 + dev_err(&client->dev, 1342 + "failed to disable regulator when suspending: %d\n", 1343 + error); 1344 + /* Attempt to power the chip back up */ 1345 + elan_set_power(data, true); 1346 + return error; 1347 + } 1348 + 1349 + return 0; 1350 + } 1351 + 1319 1352 static int elan_suspend(struct device *dev) 1320 1353 { 1321 1354 struct i2c_client *client = to_i2c_client(dev); 1322 1355 struct elan_tp_data *data = i2c_get_clientdata(client); 1323 - int ret; 1356 + int error; 1324 1357 1325 1358 /* 1326 1359 * We are taking the mutex to make sure sysfs operations are 1327 1360 * complete before we attempt to bring the device into low[er] 1328 1361 * power mode. 1329 1362 */ 1330 - ret = mutex_lock_interruptible(&data->sysfs_mutex); 1331 - if (ret) 1332 - return ret; 1363 + scoped_cond_guard(mutex_intr, return -EINTR, &data->sysfs_mutex) { 1364 + disable_irq(client->irq); 1333 1365 1334 - disable_irq(client->irq); 1335 - 1336 - if (device_may_wakeup(dev)) { 1337 - ret = elan_sleep(data); 1338 - } else { 1339 - ret = elan_set_power(data, false); 1340 - if (ret) 1341 - goto err; 1342 - 1343 - ret = regulator_disable(data->vcc); 1344 - if (ret) { 1345 - dev_err(dev, "error %d disabling regulator\n", ret); 1346 - /* Attempt to power the chip back up */ 1347 - elan_set_power(data, true); 1366 + error = __elan_suspend(data); 1367 + if (error) { 1368 + enable_irq(client->irq); 1369 + return error; 1348 1370 } 1349 1371 } 1350 1372 1351 - err: 1352 - if (ret) 1353 - enable_irq(client->irq); 1354 - mutex_unlock(&data->sysfs_mutex); 1355 - return ret; 1373 + return 0; 1356 1374 } 1357 1375 1358 1376 static int elan_resume(struct device *dev)
+5 -9
drivers/input/mouse/elan_i2c_i2c.c
··· 628 628 const u8 *page, u16 checksum, int idx) 629 629 { 630 630 struct device *dev = &client->dev; 631 - u8 *page_store; 632 631 u8 val[3]; 633 632 u16 result; 634 633 int ret, error; 635 634 636 - page_store = kmalloc(fw_page_size + 4, GFP_KERNEL); 635 + u8 *page_store __free(kfree) = kmalloc(fw_page_size + 4, GFP_KERNEL); 637 636 if (!page_store) 638 637 return -ENOMEM; 639 638 ··· 646 647 if (ret != fw_page_size + 4) { 647 648 error = ret < 0 ? ret : -EIO; 648 649 dev_err(dev, "Failed to write page %d: %d\n", idx, error); 649 - goto exit; 650 + return error; 650 651 } 651 652 652 653 /* Wait for F/W to update one page ROM data. */ ··· 655 656 error = elan_i2c_read_cmd(client, ETP_I2C_IAP_CTRL_CMD, val); 656 657 if (error) { 657 658 dev_err(dev, "Failed to read IAP write result: %d\n", error); 658 - goto exit; 659 + return error; 659 660 } 660 661 661 662 result = le16_to_cpup((__le16 *)val); 662 663 if (result & (ETP_FW_IAP_PAGE_ERR | ETP_FW_IAP_INTF_ERR)) { 663 664 dev_err(dev, "IAP reports failed write: %04hx\n", 664 665 result); 665 - error = -EIO; 666 - goto exit; 666 + return -EIO; 667 667 } 668 668 669 - exit: 670 - kfree(page_store); 671 - return error; 669 + return 0; 672 670 } 673 671 674 672 static int elan_i2c_finish_fw_update(struct i2c_client *client,
+10 -18
drivers/input/mouse/psmouse-smbus.c
··· 35 35 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_HOST_NOTIFY)) 36 36 return; 37 37 38 - mutex_lock(&psmouse_smbus_mutex); 38 + guard(mutex)(&psmouse_smbus_mutex); 39 39 40 40 list_for_each_entry(smbdev, &psmouse_smbus_list, node) { 41 41 if (smbdev->dead) ··· 55 55 "SMBus candidate adapter appeared, triggering rescan\n"); 56 56 serio_rescan(smbdev->psmouse->ps2dev.serio); 57 57 } 58 - 59 - mutex_unlock(&psmouse_smbus_mutex); 60 58 } 61 59 62 60 static void psmouse_smbus_detach_i2c_client(struct i2c_client *client) 63 61 { 64 62 struct psmouse_smbus_dev *smbdev, *tmp; 65 63 66 - mutex_lock(&psmouse_smbus_mutex); 64 + guard(mutex)(&psmouse_smbus_mutex); 67 65 68 66 list_for_each_entry_safe(smbdev, tmp, &psmouse_smbus_list, node) { 69 67 if (smbdev->client != client) ··· 83 85 kfree(smbdev); 84 86 } 85 87 } 86 - 87 - mutex_unlock(&psmouse_smbus_mutex); 88 88 } 89 89 90 90 static int psmouse_smbus_notifier_call(struct notifier_block *nb, ··· 167 171 { 168 172 struct psmouse_smbus_dev *smbdev = psmouse->private; 169 173 170 - mutex_lock(&psmouse_smbus_mutex); 174 + guard(mutex)(&psmouse_smbus_mutex); 171 175 172 176 if (smbdev->dead) { 173 177 list_del(&smbdev->node); ··· 181 185 dev_name(&smbdev->client->dev)); 182 186 psmouse_smbus_schedule_remove(smbdev->client); 183 187 } 184 - 185 - mutex_unlock(&psmouse_smbus_mutex); 186 188 187 189 psmouse->private = NULL; 188 190 } ··· 213 219 { 214 220 struct psmouse_smbus_dev *smbdev, *tmp; 215 221 216 - mutex_lock(&psmouse_smbus_mutex); 222 + guard(mutex)(&psmouse_smbus_mutex); 217 223 218 224 list_for_each_entry_safe(smbdev, tmp, &psmouse_smbus_list, node) { 219 225 if (psmouse == smbdev->psmouse) { ··· 221 227 kfree(smbdev); 222 228 } 223 229 } 224 - 225 - mutex_unlock(&psmouse_smbus_mutex); 226 230 } 227 231 228 232 int psmouse_smbus_init(struct psmouse *psmouse, ··· 259 267 psmouse->disconnect = psmouse_smbus_disconnect; 260 268 psmouse->resync_time = 0; 261 269 262 - mutex_lock(&psmouse_smbus_mutex); 263 - list_add_tail(&smbdev->node, &psmouse_smbus_list); 264 - mutex_unlock(&psmouse_smbus_mutex); 270 + scoped_guard(mutex, &psmouse_smbus_mutex) { 271 + list_add_tail(&smbdev->node, &psmouse_smbus_list); 272 + } 265 273 266 274 /* Bind to already existing adapters right away */ 267 275 error = i2c_for_each_dev(smbdev, psmouse_smbus_create_companion); ··· 285 293 smbdev->board.platform_data = NULL; 286 294 287 295 if (error < 0 || !leave_breadcrumbs) { 288 - mutex_lock(&psmouse_smbus_mutex); 289 - list_del(&smbdev->node); 290 - mutex_unlock(&psmouse_smbus_mutex); 296 + scoped_guard(mutex, &psmouse_smbus_mutex) { 297 + list_del(&smbdev->node); 298 + } 291 299 292 300 kfree(smbdev); 293 301 }
+2 -4
drivers/input/mouse/synaptics.c
··· 650 650 struct psmouse *parent = psmouse_from_serio(serio->parent); 651 651 struct synaptics_data *priv = parent->private; 652 652 653 - serio_pause_rx(parent->ps2dev.serio); 653 + guard(serio_pause_rx)(parent->ps2dev.serio); 654 654 priv->pt_port = serio; 655 - serio_continue_rx(parent->ps2dev.serio); 656 655 657 656 return 0; 658 657 } ··· 661 662 struct psmouse *parent = psmouse_from_serio(serio->parent); 662 663 struct synaptics_data *priv = parent->private; 663 664 664 - serio_pause_rx(parent->ps2dev.serio); 665 + guard(serio_pause_rx)(parent->ps2dev.serio); 665 666 priv->pt_port = NULL; 666 - serio_continue_rx(parent->ps2dev.serio); 667 667 } 668 668 669 669 static int synaptics_is_pt_packet(u8 *buf)
+1 -1
drivers/input/mouse/synaptics.h
··· 21 21 #define SYN_QUE_EXT_MIN_COORDS 0x0f 22 22 #define SYN_QUE_MEXT_CAPAB_10 0x10 23 23 24 - /* synatics modes */ 24 + /* synaptics modes */ 25 25 #define SYN_BIT_ABSOLUTE_MODE BIT(7) 26 26 #define SYN_BIT_HIGH_RATE BIT(6) 27 27 #define SYN_BIT_SLEEP_MODE BIT(3)
+2 -2
drivers/input/rmi4/rmi_f03.c
··· 61 61 struct f03_data *f03 = dev_get_drvdata(&fn->dev); 62 62 struct serio *serio = f03->serio; 63 63 64 - serio_pause_rx(serio); 64 + guard(serio_pause_rx)(serio); 65 + 65 66 if (serio->drv) { 66 67 serio->drv->interrupt(serio, PSMOUSE_OOB_EXTRA_BTNS, 67 68 SERIO_OOB_DATA); 68 69 serio->drv->interrupt(serio, f03->overwrite_buttons, 69 70 SERIO_OOB_DATA); 70 71 } 71 - serio_continue_rx(serio); 72 72 } 73 73 74 74 static int rmi_f03_pt_write(struct serio *id, unsigned char val)
+14 -23
drivers/input/rmi4/rmi_f34.c
··· 246 246 (const struct rmi_f34_firmware *)fw->data; 247 247 u32 image_size = le32_to_cpu(syn_fw->image_size); 248 248 u32 config_size = le32_to_cpu(syn_fw->config_size); 249 - int ret; 250 249 251 250 BUILD_BUG_ON(offsetof(struct rmi_f34_firmware, data) != 252 251 F34_FW_IMAGE_OFFSET); ··· 266 267 dev_err(&f34->fn->dev, 267 268 "Bad firmware image: fw size %d, expected %d\n", 268 269 image_size, f34->v5.fw_blocks * f34->v5.block_size); 269 - ret = -EILSEQ; 270 - goto out; 270 + return -EILSEQ; 271 271 } 272 272 273 273 if (config_size && ··· 275 277 "Bad firmware image: config size %d, expected %d\n", 276 278 config_size, 277 279 f34->v5.config_blocks * f34->v5.block_size); 278 - ret = -EILSEQ; 279 - goto out; 280 + return -EILSEQ; 280 281 } 281 282 282 283 if (image_size && !config_size) { 283 284 dev_err(&f34->fn->dev, "Bad firmware image: no config data\n"); 284 - ret = -EILSEQ; 285 - goto out; 285 + return -EILSEQ; 286 286 } 287 287 288 288 dev_info(&f34->fn->dev, "Firmware image OK\n"); 289 - mutex_lock(&f34->v5.flash_mutex); 290 289 291 - ret = rmi_f34_flash_firmware(f34, syn_fw); 292 - 293 - mutex_unlock(&f34->v5.flash_mutex); 294 - 295 - out: 296 - return ret; 290 + guard(mutex)(&f34->v5.flash_mutex); 291 + return rmi_f34_flash_firmware(f34, syn_fw); 297 292 } 298 293 299 294 static int rmi_f34_status(struct rmi_function *fn) ··· 452 461 { 453 462 struct rmi_driver_data *data = dev_get_drvdata(dev); 454 463 char fw_name[NAME_MAX]; 455 - const struct firmware *fw; 456 464 size_t copy_count = count; 457 - int ret; 465 + int error; 458 466 459 467 if (count == 0 || count >= NAME_MAX) 460 468 return -EINVAL; ··· 464 474 memcpy(fw_name, buf, copy_count); 465 475 fw_name[copy_count] = '\0'; 466 476 467 - ret = request_firmware(&fw, fw_name, dev); 468 - if (ret) 469 - return ret; 477 + const struct firmware *fw __free(firmware) = NULL; 478 + error = request_firmware(&fw, fw_name, dev); 479 + if (error) 480 + return error; 470 481 471 482 dev_info(dev, "Flashing %s\n", fw_name); 472 483 473 - ret = rmi_firmware_update(data, fw); 484 + error = rmi_firmware_update(data, fw); 485 + if (error) 486 + return error; 474 487 475 - release_firmware(fw); 476 - 477 - return ret ?: count; 488 + return count; 478 489 } 479 490 480 491 static DEVICE_ATTR(update_fw, 0200, NULL, rmi_driver_update_fw_store);
+1 -1
drivers/input/serio/altera_ps2.c
··· 146 146 */ 147 147 static struct platform_driver altera_ps2_driver = { 148 148 .probe = altera_ps2_probe, 149 - .remove_new = altera_ps2_remove, 149 + .remove = altera_ps2_remove, 150 150 .driver = { 151 151 .name = DRV_NAME, 152 152 .of_match_table = of_match_ptr(altera_ps2_match),
+1 -1
drivers/input/serio/ams_delta_serio.c
··· 182 182 183 183 static struct platform_driver ams_delta_serio_driver = { 184 184 .probe = ams_delta_serio_init, 185 - .remove_new = ams_delta_serio_exit, 185 + .remove = ams_delta_serio_exit, 186 186 .driver = { 187 187 .name = DRIVER_NAME 188 188 },
+1 -1
drivers/input/serio/apbps2.c
··· 208 208 .of_match_table = apbps2_of_match, 209 209 }, 210 210 .probe = apbps2_of_probe, 211 - .remove_new = apbps2_of_remove, 211 + .remove = apbps2_of_remove, 212 212 }; 213 213 214 214 module_platform_driver(apbps2_of_driver);
+1 -1
drivers/input/serio/arc_ps2.c
··· 260 260 .of_match_table = of_match_ptr(arc_ps2_match), 261 261 }, 262 262 .probe = arc_ps2_probe, 263 - .remove_new = arc_ps2_remove, 263 + .remove = arc_ps2_remove, 264 264 }; 265 265 266 266 module_platform_driver(arc_ps2_driver);
+1 -1
drivers/input/serio/ct82c710.c
··· 190 190 .name = "ct82c710", 191 191 }, 192 192 .probe = ct82c710_probe, 193 - .remove_new = ct82c710_remove, 193 + .remove = ct82c710_remove, 194 194 }; 195 195 196 196
+62 -54
drivers/input/serio/gscps2.c
··· 145 145 146 146 static inline int gscps2_writeb_output(struct gscps2port *ps2port, u8 data) 147 147 { 148 - unsigned long flags; 149 148 char __iomem *addr = ps2port->addr; 150 149 151 150 if (!wait_TBE(addr)) { ··· 155 156 while (gscps2_readb_status(addr) & GSC_STAT_RBNE) 156 157 /* wait */; 157 158 158 - spin_lock_irqsave(&ps2port->lock, flags); 159 - writeb(data, addr+GSC_XMTDATA); 160 - spin_unlock_irqrestore(&ps2port->lock, flags); 159 + scoped_guard(spinlock_irqsave, &ps2port->lock) 160 + writeb(data, addr+GSC_XMTDATA); 161 161 162 162 /* this is ugly, but due to timing of the port it seems to be necessary. */ 163 163 mdelay(6); ··· 175 177 176 178 static void gscps2_enable(struct gscps2port *ps2port, int enable) 177 179 { 178 - unsigned long flags; 179 180 u8 data; 180 181 181 182 /* now enable/disable the port */ 182 - spin_lock_irqsave(&ps2port->lock, flags); 183 - gscps2_flush(ps2port); 184 - data = gscps2_readb_control(ps2port->addr); 185 - if (enable) 186 - data |= GSC_CTRL_ENBL; 187 - else 188 - data &= ~GSC_CTRL_ENBL; 189 - gscps2_writeb_control(data, ps2port->addr); 190 - spin_unlock_irqrestore(&ps2port->lock, flags); 183 + scoped_guard(spinlock_irqsave, &ps2port->lock) { 184 + gscps2_flush(ps2port); 185 + data = gscps2_readb_control(ps2port->addr); 186 + if (enable) 187 + data |= GSC_CTRL_ENBL; 188 + else 189 + data &= ~GSC_CTRL_ENBL; 190 + gscps2_writeb_control(data, ps2port->addr); 191 + } 192 + 191 193 wait_TBE(ps2port->addr); 192 194 gscps2_flush(ps2port); 193 195 } ··· 198 200 199 201 static void gscps2_reset(struct gscps2port *ps2port) 200 202 { 201 - unsigned long flags; 202 - 203 203 /* reset the interface */ 204 - spin_lock_irqsave(&ps2port->lock, flags); 204 + guard(spinlock_irqsave)(&ps2port->lock); 205 205 gscps2_flush(ps2port); 206 206 writeb(0xff, ps2port->addr + GSC_RESET); 207 207 gscps2_flush(ps2port); 208 - spin_unlock_irqrestore(&ps2port->lock, flags); 209 208 } 210 209 211 210 static LIST_HEAD(ps2port_list); 211 + 212 + static void gscps2_read_data(struct gscps2port *ps2port) 213 + { 214 + u8 status; 215 + 216 + do { 217 + status = gscps2_readb_status(ps2port->addr); 218 + if (!(status & GSC_STAT_RBNE)) 219 + break; 220 + 221 + ps2port->buffer[ps2port->append].str = status; 222 + ps2port->buffer[ps2port->append].data = 223 + gscps2_readb_input(ps2port->addr); 224 + } while (true); 225 + } 226 + 227 + static bool gscps2_report_data(struct gscps2port *ps2port) 228 + { 229 + unsigned int rxflags; 230 + u8 data, status; 231 + 232 + while (ps2port->act != ps2port->append) { 233 + /* 234 + * Did new data arrived while we read existing data ? 235 + * If yes, exit now and let the new irq handler start 236 + * over again. 237 + */ 238 + if (gscps2_readb_status(ps2port->addr) & GSC_STAT_CMPINTR) 239 + return true; 240 + 241 + status = ps2port->buffer[ps2port->act].str; 242 + data = ps2port->buffer[ps2port->act].data; 243 + 244 + ps2port->act = (ps2port->act + 1) & BUFFER_SIZE; 245 + rxflags = ((status & GSC_STAT_TERR) ? SERIO_TIMEOUT : 0 ) | 246 + ((status & GSC_STAT_PERR) ? SERIO_PARITY : 0 ); 247 + 248 + serio_interrupt(ps2port->port, data, rxflags); 249 + } 250 + 251 + return false; 252 + } 212 253 213 254 /** 214 255 * gscps2_interrupt() - Interruption service routine ··· 266 229 struct gscps2port *ps2port; 267 230 268 231 list_for_each_entry(ps2port, &ps2port_list, node) { 232 + guard(spinlock_irqsave)(&ps2port->lock); 269 233 270 - unsigned long flags; 271 - spin_lock_irqsave(&ps2port->lock, flags); 272 - 273 - while ( (ps2port->buffer[ps2port->append].str = 274 - gscps2_readb_status(ps2port->addr)) & GSC_STAT_RBNE ) { 275 - ps2port->buffer[ps2port->append].data = 276 - gscps2_readb_input(ps2port->addr); 277 - ps2port->append = ((ps2port->append+1) & BUFFER_SIZE); 278 - } 279 - 280 - spin_unlock_irqrestore(&ps2port->lock, flags); 281 - 234 + gscps2_read_data(ps2port); 282 235 } /* list_for_each_entry */ 283 236 284 237 /* all data was read from the ports - now report the data to upper layer */ 285 - 286 238 list_for_each_entry(ps2port, &ps2port_list, node) { 287 - 288 - while (ps2port->act != ps2port->append) { 289 - 290 - unsigned int rxflags; 291 - u8 data, status; 292 - 293 - /* Did new data arrived while we read existing data ? 294 - If yes, exit now and let the new irq handler start over again */ 295 - if (gscps2_readb_status(ps2port->addr) & GSC_STAT_CMPINTR) 296 - return IRQ_HANDLED; 297 - 298 - status = ps2port->buffer[ps2port->act].str; 299 - data = ps2port->buffer[ps2port->act].data; 300 - 301 - ps2port->act = ((ps2port->act+1) & BUFFER_SIZE); 302 - rxflags = ((status & GSC_STAT_TERR) ? SERIO_TIMEOUT : 0 ) | 303 - ((status & GSC_STAT_PERR) ? SERIO_PARITY : 0 ); 304 - 305 - serio_interrupt(ps2port->port, data, rxflags); 306 - 307 - } /* while() */ 308 - 309 - } /* list_for_each_entry */ 239 + if (gscps2_report_data(ps2port)) { 240 + /* More data ready - break early to restart interrupt */ 241 + break; 242 + } 243 + } 310 244 311 245 return IRQ_HANDLED; 312 246 }
+18 -20
drivers/input/serio/hyperv-keyboard.c
··· 102 102 { 103 103 struct hv_kbd_dev *kbd_dev = hv_get_drvdata(hv_dev); 104 104 struct synth_kbd_keystroke *ks_msg; 105 - unsigned long flags; 106 105 u32 msg_type = __le32_to_cpu(msg->header.type); 107 106 u32 info; 108 107 u16 scan_code; ··· 146 147 /* 147 148 * Inject the information through the serio interrupt. 148 149 */ 149 - spin_lock_irqsave(&kbd_dev->lock, flags); 150 - if (kbd_dev->started) { 151 - if (info & IS_E0) 152 - serio_interrupt(kbd_dev->hv_serio, 153 - XTKBD_EMUL0, 0); 154 - if (info & IS_E1) 155 - serio_interrupt(kbd_dev->hv_serio, 156 - XTKBD_EMUL1, 0); 157 - scan_code = __le16_to_cpu(ks_msg->make_code); 158 - if (info & IS_BREAK) 159 - scan_code |= XTKBD_RELEASE; 150 + scoped_guard(spinlock_irqsave, &kbd_dev->lock) { 151 + if (kbd_dev->started) { 152 + if (info & IS_E0) 153 + serio_interrupt(kbd_dev->hv_serio, 154 + XTKBD_EMUL0, 0); 155 + if (info & IS_E1) 156 + serio_interrupt(kbd_dev->hv_serio, 157 + XTKBD_EMUL1, 0); 158 + scan_code = __le16_to_cpu(ks_msg->make_code); 159 + if (info & IS_BREAK) 160 + scan_code |= XTKBD_RELEASE; 160 161 161 - serio_interrupt(kbd_dev->hv_serio, scan_code, 0); 162 + serio_interrupt(kbd_dev->hv_serio, 163 + scan_code, 0); 164 + } 162 165 } 163 - spin_unlock_irqrestore(&kbd_dev->lock, flags); 164 166 165 167 /* 166 168 * Only trigger a wakeup on key down, otherwise ··· 292 292 static int hv_kbd_start(struct serio *serio) 293 293 { 294 294 struct hv_kbd_dev *kbd_dev = serio->port_data; 295 - unsigned long flags; 296 295 297 - spin_lock_irqsave(&kbd_dev->lock, flags); 296 + guard(spinlock_irqsave)(&kbd_dev->lock); 297 + 298 298 kbd_dev->started = true; 299 - spin_unlock_irqrestore(&kbd_dev->lock, flags); 300 299 301 300 return 0; 302 301 } ··· 303 304 static void hv_kbd_stop(struct serio *serio) 304 305 { 305 306 struct hv_kbd_dev *kbd_dev = serio->port_data; 306 - unsigned long flags; 307 307 308 - spin_lock_irqsave(&kbd_dev->lock, flags); 308 + guard(spinlock_irqsave)(&kbd_dev->lock); 309 + 309 310 kbd_dev->started = false; 310 - spin_unlock_irqrestore(&kbd_dev->lock, flags); 311 311 } 312 312 313 313 static int hv_kbd_probe(struct hv_device *hv_dev,
+1 -1
drivers/input/serio/i8042-acpipnpio.h
··· 90 90 * ORDERING IS IMPORTANT! The first match will be apllied and the rest ignored. 91 91 * This allows entries to overwrite vendor wide quirks on a per device basis. 92 92 * Where this is irrelevant, entries are sorted case sensitive by DMI_SYS_VENDOR 93 - * and/or DMI_BOARD_VENDOR to make it easier to avoid dublicate entries. 93 + * and/or DMI_BOARD_VENDOR to make it easier to avoid duplicate entries. 94 94 */ 95 95 static const struct dmi_system_id i8042_dmi_quirk_table[] __initconst = { 96 96 {
+4 -12
drivers/input/serio/i8042-sparcio.h
··· 101 101 .of_match_table = sparc_i8042_match, 102 102 }, 103 103 .probe = sparc_i8042_probe, 104 - .remove_new = sparc_i8042_remove, 104 + .remove = sparc_i8042_remove, 105 105 }; 106 106 107 107 static bool i8042_is_mr_coffee(void) 108 108 { 109 - struct device_node *root; 110 - const char *name; 111 - bool is_mr_coffee; 109 + struct device_node *root __free(device_node) = of_find_node_by_path("/"); 110 + const char *name = of_get_property(root, "name", NULL); 112 111 113 - root = of_find_node_by_path("/"); 114 - 115 - name = of_get_property(root, "name", NULL); 116 - is_mr_coffee = name && !strcmp(name, "SUNW,JavaStation-1"); 117 - 118 - of_node_put(root); 119 - 120 - return is_mr_coffee; 112 + return name && !strcmp(name, "SUNW,JavaStation-1"); 121 113 } 122 114 123 115 static int __init i8042_platform_init(void)
+159 -172
drivers/input/serio/i8042.c
··· 178 178 static struct platform_device *i8042_platform_device; 179 179 static struct notifier_block i8042_kbd_bind_notifier_block; 180 180 181 - static irqreturn_t i8042_interrupt(int irq, void *dev_id); 181 + static bool i8042_handle_data(int irq); 182 182 static bool (*i8042_platform_filter)(unsigned char data, unsigned char str, 183 183 struct serio *serio); 184 184 ··· 197 197 int i8042_install_filter(bool (*filter)(unsigned char data, unsigned char str, 198 198 struct serio *serio)) 199 199 { 200 - unsigned long flags; 201 - int ret = 0; 200 + guard(spinlock_irqsave)(&i8042_lock); 202 201 203 - spin_lock_irqsave(&i8042_lock, flags); 204 - 205 - if (i8042_platform_filter) { 206 - ret = -EBUSY; 207 - goto out; 208 - } 202 + if (i8042_platform_filter) 203 + return -EBUSY; 209 204 210 205 i8042_platform_filter = filter; 211 - 212 - out: 213 - spin_unlock_irqrestore(&i8042_lock, flags); 214 - return ret; 206 + return 0; 215 207 } 216 208 EXPORT_SYMBOL(i8042_install_filter); 217 209 218 210 int i8042_remove_filter(bool (*filter)(unsigned char data, unsigned char str, 219 211 struct serio *port)) 220 212 { 221 - unsigned long flags; 222 - int ret = 0; 213 + guard(spinlock_irqsave)(&i8042_lock); 223 214 224 - spin_lock_irqsave(&i8042_lock, flags); 225 - 226 - if (i8042_platform_filter != filter) { 227 - ret = -EINVAL; 228 - goto out; 229 - } 215 + if (i8042_platform_filter != filter) 216 + return -EINVAL; 230 217 231 218 i8042_platform_filter = NULL; 232 - 233 - out: 234 - spin_unlock_irqrestore(&i8042_lock, flags); 235 - return ret; 219 + return 0; 236 220 } 237 221 EXPORT_SYMBOL(i8042_remove_filter); 238 222 ··· 255 271 256 272 static int i8042_flush(void) 257 273 { 258 - unsigned long flags; 259 274 unsigned char data, str; 260 275 int count = 0; 261 - int retval = 0; 262 276 263 - spin_lock_irqsave(&i8042_lock, flags); 277 + guard(spinlock_irqsave)(&i8042_lock); 264 278 265 279 while ((str = i8042_read_status()) & I8042_STR_OBF) { 266 - if (count++ < I8042_BUFFER_SIZE) { 267 - udelay(50); 268 - data = i8042_read_data(); 269 - dbg("%02x <- i8042 (flush, %s)\n", 270 - data, str & I8042_STR_AUXDATA ? "aux" : "kbd"); 271 - } else { 272 - retval = -EIO; 273 - break; 274 - } 280 + if (count++ >= I8042_BUFFER_SIZE) 281 + return -EIO; 282 + 283 + udelay(50); 284 + data = i8042_read_data(); 285 + dbg("%02x <- i8042 (flush, %s)\n", 286 + data, str & I8042_STR_AUXDATA ? "aux" : "kbd"); 275 287 } 276 288 277 - spin_unlock_irqrestore(&i8042_lock, flags); 278 - 279 - return retval; 289 + return 0; 280 290 } 281 291 282 292 /* ··· 327 349 328 350 int i8042_command(unsigned char *param, int command) 329 351 { 330 - unsigned long flags; 331 - int retval; 332 - 333 352 if (!i8042_present) 334 353 return -1; 335 354 336 - spin_lock_irqsave(&i8042_lock, flags); 337 - retval = __i8042_command(param, command); 338 - spin_unlock_irqrestore(&i8042_lock, flags); 355 + guard(spinlock_irqsave)(&i8042_lock); 339 356 340 - return retval; 357 + return __i8042_command(param, command); 341 358 } 342 359 EXPORT_SYMBOL(i8042_command); 343 360 ··· 342 369 343 370 static int i8042_kbd_write(struct serio *port, unsigned char c) 344 371 { 345 - unsigned long flags; 346 - int retval = 0; 372 + int error; 347 373 348 - spin_lock_irqsave(&i8042_lock, flags); 374 + guard(spinlock_irqsave)(&i8042_lock); 349 375 350 - if (!(retval = i8042_wait_write())) { 351 - dbg("%02x -> i8042 (kbd-data)\n", c); 352 - i8042_write_data(c); 353 - } 376 + error = i8042_wait_write(); 377 + if (error) 378 + return error; 354 379 355 - spin_unlock_irqrestore(&i8042_lock, flags); 380 + dbg("%02x -> i8042 (kbd-data)\n", c); 381 + i8042_write_data(c); 356 382 357 - return retval; 383 + return 0; 358 384 } 359 385 360 386 /* ··· 406 434 * See if there is any data appeared while we were messing with 407 435 * port state. 408 436 */ 409 - i8042_interrupt(0, NULL); 437 + i8042_handle_data(0); 410 438 } 411 439 412 440 /* ··· 432 460 device_set_wakeup_enable(&serio->dev, true); 433 461 } 434 462 435 - spin_lock_irq(&i8042_lock); 463 + guard(spinlock_irq)(&i8042_lock); 436 464 port->exists = true; 437 - spin_unlock_irq(&i8042_lock); 438 465 439 466 return 0; 440 467 } ··· 447 476 { 448 477 struct i8042_port *port = serio->port_data; 449 478 450 - spin_lock_irq(&i8042_lock); 451 - port->exists = false; 452 - port->serio = NULL; 453 - spin_unlock_irq(&i8042_lock); 479 + scoped_guard(spinlock_irq, &i8042_lock) { 480 + port->exists = false; 481 + port->serio = NULL; 482 + } 454 483 455 484 /* 456 485 * We need to make sure that interrupt handler finishes using ··· 489 518 } 490 519 491 520 /* 492 - * i8042_interrupt() is the most important function in this driver - 493 - * it handles the interrupts from the i8042, and sends incoming bytes 494 - * to the upper layers. 495 - */ 496 - 497 - static irqreturn_t i8042_interrupt(int irq, void *dev_id) 498 - { 499 - struct i8042_port *port; 500 - struct serio *serio; 501 - unsigned long flags; 502 - unsigned char str, data; 503 - unsigned int dfl; 504 - unsigned int port_no; 505 - bool filtered; 506 - int ret = 1; 507 - 508 - spin_lock_irqsave(&i8042_lock, flags); 509 - 510 - str = i8042_read_status(); 511 - if (unlikely(~str & I8042_STR_OBF)) { 512 - spin_unlock_irqrestore(&i8042_lock, flags); 513 - if (irq) 514 - dbg("Interrupt %d, without any data\n", irq); 515 - ret = 0; 516 - goto out; 517 - } 518 - 519 - data = i8042_read_data(); 520 - 521 - if (i8042_mux_present && (str & I8042_STR_AUXDATA)) { 522 - static unsigned long last_transmit; 523 - static unsigned char last_str; 524 - 525 - dfl = 0; 526 - if (str & I8042_STR_MUXERR) { 527 - dbg("MUX error, status is %02x, data is %02x\n", 528 - str, data); 529 - /* 521 + * i8042_handle_mux() handles case when data is coming from one of 522 + * the multiplexed ports. It would be simple if not for quirks with 523 + * handling errors: 524 + * 530 525 * When MUXERR condition is signalled the data register can only contain 531 526 * 0xfd, 0xfe or 0xff if implementation follows the spec. Unfortunately 532 527 * it is not always the case. Some KBCs also report 0xfc when there is ··· 504 567 * rest assume that the data came from the same serio last byte 505 568 * was transmitted (if transmission happened not too long ago). 506 569 */ 570 + static int i8042_handle_mux(u8 str, u8 *data, unsigned int *dfl) 571 + { 572 + static unsigned long last_transmit; 573 + static unsigned long last_port; 574 + unsigned int mux_port; 507 575 508 - switch (data) { 509 - default: 510 - if (time_before(jiffies, last_transmit + HZ/10)) { 511 - str = last_str; 512 - break; 513 - } 514 - fallthrough; /* report timeout */ 515 - case 0xfc: 516 - case 0xfd: 517 - case 0xfe: dfl = SERIO_TIMEOUT; data = 0xfe; break; 518 - case 0xff: dfl = SERIO_PARITY; data = 0xfe; break; 576 + mux_port = (str >> 6) & 3; 577 + *dfl = 0; 578 + 579 + if (str & I8042_STR_MUXERR) { 580 + dbg("MUX error, status is %02x, data is %02x\n", 581 + str, *data); 582 + 583 + switch (*data) { 584 + default: 585 + if (time_before(jiffies, last_transmit + HZ/10)) { 586 + mux_port = last_port; 587 + break; 519 588 } 589 + fallthrough; /* report timeout */ 590 + case 0xfc: 591 + case 0xfd: 592 + case 0xfe: 593 + *dfl = SERIO_TIMEOUT; 594 + *data = 0xfe; 595 + break; 596 + case 0xff: 597 + *dfl = SERIO_PARITY; 598 + *data = 0xfe; 599 + break; 520 600 } 521 - 522 - port_no = I8042_MUX_PORT_NO + ((str >> 6) & 3); 523 - last_str = str; 524 - last_transmit = jiffies; 525 - } else { 526 - 527 - dfl = ((str & I8042_STR_PARITY) ? SERIO_PARITY : 0) | 528 - ((str & I8042_STR_TIMEOUT && !i8042_notimeout) ? SERIO_TIMEOUT : 0); 529 - 530 - port_no = (str & I8042_STR_AUXDATA) ? 531 - I8042_AUX_PORT_NO : I8042_KBD_PORT_NO; 532 601 } 533 602 534 - port = &i8042_ports[port_no]; 535 - serio = port->exists ? port->serio : NULL; 603 + last_port = mux_port; 604 + last_transmit = jiffies; 536 605 537 - filter_dbg(port->driver_bound, data, "<- i8042 (interrupt, %d, %d%s%s)\n", 538 - port_no, irq, 539 - dfl & SERIO_PARITY ? ", bad parity" : "", 540 - dfl & SERIO_TIMEOUT ? ", timeout" : ""); 606 + return I8042_MUX_PORT_NO + mux_port; 607 + } 541 608 542 - filtered = i8042_filter(data, str, serio); 609 + /* 610 + * i8042_handle_data() is the most important function in this driver - 611 + * it reads the data from the i8042, determines its destination serio 612 + * port, and sends received byte to the upper layers. 613 + * 614 + * Returns true if there was data waiting, false otherwise. 615 + */ 616 + static bool i8042_handle_data(int irq) 617 + { 618 + struct i8042_port *port; 619 + struct serio *serio; 620 + unsigned char str, data; 621 + unsigned int dfl; 622 + unsigned int port_no; 623 + bool filtered; 543 624 544 - spin_unlock_irqrestore(&i8042_lock, flags); 625 + scoped_guard(spinlock_irqsave, &i8042_lock) { 626 + str = i8042_read_status(); 627 + if (unlikely(~str & I8042_STR_OBF)) 628 + return false; 629 + 630 + data = i8042_read_data(); 631 + 632 + if (i8042_mux_present && (str & I8042_STR_AUXDATA)) { 633 + port_no = i8042_handle_mux(str, &data, &dfl); 634 + } else { 635 + 636 + dfl = (str & I8042_STR_PARITY) ? SERIO_PARITY : 0; 637 + if ((str & I8042_STR_TIMEOUT) && !i8042_notimeout) 638 + dfl |= SERIO_TIMEOUT; 639 + 640 + port_no = (str & I8042_STR_AUXDATA) ? 641 + I8042_AUX_PORT_NO : I8042_KBD_PORT_NO; 642 + } 643 + 644 + port = &i8042_ports[port_no]; 645 + serio = port->exists ? port->serio : NULL; 646 + 647 + filter_dbg(port->driver_bound, 648 + data, "<- i8042 (interrupt, %d, %d%s%s)\n", 649 + port_no, irq, 650 + dfl & SERIO_PARITY ? ", bad parity" : "", 651 + dfl & SERIO_TIMEOUT ? ", timeout" : ""); 652 + 653 + filtered = i8042_filter(data, str, serio); 654 + } 545 655 546 656 if (likely(serio && !filtered)) 547 657 serio_interrupt(serio, data, dfl); 548 658 549 - out: 550 - return IRQ_RETVAL(ret); 659 + return true; 660 + } 661 + 662 + static irqreturn_t i8042_interrupt(int irq, void *dev_id) 663 + { 664 + if (unlikely(!i8042_handle_data(irq))) { 665 + dbg("Interrupt %d, without any data\n", irq); 666 + return IRQ_NONE; 667 + } 668 + 669 + return IRQ_HANDLED; 551 670 } 552 671 553 672 /* ··· 746 753 747 754 static irqreturn_t i8042_aux_test_irq(int irq, void *dev_id) 748 755 { 749 - unsigned long flags; 750 756 unsigned char str, data; 751 - int ret = 0; 752 757 753 - spin_lock_irqsave(&i8042_lock, flags); 758 + guard(spinlock_irqsave)(&i8042_lock); 759 + 754 760 str = i8042_read_status(); 755 - if (str & I8042_STR_OBF) { 756 - data = i8042_read_data(); 757 - dbg("%02x <- i8042 (aux_test_irq, %s)\n", 758 - data, str & I8042_STR_AUXDATA ? "aux" : "kbd"); 759 - if (i8042_irq_being_tested && 760 - data == 0xa5 && (str & I8042_STR_AUXDATA)) 761 - complete(&i8042_aux_irq_delivered); 762 - ret = 1; 763 - } 764 - spin_unlock_irqrestore(&i8042_lock, flags); 761 + if (!(str & I8042_STR_OBF)) 762 + return IRQ_NONE; 765 763 766 - return IRQ_RETVAL(ret); 764 + data = i8042_read_data(); 765 + dbg("%02x <- i8042 (aux_test_irq, %s)\n", 766 + data, str & I8042_STR_AUXDATA ? "aux" : "kbd"); 767 + 768 + if (i8042_irq_being_tested && data == 0xa5 && (str & I8042_STR_AUXDATA)) 769 + complete(&i8042_aux_irq_delivered); 770 + 771 + return IRQ_HANDLED; 767 772 } 768 773 769 774 /* ··· 802 811 int retval = -1; 803 812 bool irq_registered = false; 804 813 bool aux_loop_broken = false; 805 - unsigned long flags; 806 814 unsigned char param; 807 815 808 816 /* ··· 885 895 if (i8042_enable_aux_port()) 886 896 goto out; 887 897 888 - spin_lock_irqsave(&i8042_lock, flags); 898 + scoped_guard(spinlock_irqsave, &i8042_lock) { 899 + init_completion(&i8042_aux_irq_delivered); 900 + i8042_irq_being_tested = true; 889 901 890 - init_completion(&i8042_aux_irq_delivered); 891 - i8042_irq_being_tested = true; 892 - 893 - param = 0xa5; 894 - retval = __i8042_command(&param, I8042_CMD_AUX_LOOP & 0xf0ff); 895 - 896 - spin_unlock_irqrestore(&i8042_lock, flags); 897 - 898 - if (retval) 899 - goto out; 902 + param = 0xa5; 903 + retval = __i8042_command(&param, I8042_CMD_AUX_LOOP & 0xf0ff); 904 + if (retval) 905 + goto out; 906 + } 900 907 901 908 if (wait_for_completion_timeout(&i8042_aux_irq_delivered, 902 909 msecs_to_jiffies(250)) == 0) { ··· 981 994 982 995 static int i8042_controller_init(void) 983 996 { 984 - unsigned long flags; 985 997 int n = 0; 986 998 unsigned char ctr[2]; 987 999 ··· 1017 1031 * Handle keylock. 1018 1032 */ 1019 1033 1020 - spin_lock_irqsave(&i8042_lock, flags); 1021 - if (~i8042_read_status() & I8042_STR_KEYLOCK) { 1022 - if (i8042_unlock) 1023 - i8042_ctr |= I8042_CTR_IGNKEYLOCK; 1024 - else 1025 - pr_warn("Warning: Keylock active\n"); 1034 + scoped_guard(spinlock_irqsave, &i8042_lock) { 1035 + if (~i8042_read_status() & I8042_STR_KEYLOCK) { 1036 + if (i8042_unlock) 1037 + i8042_ctr |= I8042_CTR_IGNKEYLOCK; 1038 + else 1039 + pr_warn("Warning: Keylock active\n"); 1040 + } 1026 1041 } 1027 - spin_unlock_irqrestore(&i8042_lock, flags); 1028 1042 1029 1043 /* 1030 1044 * If the chip is configured into nontranslated mode by the BIOS, don't ··· 1202 1216 if (i8042_mux_present) { 1203 1217 if (i8042_set_mux_mode(true, NULL) || i8042_enable_mux_ports()) 1204 1218 pr_warn("failed to resume active multiplexor, mouse won't work\n"); 1205 - } else if (i8042_ports[I8042_AUX_PORT_NO].serio) 1219 + } else if (i8042_ports[I8042_AUX_PORT_NO].serio) { 1206 1220 i8042_enable_aux_port(); 1221 + } 1207 1222 1208 1223 if (i8042_ports[I8042_KBD_PORT_NO].serio) 1209 1224 i8042_enable_kbd_port(); 1210 1225 1211 - i8042_interrupt(0, NULL); 1226 + i8042_handle_data(0); 1212 1227 1213 1228 return 0; 1214 1229 } ··· 1240 1253 static int i8042_pm_resume_noirq(struct device *dev) 1241 1254 { 1242 1255 if (i8042_forcenorestore || !pm_resume_via_firmware()) 1243 - i8042_interrupt(0, NULL); 1256 + i8042_handle_data(0); 1244 1257 1245 1258 return 0; 1246 1259 } ··· 1277 1290 1278 1291 static int i8042_pm_thaw(struct device *dev) 1279 1292 { 1280 - i8042_interrupt(0, NULL); 1293 + i8042_handle_data(0); 1281 1294 1282 1295 return 0; 1283 1296 } ··· 1590 1603 #endif 1591 1604 }, 1592 1605 .probe = i8042_probe, 1593 - .remove_new = i8042_remove, 1606 + .remove = i8042_remove, 1594 1607 .shutdown = i8042_shutdown, 1595 1608 }; 1596 1609
+1 -1
drivers/input/serio/ioc3kbd.c
··· 208 208 209 209 static struct platform_driver ioc3kbd_driver = { 210 210 .probe = ioc3kbd_probe, 211 - .remove_new = ioc3kbd_remove, 211 + .remove = ioc3kbd_remove, 212 212 .id_table = ioc3kbd_id_table, 213 213 .driver = { 214 214 .name = "ioc3-kbd",
+15 -13
drivers/input/serio/libps2.c
··· 108 108 { 109 109 int retval; 110 110 111 - serio_pause_rx(ps2dev->serio); 111 + guard(serio_pause_rx)(ps2dev->serio); 112 112 113 113 retval = ps2_do_sendbyte(ps2dev, byte, timeout, 1); 114 114 dev_dbg(&ps2dev->serio->dev, "%02x - %x\n", byte, ps2dev->nak); 115 - 116 - serio_continue_rx(ps2dev->serio); 117 115 118 116 return retval; 119 117 } ··· 160 162 161 163 ps2_begin_command(ps2dev); 162 164 163 - serio_pause_rx(ps2dev->serio); 164 - ps2dev->flags = PS2_FLAG_CMD; 165 - ps2dev->cmdcnt = maxbytes; 166 - serio_continue_rx(ps2dev->serio); 165 + scoped_guard(serio_pause_rx, ps2dev->serio) { 166 + ps2dev->flags = PS2_FLAG_CMD; 167 + ps2dev->cmdcnt = maxbytes; 168 + } 167 169 168 170 wait_event_timeout(ps2dev->wait, 169 171 !(ps2dev->flags & PS2_FLAG_CMD), ··· 222 224 * use alternative probe to detect it. 223 225 */ 224 226 if (ps2dev->cmdbuf[1] == 0xaa) { 225 - serio_pause_rx(ps2dev->serio); 226 - ps2dev->flags = 0; 227 - serio_continue_rx(ps2dev->serio); 227 + scoped_guard(serio_pause_rx, ps2dev->serio) 228 + ps2dev->flags = 0; 229 + 228 230 timeout = 0; 229 231 } 230 232 ··· 233 235 * won't be 2nd byte of ID response. 234 236 */ 235 237 if (!ps2_is_keyboard_id(ps2dev->cmdbuf[1])) { 236 - serio_pause_rx(ps2dev->serio); 237 - ps2dev->flags = ps2dev->cmdcnt = 0; 238 - serio_continue_rx(ps2dev->serio); 238 + scoped_guard(serio_pause_rx, ps2dev->serio) 239 + ps2dev->flags = ps2dev->cmdcnt = 0; 240 + 239 241 timeout = 0; 240 242 } 241 243 break; ··· 281 283 282 284 memcpy(send_param, param, send); 283 285 286 + /* 287 + * Not using guard notation because we need to break critical 288 + * section below while waiting for the response. 289 + */ 284 290 serio_pause_rx(ps2dev->serio); 285 291 286 292 ps2dev->cmdcnt = receive;
+1 -1
drivers/input/serio/maceps2.c
··· 159 159 .name = "maceps2", 160 160 }, 161 161 .probe = maceps2_probe, 162 - .remove_new = maceps2_remove, 162 + .remove = maceps2_remove, 163 163 }; 164 164 165 165 static int __init maceps2_init(void)
+1 -1
drivers/input/serio/olpc_apsp.c
··· 256 256 257 257 static struct platform_driver olpc_apsp_driver = { 258 258 .probe = olpc_apsp_probe, 259 - .remove_new = olpc_apsp_remove, 259 + .remove = olpc_apsp_remove, 260 260 .driver = { 261 261 .name = "olpc-apsp", 262 262 .of_match_table = olpc_apsp_dt_ids,
+3 -3
drivers/input/serio/ps2-gpio.c
··· 133 133 int ret = 0; 134 134 135 135 if (in_task()) { 136 - mutex_lock(&drvdata->tx.mutex); 136 + guard(mutex)(&drvdata->tx.mutex); 137 + 137 138 __ps2_gpio_write(serio, val); 138 139 if (!wait_for_completion_timeout(&drvdata->tx.complete, 139 140 msecs_to_jiffies(10000))) 140 141 ret = SERIO_TIMEOUT; 141 - mutex_unlock(&drvdata->tx.mutex); 142 142 } else { 143 143 __ps2_gpio_write(serio, val); 144 144 } ··· 491 491 492 492 static struct platform_driver ps2_gpio_driver = { 493 493 .probe = ps2_gpio_probe, 494 - .remove_new = ps2_gpio_remove, 494 + .remove = ps2_gpio_remove, 495 495 .driver = { 496 496 .name = DRIVER_NAME, 497 497 .of_match_table = of_match_ptr(ps2_gpio_match),
+7 -18
drivers/input/serio/ps2mult.c
··· 76 76 struct ps2mult *psm = serio_get_drvdata(mx_port); 77 77 struct ps2mult_port *port = serio->port_data; 78 78 bool need_escape; 79 - unsigned long flags; 80 79 81 - spin_lock_irqsave(&psm->lock, flags); 80 + guard(spinlock_irqsave)(&psm->lock); 82 81 83 82 if (psm->out_port != port) 84 83 ps2mult_select_port(psm, port); ··· 92 93 93 94 serio_write(mx_port, data); 94 95 95 - spin_unlock_irqrestore(&psm->lock, flags); 96 - 97 96 return 0; 98 97 } 99 98 ··· 99 102 { 100 103 struct ps2mult *psm = serio_get_drvdata(serio->parent); 101 104 struct ps2mult_port *port = serio->port_data; 102 - unsigned long flags; 103 105 104 - spin_lock_irqsave(&psm->lock, flags); 106 + guard(spinlock_irqsave)(&psm->lock); 107 + 105 108 port->registered = true; 106 - spin_unlock_irqrestore(&psm->lock, flags); 107 109 108 110 return 0; 109 111 } ··· 111 115 { 112 116 struct ps2mult *psm = serio_get_drvdata(serio->parent); 113 117 struct ps2mult_port *port = serio->port_data; 114 - unsigned long flags; 115 118 116 - spin_lock_irqsave(&psm->lock, flags); 119 + guard(spinlock_irqsave)(&psm->lock); 120 + 117 121 port->registered = false; 118 - spin_unlock_irqrestore(&psm->lock, flags); 119 122 } 120 123 121 124 static int ps2mult_create_port(struct ps2mult *psm, int i) ··· 143 148 144 149 static void ps2mult_reset(struct ps2mult *psm) 145 150 { 146 - unsigned long flags; 147 - 148 - spin_lock_irqsave(&psm->lock, flags); 151 + guard(spinlock_irqsave)(&psm->lock); 149 152 150 153 serio_write(psm->mx_serio, PS2MULT_SESSION_END); 151 154 serio_write(psm->mx_serio, PS2MULT_SESSION_START); 152 155 153 156 ps2mult_select_port(psm, &psm->ports[PS2MULT_KBD_PORT]); 154 - 155 - spin_unlock_irqrestore(&psm->lock, flags); 156 157 } 157 158 158 159 static int ps2mult_connect(struct serio *serio, struct serio_driver *drv) ··· 225 234 { 226 235 struct ps2mult *psm = serio_get_drvdata(serio); 227 236 struct ps2mult_port *in_port; 228 - unsigned long flags; 229 237 230 238 dev_dbg(&serio->dev, "Received %02x flags %02x\n", data, dfl); 231 239 232 - spin_lock_irqsave(&psm->lock, flags); 240 + guard(spinlock_irqsave)(&psm->lock); 233 241 234 242 if (psm->escape) { 235 243 psm->escape = false; ··· 275 285 } 276 286 277 287 out: 278 - spin_unlock_irqrestore(&psm->lock, flags); 279 288 return IRQ_HANDLED; 280 289 } 281 290
+3 -9
drivers/input/serio/q40kbd.c
··· 39 39 static irqreturn_t q40kbd_interrupt(int irq, void *dev_id) 40 40 { 41 41 struct q40kbd *q40kbd = dev_id; 42 - unsigned long flags; 43 42 44 - spin_lock_irqsave(&q40kbd->lock, flags); 43 + guard(spinlock_irqsave)(&q40kbd->lock); 45 44 46 45 if (Q40_IRQ_KEYB_MASK & master_inb(INTERRUPT_REG)) 47 46 serio_interrupt(q40kbd->port, master_inb(KEYCODE_REG), 0); 48 47 49 48 master_outb(-1, KEYBOARD_UNLOCK_REG); 50 - 51 - spin_unlock_irqrestore(&q40kbd->lock, flags); 52 49 53 50 return IRQ_HANDLED; 54 51 } ··· 57 60 static void q40kbd_flush(struct q40kbd *q40kbd) 58 61 { 59 62 int maxread = 100; 60 - unsigned long flags; 61 63 62 - spin_lock_irqsave(&q40kbd->lock, flags); 64 + guard(spinlock_irqsave)(&q40kbd->lock); 63 65 64 66 while (maxread-- && (Q40_IRQ_KEYB_MASK & master_inb(INTERRUPT_REG))) 65 67 master_inb(KEYCODE_REG); 66 - 67 - spin_unlock_irqrestore(&q40kbd->lock, flags); 68 68 } 69 69 70 70 static void q40kbd_stop(void) ··· 160 166 .driver = { 161 167 .name = "q40kbd", 162 168 }, 163 - .remove_new = q40kbd_remove, 169 + .remove = q40kbd_remove, 164 170 }; 165 171 166 172 module_platform_driver_probe(q40kbd_driver, q40kbd_probe);
+1 -1
drivers/input/serio/rpckbd.c
··· 144 144 145 145 static struct platform_driver rpckbd_driver = { 146 146 .probe = rpckbd_probe, 147 - .remove_new = rpckbd_remove, 147 + .remove = rpckbd_remove, 148 148 .driver = { 149 149 .name = "kart", 150 150 },
+3 -5
drivers/input/serio/sa1111ps2.c
··· 92 92 struct ps2if *ps2if = dev_id; 93 93 unsigned int status; 94 94 95 - spin_lock(&ps2if->lock); 95 + guard(spinlock)(&ps2if->lock); 96 + 96 97 status = readl_relaxed(ps2if->base + PS2STAT); 97 98 if (ps2if->head == ps2if->tail) { 98 99 disable_irq_nosync(irq); ··· 102 101 writel_relaxed(ps2if->buf[ps2if->tail], ps2if->base + PS2DATA); 103 102 ps2if->tail = (ps2if->tail + 1) & (sizeof(ps2if->buf) - 1); 104 103 } 105 - spin_unlock(&ps2if->lock); 106 104 107 105 return IRQ_HANDLED; 108 106 } ··· 113 113 static int ps2_write(struct serio *io, unsigned char val) 114 114 { 115 115 struct ps2if *ps2if = io->port_data; 116 - unsigned long flags; 117 116 unsigned int head; 118 117 119 - spin_lock_irqsave(&ps2if->lock, flags); 118 + guard(spinlock_irqsave)(&ps2if->lock); 120 119 121 120 /* 122 121 * If the TX register is empty, we can go straight out. ··· 132 133 } 133 134 } 134 135 135 - spin_unlock_irqrestore(&ps2if->lock, flags); 136 136 return 0; 137 137 } 138 138
+66 -99
drivers/input/serio/serio.c
··· 38 38 39 39 static int serio_connect_driver(struct serio *serio, struct serio_driver *drv) 40 40 { 41 - int retval; 41 + guard(mutex)(&serio->drv_mutex); 42 42 43 - mutex_lock(&serio->drv_mutex); 44 - retval = drv->connect(serio, drv); 45 - mutex_unlock(&serio->drv_mutex); 46 - 47 - return retval; 43 + return drv->connect(serio, drv); 48 44 } 49 45 50 46 static int serio_reconnect_driver(struct serio *serio) 51 47 { 52 - int retval = -1; 48 + guard(mutex)(&serio->drv_mutex); 53 49 54 - mutex_lock(&serio->drv_mutex); 55 50 if (serio->drv && serio->drv->reconnect) 56 - retval = serio->drv->reconnect(serio); 57 - mutex_unlock(&serio->drv_mutex); 51 + return serio->drv->reconnect(serio); 58 52 59 - return retval; 53 + return -1; 60 54 } 61 55 62 56 static void serio_disconnect_driver(struct serio *serio) 63 57 { 64 - mutex_lock(&serio->drv_mutex); 58 + guard(mutex)(&serio->drv_mutex); 59 + 65 60 if (serio->drv) 66 61 serio->drv->disconnect(serio); 67 - mutex_unlock(&serio->drv_mutex); 68 62 } 69 63 70 64 static int serio_match_port(const struct serio_device_id *ids, struct serio *serio) ··· 141 147 static struct serio_event *serio_get_event(void) 142 148 { 143 149 struct serio_event *event = NULL; 144 - unsigned long flags; 145 150 146 - spin_lock_irqsave(&serio_event_lock, flags); 151 + guard(spinlock_irqsave)(&serio_event_lock); 147 152 148 153 if (!list_empty(&serio_event_list)) { 149 154 event = list_first_entry(&serio_event_list, ··· 150 157 list_del_init(&event->node); 151 158 } 152 159 153 - spin_unlock_irqrestore(&serio_event_lock, flags); 154 160 return event; 155 161 } 156 162 ··· 163 171 enum serio_event_type type) 164 172 { 165 173 struct serio_event *e, *next; 166 - unsigned long flags; 167 174 168 - spin_lock_irqsave(&serio_event_lock, flags); 175 + guard(spinlock_irqsave)(&serio_event_lock); 169 176 170 177 list_for_each_entry_safe(e, next, &serio_event_list, node) { 171 178 if (object == e->object) { ··· 180 189 serio_free_event(e); 181 190 } 182 191 } 183 - 184 - spin_unlock_irqrestore(&serio_event_lock, flags); 185 192 } 186 193 187 194 static void serio_handle_event(struct work_struct *work) 188 195 { 189 196 struct serio_event *event; 190 197 191 - mutex_lock(&serio_mutex); 198 + guard(mutex)(&serio_mutex); 192 199 193 200 while ((event = serio_get_event())) { 194 201 ··· 217 228 serio_remove_duplicate_events(event->object, event->type); 218 229 serio_free_event(event); 219 230 } 220 - 221 - mutex_unlock(&serio_mutex); 222 231 } 223 232 224 233 static DECLARE_WORK(serio_event_work, serio_handle_event); ··· 224 237 static int serio_queue_event(void *object, struct module *owner, 225 238 enum serio_event_type event_type) 226 239 { 227 - unsigned long flags; 228 240 struct serio_event *event; 229 - int retval = 0; 230 241 231 - spin_lock_irqsave(&serio_event_lock, flags); 242 + guard(spinlock_irqsave)(&serio_event_lock); 232 243 233 244 /* 234 245 * Scan event list for the other events for the same serio port, ··· 238 253 list_for_each_entry_reverse(event, &serio_event_list, node) { 239 254 if (event->object == object) { 240 255 if (event->type == event_type) 241 - goto out; 256 + return 0; 242 257 break; 243 258 } 244 259 } ··· 246 261 event = kmalloc(sizeof(*event), GFP_ATOMIC); 247 262 if (!event) { 248 263 pr_err("Not enough memory to queue event %d\n", event_type); 249 - retval = -ENOMEM; 250 - goto out; 264 + return -ENOMEM; 251 265 } 252 266 253 267 if (!try_module_get(owner)) { 254 268 pr_warn("Can't get module reference, dropping event %d\n", 255 269 event_type); 256 270 kfree(event); 257 - retval = -EINVAL; 258 - goto out; 271 + return -EINVAL; 259 272 } 260 273 261 274 event->type = event_type; ··· 263 280 list_add_tail(&event->node, &serio_event_list); 264 281 queue_work(system_long_wq, &serio_event_work); 265 282 266 - out: 267 - spin_unlock_irqrestore(&serio_event_lock, flags); 268 - return retval; 283 + return 0; 269 284 } 270 285 271 286 /* ··· 273 292 static void serio_remove_pending_events(void *object) 274 293 { 275 294 struct serio_event *event, *next; 276 - unsigned long flags; 277 295 278 - spin_lock_irqsave(&serio_event_lock, flags); 296 + guard(spinlock_irqsave)(&serio_event_lock); 279 297 280 298 list_for_each_entry_safe(event, next, &serio_event_list, node) { 281 299 if (event->object == object) { ··· 282 302 serio_free_event(event); 283 303 } 284 304 } 285 - 286 - spin_unlock_irqrestore(&serio_event_lock, flags); 287 305 } 288 306 289 307 /* ··· 293 315 static struct serio *serio_get_pending_child(struct serio *parent) 294 316 { 295 317 struct serio_event *event; 296 - struct serio *serio, *child = NULL; 297 - unsigned long flags; 318 + struct serio *serio; 298 319 299 - spin_lock_irqsave(&serio_event_lock, flags); 320 + guard(spinlock_irqsave)(&serio_event_lock); 300 321 301 322 list_for_each_entry(event, &serio_event_list, node) { 302 323 if (event->type == SERIO_REGISTER_PORT) { 303 324 serio = event->object; 304 - if (serio->parent == parent) { 305 - child = serio; 306 - break; 307 - } 325 + if (serio->parent == parent) 326 + return serio; 308 327 } 309 328 } 310 329 311 - spin_unlock_irqrestore(&serio_event_lock, flags); 312 - return child; 330 + return NULL; 313 331 } 314 332 315 333 /* ··· 356 382 struct device_driver *drv; 357 383 int error; 358 384 359 - error = mutex_lock_interruptible(&serio_mutex); 360 - if (error) 361 - return error; 362 - 363 - if (!strncmp(buf, "none", count)) { 364 - serio_disconnect_port(serio); 365 - } else if (!strncmp(buf, "reconnect", count)) { 366 - serio_reconnect_subtree(serio); 367 - } else if (!strncmp(buf, "rescan", count)) { 368 - serio_disconnect_port(serio); 369 - serio_find_driver(serio); 370 - serio_remove_duplicate_events(serio, SERIO_RESCAN_PORT); 371 - } else if ((drv = driver_find(buf, &serio_bus)) != NULL) { 372 - serio_disconnect_port(serio); 373 - error = serio_bind_driver(serio, to_serio_driver(drv)); 374 - serio_remove_duplicate_events(serio, SERIO_RESCAN_PORT); 375 - } else { 376 - error = -EINVAL; 385 + scoped_cond_guard(mutex_intr, return -EINTR, &serio_mutex) { 386 + if (!strncmp(buf, "none", count)) { 387 + serio_disconnect_port(serio); 388 + } else if (!strncmp(buf, "reconnect", count)) { 389 + serio_reconnect_subtree(serio); 390 + } else if (!strncmp(buf, "rescan", count)) { 391 + serio_disconnect_port(serio); 392 + serio_find_driver(serio); 393 + serio_remove_duplicate_events(serio, SERIO_RESCAN_PORT); 394 + } else if ((drv = driver_find(buf, &serio_bus)) != NULL) { 395 + serio_disconnect_port(serio); 396 + error = serio_bind_driver(serio, to_serio_driver(drv)); 397 + serio_remove_duplicate_events(serio, SERIO_RESCAN_PORT); 398 + if (error) 399 + return error; 400 + } else { 401 + return -EINVAL; 402 + } 377 403 } 378 404 379 - mutex_unlock(&serio_mutex); 380 - 381 - return error ? error : count; 405 + return count; 382 406 } 383 407 384 408 static ssize_t serio_show_bind_mode(struct device *dev, struct device_attribute *attr, char *buf) ··· 498 526 int error; 499 527 500 528 if (parent) { 501 - serio_pause_rx(parent); 529 + guard(serio_pause_rx)(parent); 530 + 502 531 list_add_tail(&serio->child_node, &parent->children); 503 - serio_continue_rx(parent); 504 532 } 505 533 506 534 list_add_tail(&serio->node, &serio_list); ··· 532 560 serio->stop(serio); 533 561 534 562 if (serio->parent) { 535 - serio_pause_rx(serio->parent); 563 + guard(serio_pause_rx)(serio->parent); 564 + 536 565 list_del_init(&serio->child_node); 537 - serio_continue_rx(serio->parent); 538 566 serio->parent = NULL; 539 567 } 540 568 ··· 673 701 */ 674 702 void serio_unregister_port(struct serio *serio) 675 703 { 676 - mutex_lock(&serio_mutex); 704 + guard(mutex)(&serio_mutex); 705 + 677 706 serio_disconnect_port(serio); 678 707 serio_destroy_port(serio); 679 - mutex_unlock(&serio_mutex); 680 708 } 681 709 EXPORT_SYMBOL(serio_unregister_port); 682 710 ··· 687 715 { 688 716 struct serio *s, *next; 689 717 690 - mutex_lock(&serio_mutex); 718 + guard(mutex)(&serio_mutex); 719 + 691 720 list_for_each_entry_safe(s, next, &serio->children, child_node) { 692 721 serio_disconnect_port(s); 693 722 serio_destroy_port(s); 694 723 } 695 - mutex_unlock(&serio_mutex); 696 724 } 697 725 EXPORT_SYMBOL(serio_unregister_child_port); 698 726 ··· 756 784 757 785 static void serio_cleanup(struct serio *serio) 758 786 { 759 - mutex_lock(&serio->drv_mutex); 787 + guard(mutex)(&serio->drv_mutex); 788 + 760 789 if (serio->drv && serio->drv->cleanup) 761 790 serio->drv->cleanup(serio); 762 - mutex_unlock(&serio->drv_mutex); 763 791 } 764 792 765 793 static void serio_shutdown(struct device *dev) ··· 822 850 { 823 851 struct serio *serio; 824 852 825 - mutex_lock(&serio_mutex); 853 + guard(mutex)(&serio_mutex); 826 854 827 855 drv->manual_bind = true; /* so serio_find_driver ignores it */ 828 856 serio_remove_pending_events(drv); ··· 838 866 } 839 867 840 868 driver_unregister(&drv->driver); 841 - mutex_unlock(&serio_mutex); 842 869 } 843 870 EXPORT_SYMBOL(serio_unregister_driver); 844 871 845 872 static void serio_set_drv(struct serio *serio, struct serio_driver *drv) 846 873 { 847 - serio_pause_rx(serio); 874 + guard(serio_pause_rx)(serio); 875 + 848 876 serio->drv = drv; 849 - serio_continue_rx(serio); 850 877 } 851 878 852 879 static int serio_bus_match(struct device *dev, const struct device_driver *drv) ··· 906 935 struct serio *serio = to_serio_port(dev); 907 936 int error = -ENOENT; 908 937 909 - mutex_lock(&serio->drv_mutex); 910 - if (serio->drv && serio->drv->fast_reconnect) { 911 - error = serio->drv->fast_reconnect(serio); 912 - if (error && error != -ENOENT) 913 - dev_warn(dev, "fast reconnect failed with error %d\n", 914 - error); 938 + scoped_guard(mutex, &serio->drv_mutex) { 939 + if (serio->drv && serio->drv->fast_reconnect) { 940 + error = serio->drv->fast_reconnect(serio); 941 + if (error && error != -ENOENT) 942 + dev_warn(dev, "fast reconnect failed with error %d\n", 943 + error); 944 + } 915 945 } 916 - mutex_unlock(&serio->drv_mutex); 917 946 918 947 if (error) { 919 948 /* ··· 960 989 irqreturn_t serio_interrupt(struct serio *serio, 961 990 unsigned char data, unsigned int dfl) 962 991 { 963 - unsigned long flags; 964 - irqreturn_t ret = IRQ_NONE; 992 + guard(spinlock_irqsave)(&serio->lock); 965 993 966 - spin_lock_irqsave(&serio->lock, flags); 994 + if (likely(serio->drv)) 995 + return serio->drv->interrupt(serio, data, dfl); 967 996 968 - if (likely(serio->drv)) { 969 - ret = serio->drv->interrupt(serio, data, dfl); 970 - } else if (!dfl && device_is_registered(&serio->dev)) { 997 + if (!dfl && device_is_registered(&serio->dev)) { 971 998 serio_rescan(serio); 972 - ret = IRQ_HANDLED; 999 + return IRQ_HANDLED; 973 1000 } 974 1001 975 - spin_unlock_irqrestore(&serio->lock, flags); 976 - 977 - return ret; 1002 + return IRQ_NONE; 978 1003 } 979 1004 EXPORT_SYMBOL(serio_interrupt); 980 1005
+56 -79
drivers/input/serio/serio_raw.c
··· 29 29 unsigned char queue[SERIO_RAW_QUEUE_LEN]; 30 30 unsigned int tail, head; 31 31 32 - char name[16]; 32 + char name[20]; 33 33 struct kref kref; 34 34 struct serio *serio; 35 35 struct miscdevice dev; ··· 75 75 { 76 76 struct serio_raw *serio_raw; 77 77 struct serio_raw_client *client; 78 - int retval; 79 78 80 - retval = mutex_lock_interruptible(&serio_raw_mutex); 81 - if (retval) 82 - return retval; 79 + scoped_guard(mutex_intr, &serio_raw_mutex) { 80 + serio_raw = serio_raw_locate(iminor(inode)); 81 + if (!serio_raw) 82 + return -ENODEV; 83 83 84 - serio_raw = serio_raw_locate(iminor(inode)); 85 - if (!serio_raw) { 86 - retval = -ENODEV; 87 - goto out; 84 + if (serio_raw->dead) 85 + return -ENODEV; 86 + 87 + client = kzalloc(sizeof(*client), GFP_KERNEL); 88 + if (!client) 89 + return -ENOMEM; 90 + 91 + client->serio_raw = serio_raw; 92 + file->private_data = client; 93 + 94 + kref_get(&serio_raw->kref); 95 + 96 + scoped_guard(serio_pause_rx, serio_raw->serio) 97 + list_add_tail(&client->node, &serio_raw->client_list); 98 + 99 + return 0; 88 100 } 89 101 90 - if (serio_raw->dead) { 91 - retval = -ENODEV; 92 - goto out; 93 - } 94 - 95 - client = kzalloc(sizeof(*client), GFP_KERNEL); 96 - if (!client) { 97 - retval = -ENOMEM; 98 - goto out; 99 - } 100 - 101 - client->serio_raw = serio_raw; 102 - file->private_data = client; 103 - 104 - kref_get(&serio_raw->kref); 105 - 106 - serio_pause_rx(serio_raw->serio); 107 - list_add_tail(&client->node, &serio_raw->client_list); 108 - serio_continue_rx(serio_raw->serio); 109 - 110 - out: 111 - mutex_unlock(&serio_raw_mutex); 112 - return retval; 102 + return -EINTR; 113 103 } 114 104 115 105 static void serio_raw_free(struct kref *kref) ··· 116 126 struct serio_raw_client *client = file->private_data; 117 127 struct serio_raw *serio_raw = client->serio_raw; 118 128 119 - serio_pause_rx(serio_raw->serio); 120 - list_del(&client->node); 121 - serio_continue_rx(serio_raw->serio); 129 + scoped_guard(serio_pause_rx, serio_raw->serio) 130 + list_del(&client->node); 122 131 123 132 kfree(client); 124 133 ··· 128 139 129 140 static bool serio_raw_fetch_byte(struct serio_raw *serio_raw, char *c) 130 141 { 131 - bool empty; 142 + guard(serio_pause_rx)(serio_raw->serio); 132 143 133 - serio_pause_rx(serio_raw->serio); 144 + if (serio_raw->head == serio_raw->tail) 145 + return false; /* queue is empty */ 134 146 135 - empty = serio_raw->head == serio_raw->tail; 136 - if (!empty) { 137 - *c = serio_raw->queue[serio_raw->tail]; 138 - serio_raw->tail = (serio_raw->tail + 1) % SERIO_RAW_QUEUE_LEN; 139 - } 147 + *c = serio_raw->queue[serio_raw->tail]; 148 + serio_raw->tail = (serio_raw->tail + 1) % SERIO_RAW_QUEUE_LEN; 140 149 141 - serio_continue_rx(serio_raw->serio); 142 - 143 - return !empty; 150 + return true; 144 151 } 145 152 146 153 static ssize_t serio_raw_read(struct file *file, char __user *buffer, ··· 185 200 { 186 201 struct serio_raw_client *client = file->private_data; 187 202 struct serio_raw *serio_raw = client->serio_raw; 188 - int retval = 0; 203 + int written = 0; 189 204 unsigned char c; 190 205 191 - retval = mutex_lock_interruptible(&serio_raw_mutex); 192 - if (retval) 193 - return retval; 206 + scoped_guard(mutex_intr, &serio_raw_mutex) { 207 + if (serio_raw->dead) 208 + return -ENODEV; 194 209 195 - if (serio_raw->dead) { 196 - retval = -ENODEV; 197 - goto out; 198 - } 210 + if (count > 32) 211 + count = 32; 199 212 200 - if (count > 32) 201 - count = 32; 213 + while (count--) { 214 + if (get_user(c, buffer++)) 215 + return -EFAULT; 202 216 203 - while (count--) { 204 - if (get_user(c, buffer++)) { 205 - retval = -EFAULT; 206 - goto out; 217 + if (serio_write(serio_raw->serio, c)) { 218 + /* Either signal error or partial write */ 219 + return written ?: -EIO; 220 + } 221 + 222 + written++; 207 223 } 208 224 209 - if (serio_write(serio_raw->serio, c)) { 210 - /* Either signal error or partial write */ 211 - if (retval == 0) 212 - retval = -EIO; 213 - goto out; 214 - } 215 - 216 - retval++; 225 + return written; 217 226 } 218 227 219 - out: 220 - mutex_unlock(&serio_raw_mutex); 221 - return retval; 228 + return -EINTR; 222 229 } 223 230 224 231 static __poll_t serio_raw_poll(struct file *file, poll_table *wait) ··· 277 300 } 278 301 279 302 snprintf(serio_raw->name, sizeof(serio_raw->name), 280 - "serio_raw%ld", (long)atomic_inc_return(&serio_raw_no)); 303 + "serio_raw%u", atomic_inc_return(&serio_raw_no)); 281 304 kref_init(&serio_raw->kref); 282 305 INIT_LIST_HEAD(&serio_raw->client_list); 283 306 init_waitqueue_head(&serio_raw->wait); ··· 356 379 { 357 380 struct serio_raw_client *client; 358 381 359 - serio_pause_rx(serio_raw->serio); 360 - list_for_each_entry(client, &serio_raw->client_list, node) 361 - kill_fasync(&client->fasync, SIGIO, POLL_HUP); 362 - serio_continue_rx(serio_raw->serio); 382 + scoped_guard(serio_pause_rx, serio_raw->serio) { 383 + list_for_each_entry(client, &serio_raw->client_list, node) 384 + kill_fasync(&client->fasync, SIGIO, POLL_HUP); 385 + } 363 386 364 387 wake_up_interruptible(&serio_raw->wait); 365 388 } ··· 371 394 372 395 misc_deregister(&serio_raw->dev); 373 396 374 - mutex_lock(&serio_raw_mutex); 375 - serio_raw->dead = true; 376 - list_del_init(&serio_raw->node); 377 - mutex_unlock(&serio_raw_mutex); 397 + scoped_guard(mutex, &serio_raw_mutex) { 398 + serio_raw->dead = true; 399 + list_del_init(&serio_raw->node); 400 + } 378 401 379 402 serio_raw_hangup(serio_raw); 380 403
+8 -19
drivers/input/serio/serport.c
··· 50 50 static int serport_serio_open(struct serio *serio) 51 51 { 52 52 struct serport *serport = serio->port_data; 53 - unsigned long flags; 54 53 55 - spin_lock_irqsave(&serport->lock, flags); 54 + guard(spinlock_irqsave)(&serport->lock); 56 55 set_bit(SERPORT_ACTIVE, &serport->flags); 57 - spin_unlock_irqrestore(&serport->lock, flags); 58 56 59 57 return 0; 60 58 } ··· 61 63 static void serport_serio_close(struct serio *serio) 62 64 { 63 65 struct serport *serport = serio->port_data; 64 - unsigned long flags; 65 66 66 - spin_lock_irqsave(&serport->lock, flags); 67 + guard(spinlock_irqsave)(&serport->lock); 67 68 clear_bit(SERPORT_ACTIVE, &serport->flags); 68 - spin_unlock_irqrestore(&serport->lock, flags); 69 69 } 70 70 71 71 /* ··· 114 118 const u8 *fp, size_t count) 115 119 { 116 120 struct serport *serport = tty->disc_data; 117 - unsigned long flags; 118 121 unsigned int ch_flags = 0; 119 122 int i; 120 123 121 - spin_lock_irqsave(&serport->lock, flags); 124 + guard(spinlock_irqsave)(&serport->lock); 122 125 123 126 if (!test_bit(SERPORT_ACTIVE, &serport->flags)) 124 - goto out; 127 + return; 125 128 126 129 for (i = 0; i < count; i++) { 127 130 if (fp) { ··· 141 146 142 147 serio_interrupt(serport->serio, cp[i], ch_flags); 143 148 } 144 - 145 - out: 146 - spin_unlock_irqrestore(&serport->lock, flags); 147 149 } 148 150 149 151 /* ··· 238 246 static void serport_ldisc_hangup(struct tty_struct *tty) 239 247 { 240 248 struct serport *serport = tty->disc_data; 241 - unsigned long flags; 242 249 243 - spin_lock_irqsave(&serport->lock, flags); 244 - set_bit(SERPORT_DEAD, &serport->flags); 245 - spin_unlock_irqrestore(&serport->lock, flags); 250 + scoped_guard(spinlock_irqsave, &serport->lock) 251 + set_bit(SERPORT_DEAD, &serport->flags); 246 252 247 253 wake_up_interruptible(&serport->wait); 248 254 } ··· 248 258 static void serport_ldisc_write_wakeup(struct tty_struct * tty) 249 259 { 250 260 struct serport *serport = tty->disc_data; 251 - unsigned long flags; 252 261 253 - spin_lock_irqsave(&serport->lock, flags); 262 + guard(spinlock_irqsave)(&serport->lock); 263 + 254 264 if (test_bit(SERPORT_ACTIVE, &serport->flags)) 255 265 serio_drv_write_wakeup(serport->serio); 256 - spin_unlock_irqrestore(&serport->lock, flags); 257 266 } 258 267 259 268 /*
+3 -7
drivers/input/serio/sun4i-ps2.c
··· 101 101 unsigned int rxflags = 0; 102 102 u32 rval; 103 103 104 - spin_lock(&drvdata->lock); 104 + guard(spinlock)(&drvdata->lock); 105 105 106 106 /* Get the PS/2 interrupts and clear them */ 107 107 intr_status = readl(drvdata->reg_base + PS2_REG_LSTS); ··· 134 134 writel(intr_status, drvdata->reg_base + PS2_REG_LSTS); 135 135 writel(fifo_status, drvdata->reg_base + PS2_REG_FSTS); 136 136 137 - spin_unlock(&drvdata->lock); 138 - 139 137 return IRQ_HANDLED; 140 138 } 141 139 ··· 144 146 u32 clk_scdf; 145 147 u32 clk_pcdf; 146 148 u32 rval; 147 - unsigned long flags; 148 149 149 150 /* Set line control and enable interrupt */ 150 151 rval = PS2_LCTL_STOPERREN | PS2_LCTL_ACKERREN ··· 168 171 rval = PS2_GCTL_RESET | PS2_GCTL_INTEN | PS2_GCTL_MASTER 169 172 | PS2_GCTL_BUSEN; 170 173 171 - spin_lock_irqsave(&drvdata->lock, flags); 174 + guard(spinlock_irqsave)(&drvdata->lock); 172 175 writel(rval, drvdata->reg_base + PS2_REG_GCTL); 173 - spin_unlock_irqrestore(&drvdata->lock, flags); 174 176 175 177 return 0; 176 178 } ··· 318 322 319 323 static struct platform_driver sun4i_ps2_driver = { 320 324 .probe = sun4i_ps2_probe, 321 - .remove_new = sun4i_ps2_remove, 325 + .remove = sun4i_ps2_remove, 322 326 .driver = { 323 327 .name = DRIVER_NAME, 324 328 .of_match_table = sun4i_ps2_match,
+87 -88
drivers/input/serio/userio.c
··· 55 55 static int userio_device_write(struct serio *id, unsigned char val) 56 56 { 57 57 struct userio_device *userio = id->port_data; 58 - unsigned long flags; 59 58 60 - spin_lock_irqsave(&userio->buf_lock, flags); 59 + scoped_guard(spinlock_irqsave, &userio->buf_lock) { 60 + userio->buf[userio->head] = val; 61 + userio->head = (userio->head + 1) % USERIO_BUFSIZE; 61 62 62 - userio->buf[userio->head] = val; 63 - userio->head = (userio->head + 1) % USERIO_BUFSIZE; 64 - 65 - if (userio->head == userio->tail) 66 - dev_warn(userio_misc.this_device, 67 - "Buffer overflowed, userio client isn't keeping up"); 68 - 69 - spin_unlock_irqrestore(&userio->buf_lock, flags); 63 + if (userio->head == userio->tail) 64 + dev_warn(userio_misc.this_device, 65 + "Buffer overflowed, userio client isn't keeping up"); 66 + } 70 67 71 68 wake_up_interruptible(&userio->waitq); 72 69 ··· 72 75 73 76 static int userio_char_open(struct inode *inode, struct file *file) 74 77 { 75 - struct userio_device *userio; 76 - 77 - userio = kzalloc(sizeof(*userio), GFP_KERNEL); 78 + struct userio_device *userio __free(kfree) = 79 + kzalloc(sizeof(*userio), GFP_KERNEL); 78 80 if (!userio) 79 81 return -ENOMEM; 80 82 ··· 82 86 init_waitqueue_head(&userio->waitq); 83 87 84 88 userio->serio = kzalloc(sizeof(*userio->serio), GFP_KERNEL); 85 - if (!userio->serio) { 86 - kfree(userio); 89 + if (!userio->serio) 87 90 return -ENOMEM; 88 - } 89 91 90 92 userio->serio->write = userio_device_write; 91 93 userio->serio->port_data = userio; 92 94 93 - file->private_data = userio; 95 + file->private_data = no_free_ptr(userio); 94 96 95 97 return 0; 96 98 } ··· 112 118 return 0; 113 119 } 114 120 121 + static size_t userio_fetch_data(struct userio_device *userio, u8 *buf, 122 + size_t count, size_t *copylen) 123 + { 124 + size_t available, len; 125 + 126 + guard(spinlock_irqsave)(&userio->buf_lock); 127 + 128 + available = CIRC_CNT_TO_END(userio->head, userio->tail, 129 + USERIO_BUFSIZE); 130 + len = min(available, count); 131 + if (len) { 132 + memcpy(buf, &userio->buf[userio->tail], len); 133 + userio->tail = (userio->tail + len) % USERIO_BUFSIZE; 134 + } 135 + 136 + *copylen = len; 137 + return available; 138 + } 139 + 115 140 static ssize_t userio_char_read(struct file *file, char __user *user_buffer, 116 141 size_t count, loff_t *ppos) 117 142 { 118 143 struct userio_device *userio = file->private_data; 119 144 int error; 120 - size_t nonwrap_len, copylen; 121 - unsigned char buf[USERIO_BUFSIZE]; 122 - unsigned long flags; 145 + size_t available, copylen; 146 + u8 buf[USERIO_BUFSIZE]; 123 147 124 148 /* 125 149 * By the time we get here, the data that was waiting might have ··· 147 135 * of course). 148 136 */ 149 137 for (;;) { 150 - spin_lock_irqsave(&userio->buf_lock, flags); 151 - 152 - nonwrap_len = CIRC_CNT_TO_END(userio->head, 153 - userio->tail, 154 - USERIO_BUFSIZE); 155 - copylen = min(nonwrap_len, count); 156 - if (copylen) { 157 - memcpy(buf, &userio->buf[userio->tail], copylen); 158 - userio->tail = (userio->tail + copylen) % 159 - USERIO_BUFSIZE; 160 - } 161 - 162 - spin_unlock_irqrestore(&userio->buf_lock, flags); 163 - 164 - if (nonwrap_len) 138 + available = userio_fetch_data(userio, buf, count, &copylen); 139 + if (available) 165 140 break; 166 141 167 142 /* buffer was/is empty */ ··· 175 176 return copylen; 176 177 } 177 178 179 + static int userio_execute_cmd(struct userio_device *userio, 180 + const struct userio_cmd *cmd) 181 + { 182 + switch (cmd->type) { 183 + case USERIO_CMD_REGISTER: 184 + if (!userio->serio->id.type) { 185 + dev_warn(userio_misc.this_device, 186 + "No port type given on /dev/userio\n"); 187 + return -EINVAL; 188 + } 189 + 190 + if (userio->running) { 191 + dev_warn(userio_misc.this_device, 192 + "Begin command sent, but we're already running\n"); 193 + return -EBUSY; 194 + } 195 + 196 + userio->running = true; 197 + serio_register_port(userio->serio); 198 + break; 199 + 200 + case USERIO_CMD_SET_PORT_TYPE: 201 + if (userio->running) { 202 + dev_warn(userio_misc.this_device, 203 + "Can't change port type on an already running userio instance\n"); 204 + return -EBUSY; 205 + } 206 + 207 + userio->serio->id.type = cmd->data; 208 + break; 209 + 210 + case USERIO_CMD_SEND_INTERRUPT: 211 + if (!userio->running) { 212 + dev_warn(userio_misc.this_device, 213 + "The device must be registered before sending interrupts\n"); 214 + return -ENODEV; 215 + } 216 + 217 + serio_interrupt(userio->serio, cmd->data, 0); 218 + break; 219 + 220 + default: 221 + return -EOPNOTSUPP; 222 + } 223 + 224 + return 0; 225 + } 226 + 178 227 static ssize_t userio_char_write(struct file *file, const char __user *buffer, 179 228 size_t count, loff_t *ppos) 180 229 { ··· 238 191 if (copy_from_user(&cmd, buffer, sizeof(cmd))) 239 192 return -EFAULT; 240 193 241 - error = mutex_lock_interruptible(&userio->mutex); 242 - if (error) 243 - return error; 244 - 245 - switch (cmd.type) { 246 - case USERIO_CMD_REGISTER: 247 - if (!userio->serio->id.type) { 248 - dev_warn(userio_misc.this_device, 249 - "No port type given on /dev/userio\n"); 250 - 251 - error = -EINVAL; 252 - goto out; 253 - } 254 - 255 - if (userio->running) { 256 - dev_warn(userio_misc.this_device, 257 - "Begin command sent, but we're already running\n"); 258 - error = -EBUSY; 259 - goto out; 260 - } 261 - 262 - userio->running = true; 263 - serio_register_port(userio->serio); 264 - break; 265 - 266 - case USERIO_CMD_SET_PORT_TYPE: 267 - if (userio->running) { 268 - dev_warn(userio_misc.this_device, 269 - "Can't change port type on an already running userio instance\n"); 270 - error = -EBUSY; 271 - goto out; 272 - } 273 - 274 - userio->serio->id.type = cmd.data; 275 - break; 276 - 277 - case USERIO_CMD_SEND_INTERRUPT: 278 - if (!userio->running) { 279 - dev_warn(userio_misc.this_device, 280 - "The device must be registered before sending interrupts\n"); 281 - error = -ENODEV; 282 - goto out; 283 - } 284 - 285 - serio_interrupt(userio->serio, cmd.data, 0); 286 - break; 287 - 288 - default: 289 - error = -EOPNOTSUPP; 290 - goto out; 194 + scoped_cond_guard(mutex_intr, return -EINTR, &userio->mutex) { 195 + error = userio_execute_cmd(userio, &cmd); 196 + if (error) 197 + return error; 291 198 } 292 199 293 - out: 294 - mutex_unlock(&userio->mutex); 295 - return error ?: count; 200 + return count; 296 201 } 297 202 298 203 static __poll_t userio_char_poll(struct file *file, poll_table *wait)
+6 -11
drivers/input/serio/xilinx_ps2.c
··· 155 155 static int sxps2_write(struct serio *pserio, unsigned char c) 156 156 { 157 157 struct xps2data *drvdata = pserio->port_data; 158 - unsigned long flags; 159 158 u32 sr; 160 - int status = -1; 161 159 162 - spin_lock_irqsave(&drvdata->lock, flags); 160 + guard(spinlock_irqsave)(&drvdata->lock); 163 161 164 162 /* If the PS/2 transmitter is empty send a byte of data */ 165 163 sr = in_be32(drvdata->base_address + XPS2_STATUS_OFFSET); 166 - if (!(sr & XPS2_STATUS_TX_FULL)) { 167 - out_be32(drvdata->base_address + XPS2_TX_DATA_OFFSET, c); 168 - status = 0; 169 - } 164 + if (sr & XPS2_STATUS_TX_FULL) 165 + return -EAGAIN; 170 166 171 - spin_unlock_irqrestore(&drvdata->lock, flags); 172 - 173 - return status; 167 + out_be32(drvdata->base_address + XPS2_TX_DATA_OFFSET, c); 168 + return 0; 174 169 } 175 170 176 171 /** ··· 353 358 .of_match_table = xps2_of_match, 354 359 }, 355 360 .probe = xps2_of_probe, 356 - .remove_new = xps2_of_remove, 361 + .remove = xps2_of_remove, 357 362 }; 358 363 module_platform_driver(xps2_of_driver); 359 364
+49 -39
drivers/input/tablet/pegasus_notetaker.c
··· 214 214 error); 215 215 } 216 216 217 + static int __pegasus_open(struct pegasus *pegasus) 218 + { 219 + int error; 220 + 221 + guard(mutex)(&pegasus->pm_mutex); 222 + 223 + pegasus->irq->dev = pegasus->usbdev; 224 + if (usb_submit_urb(pegasus->irq, GFP_KERNEL)) 225 + return -EIO; 226 + 227 + error = pegasus_set_mode(pegasus, PEN_MODE_XY, NOTETAKER_LED_MOUSE); 228 + if (error) { 229 + usb_kill_urb(pegasus->irq); 230 + cancel_work_sync(&pegasus->init); 231 + return error; 232 + } 233 + 234 + pegasus->is_open = true; 235 + 236 + return 0; 237 + } 238 + 217 239 static int pegasus_open(struct input_dev *dev) 218 240 { 219 241 struct pegasus *pegasus = input_get_drvdata(dev); ··· 245 223 if (error) 246 224 return error; 247 225 248 - mutex_lock(&pegasus->pm_mutex); 249 - pegasus->irq->dev = pegasus->usbdev; 250 - if (usb_submit_urb(pegasus->irq, GFP_KERNEL)) { 251 - error = -EIO; 252 - goto err_autopm_put; 226 + error = __pegasus_open(pegasus); 227 + if (error) { 228 + usb_autopm_put_interface(pegasus->intf); 229 + return error; 253 230 } 254 231 255 - error = pegasus_set_mode(pegasus, PEN_MODE_XY, NOTETAKER_LED_MOUSE); 256 - if (error) 257 - goto err_kill_urb; 258 - 259 - pegasus->is_open = true; 260 - mutex_unlock(&pegasus->pm_mutex); 261 232 return 0; 262 - 263 - err_kill_urb: 264 - usb_kill_urb(pegasus->irq); 265 - cancel_work_sync(&pegasus->init); 266 - err_autopm_put: 267 - mutex_unlock(&pegasus->pm_mutex); 268 - usb_autopm_put_interface(pegasus->intf); 269 - return error; 270 233 } 271 234 272 235 static void pegasus_close(struct input_dev *dev) 273 236 { 274 237 struct pegasus *pegasus = input_get_drvdata(dev); 275 238 276 - mutex_lock(&pegasus->pm_mutex); 277 - usb_kill_urb(pegasus->irq); 278 - cancel_work_sync(&pegasus->init); 279 - pegasus->is_open = false; 280 - mutex_unlock(&pegasus->pm_mutex); 239 + scoped_guard(mutex, &pegasus->pm_mutex) { 240 + usb_kill_urb(pegasus->irq); 241 + cancel_work_sync(&pegasus->init); 242 + 243 + pegasus->is_open = false; 244 + } 281 245 282 246 usb_autopm_put_interface(pegasus->intf); 283 247 } ··· 419 411 { 420 412 struct pegasus *pegasus = usb_get_intfdata(intf); 421 413 422 - mutex_lock(&pegasus->pm_mutex); 414 + guard(mutex)(&pegasus->pm_mutex); 415 + 423 416 usb_kill_urb(pegasus->irq); 424 417 cancel_work_sync(&pegasus->init); 425 - mutex_unlock(&pegasus->pm_mutex); 426 418 427 419 return 0; 428 420 } ··· 430 422 static int pegasus_resume(struct usb_interface *intf) 431 423 { 432 424 struct pegasus *pegasus = usb_get_intfdata(intf); 433 - int retval = 0; 434 425 435 - mutex_lock(&pegasus->pm_mutex); 426 + guard(mutex)(&pegasus->pm_mutex); 427 + 436 428 if (pegasus->is_open && usb_submit_urb(pegasus->irq, GFP_NOIO) < 0) 437 - retval = -EIO; 438 - mutex_unlock(&pegasus->pm_mutex); 429 + return -EIO; 439 430 440 - return retval; 431 + return 0; 441 432 } 442 433 443 434 static int pegasus_reset_resume(struct usb_interface *intf) 444 435 { 445 436 struct pegasus *pegasus = usb_get_intfdata(intf); 446 - int retval = 0; 437 + int error; 447 438 448 - mutex_lock(&pegasus->pm_mutex); 439 + guard(mutex)(&pegasus->pm_mutex); 440 + 449 441 if (pegasus->is_open) { 450 - retval = pegasus_set_mode(pegasus, PEN_MODE_XY, 442 + error = pegasus_set_mode(pegasus, PEN_MODE_XY, 451 443 NOTETAKER_LED_MOUSE); 452 - if (!retval && usb_submit_urb(pegasus->irq, GFP_NOIO) < 0) 453 - retval = -EIO; 454 - } 455 - mutex_unlock(&pegasus->pm_mutex); 444 + if (error) 445 + return error; 456 446 457 - return retval; 447 + if (usb_submit_urb(pegasus->irq, GFP_NOIO) < 0) 448 + return -EIO; 449 + } 450 + 451 + return 0; 458 452 } 459 453 460 454 static const struct usb_device_id pegasus_ids[] = {
+7 -13
drivers/input/touchscreen/88pm860x-ts.c
··· 117 117 struct pm860x_chip *chip, 118 118 int *res_x) 119 119 { 120 - struct device_node *np = pdev->dev.parent->of_node; 121 120 struct i2c_client *i2c = (chip->id == CHIP_PM8607) ? chip->client \ 122 121 : chip->companion; 123 122 int data, n, ret; 124 - if (!np) 123 + if (!pdev->dev.parent->of_node) 125 124 return -ENODEV; 126 - np = of_get_child_by_name(np, "touch"); 125 + 126 + struct device_node *np __free(device_node) = 127 + of_get_child_by_name(pdev->dev.parent->of_node, "touch"); 127 128 if (!np) { 128 129 dev_err(&pdev->dev, "Can't find touch node\n"); 129 130 return -EINVAL; ··· 142 141 if (data) { 143 142 ret = pm860x_reg_write(i2c, PM8607_GPADC_MISC1, data); 144 143 if (ret < 0) 145 - goto err_put_node; 144 + return -EINVAL; 146 145 } 147 146 /* set tsi prebias time */ 148 147 if (!of_property_read_u32(np, "marvell,88pm860x-tsi-prebias", &data)) { 149 148 ret = pm860x_reg_write(i2c, PM8607_TSI_PREBIAS, data); 150 149 if (ret < 0) 151 - goto err_put_node; 150 + return -EINVAL; 152 151 } 153 152 /* set prebias & prechg time of pen detect */ 154 153 data = 0; ··· 159 158 if (data) { 160 159 ret = pm860x_reg_write(i2c, PM8607_PD_PREBIAS, data); 161 160 if (ret < 0) 162 - goto err_put_node; 161 + return -EINVAL; 163 162 } 164 163 of_property_read_u32(np, "marvell,88pm860x-resistor-X", res_x); 165 164 166 - of_node_put(np); 167 - 168 165 return 0; 169 - 170 - err_put_node: 171 - of_node_put(np); 172 - 173 - return -EINVAL; 174 166 } 175 167 #else 176 168 #define pm860x_touch_dt_init(x, y, z) (-1)
+2
drivers/input/touchscreen/Kconfig
··· 420 420 config TOUCHSCREEN_HIDEEP 421 421 tristate "HiDeep Touch IC" 422 422 depends on I2C 423 + select REGMAP_I2C 423 424 help 424 425 Say Y here if you have a touchscreen using HiDeep. 425 426 ··· 432 431 config TOUCHSCREEN_HYCON_HY46XX 433 432 tristate "Hycon hy46xx touchscreen support" 434 433 depends on I2C 434 + select REGMAP_I2C 435 435 help 436 436 Say Y here if you have a touchscreen using Hycon hy46xx 437 437
+12 -2
drivers/input/touchscreen/ads7846.c
··· 331 331 u8 ref_off; 332 332 u16 scratch; 333 333 struct spi_message msg; 334 - struct spi_transfer xfer[6]; 334 + struct spi_transfer xfer[8]; 335 335 /* 336 336 * DMA (thus cache coherency maintenance) requires the 337 337 * transfer buffers to live in their own cache lines. ··· 405 405 406 406 req->xfer[5].rx_buf = &req->scratch; 407 407 req->xfer[5].len = 2; 408 - CS_CHANGE(req->xfer[5]); 409 408 spi_message_add_tail(&req->xfer[5], &req->msg); 409 + 410 + /* clear the command register */ 411 + req->scratch = 0; 412 + req->xfer[6].tx_buf = &req->scratch; 413 + req->xfer[6].len = 1; 414 + spi_message_add_tail(&req->xfer[6], &req->msg); 415 + 416 + req->xfer[7].rx_buf = &req->scratch; 417 + req->xfer[7].len = 2; 418 + CS_CHANGE(req->xfer[7]); 419 + spi_message_add_tail(&req->xfer[7], &req->msg); 410 420 411 421 mutex_lock(&ts->lock); 412 422 ads7846_stop(ts);
+1 -1
drivers/input/touchscreen/auo-pixcir-ts.c
··· 72 72 73 73 /* 74 74 * Interrupt modes: 75 - * periodical: interrupt is asserted periodicaly 75 + * periodical: interrupt is asserted periodically 76 76 * compare coordinates: interrupt is asserted when coordinates change 77 77 * indicate touch: interrupt is asserted during touch 78 78 */
+1 -1
drivers/input/touchscreen/bcm_iproc_tsc.c
··· 217 217 "pen up-down (%d)\n", priv->pen_status); 218 218 } 219 219 220 - /* coordinates in FIFO exceed the theshold */ 220 + /* coordinates in FIFO exceed the threshold */ 221 221 if (intr_status & TS_FIFO_INTR_MASK) { 222 222 for (i = 0; i < priv->cfg_params.fifo_threshold; i++) { 223 223 regmap_read(priv->regmap, FIFO_DATA, &raw_coordinate);
+1 -1
drivers/input/touchscreen/da9052_tsi.c
··· 326 326 327 327 static struct platform_driver da9052_tsi_driver = { 328 328 .probe = da9052_ts_probe, 329 - .remove_new = da9052_ts_remove, 329 + .remove = da9052_ts_remove, 330 330 .driver = { 331 331 .name = "da9052-tsi", 332 332 },
+1 -1
drivers/input/touchscreen/edt-ft5x06.c
··· 1237 1237 } 1238 1238 1239 1239 /* 1240 - * Check which sleep modes we can support. Power-off requieres the 1240 + * Check which sleep modes we can support. Power-off requires the 1241 1241 * reset-pin to ensure correct power-down/power-up behaviour. Start with 1242 1242 * the EDT_PMODE_POWEROFF test since this is the deepest possible sleep 1243 1243 * mode.
+4 -4
drivers/input/touchscreen/elo.c
··· 225 225 226 226 mutex_lock(&elo->cmd_mutex); 227 227 228 - serio_pause_rx(elo->serio); 229 - elo->expected_packet = toupper(packet[0]); 230 - init_completion(&elo->cmd_done); 231 - serio_continue_rx(elo->serio); 228 + scoped_guard(serio_pause_rx, elo->serio) { 229 + elo->expected_packet = toupper(packet[0]); 230 + init_completion(&elo->cmd_done); 231 + } 232 232 233 233 if (serio_write(elo->serio, ELO10_LEAD_BYTE)) 234 234 goto out;
+1 -1
drivers/input/touchscreen/ili210x.c
··· 898 898 if (attr == &dev_attr_calibrate.attr) 899 899 return priv->chip->has_calibrate_reg ? attr->mode : 0; 900 900 901 - /* Firmware/Kernel/Protocol/BootMode is implememted only for ILI251x */ 901 + /* Firmware/Kernel/Protocol/BootMode is implemented only for ILI251x */ 902 902 if (!priv->chip->has_firmware_proto) 903 903 return 0; 904 904
+1 -1
drivers/input/touchscreen/imagis.c
··· 395 395 396 396 static DEFINE_SIMPLE_DEV_PM_OPS(imagis_pm_ops, imagis_suspend, imagis_resume); 397 397 398 + #ifdef CONFIG_OF 398 399 static const struct imagis_properties imagis_3032c_data = { 399 400 .interrupt_msg_cmd = IST3038C_REG_INTR_MESSAGE, 400 401 .touch_coord_cmd = IST3038C_REG_TOUCH_COORD, ··· 428 427 .protocol_b = true, 429 428 }; 430 429 431 - #ifdef CONFIG_OF 432 430 static const struct of_device_id imagis_of_match[] = { 433 431 { .compatible = "imagis,ist3032c", .data = &imagis_3032c_data }, 434 432 { .compatible = "imagis,ist3038", .data = &imagis_3038_data },
+1 -1
drivers/input/touchscreen/mainstone-wm97xx.c
··· 261 261 262 262 static struct platform_driver mainstone_wm97xx_driver = { 263 263 .probe = mainstone_wm97xx_probe, 264 - .remove_new = mainstone_wm97xx_remove, 264 + .remove = mainstone_wm97xx_remove, 265 265 .driver = { 266 266 .name = "wm97xx-touch", 267 267 },
+1 -1
drivers/input/touchscreen/mc13783_ts.c
··· 226 226 } 227 227 228 228 static struct platform_driver mc13783_ts_driver = { 229 - .remove_new = mc13783_ts_remove, 229 + .remove = mc13783_ts_remove, 230 230 .driver = { 231 231 .name = MC13783_TS_NAME, 232 232 },
+61 -6
drivers/input/touchscreen/novatek-nvt-ts.c
··· 31 31 #define NVT_TS_PARAMS_CHIP_ID 0x0e 32 32 #define NVT_TS_PARAMS_SIZE 0x0f 33 33 34 - #define NVT_TS_SUPPORTED_WAKE_TYPE 0x05 35 - #define NVT_TS_SUPPORTED_CHIP_ID 0x05 36 - 37 34 #define NVT_TS_MAX_TOUCHES 10 38 35 #define NVT_TS_MAX_SIZE 4096 39 36 ··· 48 51 IRQF_TRIGGER_HIGH 49 52 }; 50 53 54 + struct nvt_ts_i2c_chip_data { 55 + u8 wake_type; 56 + u8 chip_id; 57 + }; 58 + 51 59 struct nvt_ts_data { 52 60 struct i2c_client *client; 53 61 struct input_dev *input; 54 62 struct gpio_desc *reset_gpio; 63 + struct regulator_bulk_data regulators[2]; 55 64 struct touchscreen_properties prop; 56 65 int max_touches; 57 66 u8 buf[NVT_TS_TOUCH_SIZE * NVT_TS_MAX_TOUCHES]; ··· 145 142 static int nvt_ts_start(struct input_dev *dev) 146 143 { 147 144 struct nvt_ts_data *data = input_get_drvdata(dev); 145 + int error; 146 + 147 + error = regulator_bulk_enable(ARRAY_SIZE(data->regulators), data->regulators); 148 + if (error) { 149 + dev_err(&data->client->dev, "failed to enable regulators\n"); 150 + return error; 151 + } 148 152 149 153 enable_irq(data->client->irq); 150 154 gpiod_set_value_cansleep(data->reset_gpio, 0); ··· 165 155 166 156 disable_irq(data->client->irq); 167 157 gpiod_set_value_cansleep(data->reset_gpio, 1); 158 + regulator_bulk_disable(ARRAY_SIZE(data->regulators), data->regulators); 168 159 } 169 160 170 161 static int nvt_ts_suspend(struct device *dev) ··· 199 188 struct device *dev = &client->dev; 200 189 int error, width, height, irq_type; 201 190 struct nvt_ts_data *data; 191 + const struct nvt_ts_i2c_chip_data *chip; 202 192 struct input_dev *input; 203 193 204 194 if (!client->irq) { ··· 211 199 if (!data) 212 200 return -ENOMEM; 213 201 202 + chip = device_get_match_data(&client->dev); 203 + if (!chip) 204 + return -EINVAL; 205 + 214 206 data->client = client; 215 207 i2c_set_clientdata(client, data); 208 + 209 + /* 210 + * VCC is the analog voltage supply 211 + * IOVCC is the digital voltage supply 212 + */ 213 + data->regulators[0].supply = "vcc"; 214 + data->regulators[1].supply = "iovcc"; 215 + error = devm_regulator_bulk_get(dev, ARRAY_SIZE(data->regulators), data->regulators); 216 + if (error) { 217 + dev_err(dev, "cannot get regulators: %d\n", error); 218 + return error; 219 + } 220 + 221 + error = regulator_bulk_enable(ARRAY_SIZE(data->regulators), data->regulators); 222 + if (error) { 223 + dev_err(dev, "failed to enable regulators: %d\n", error); 224 + return error; 225 + } 216 226 217 227 data->reset_gpio = devm_gpiod_get(dev, "reset", GPIOD_OUT_LOW); 218 228 error = PTR_ERR_OR_ZERO(data->reset_gpio); 219 229 if (error) { 230 + regulator_bulk_disable(ARRAY_SIZE(data->regulators), data->regulators); 220 231 dev_err(dev, "failed to request reset GPIO: %d\n", error); 221 232 return error; 222 233 } ··· 249 214 error = nvt_ts_read_data(data->client, NVT_TS_PARAMETERS_START, 250 215 data->buf, NVT_TS_PARAMS_SIZE); 251 216 gpiod_set_value_cansleep(data->reset_gpio, 1); /* Put back in reset */ 217 + regulator_bulk_disable(ARRAY_SIZE(data->regulators), data->regulators); 252 218 if (error) 253 219 return error; 254 220 ··· 261 225 if (width > NVT_TS_MAX_SIZE || height >= NVT_TS_MAX_SIZE || 262 226 data->max_touches > NVT_TS_MAX_TOUCHES || 263 227 irq_type >= ARRAY_SIZE(nvt_ts_irq_type) || 264 - data->buf[NVT_TS_PARAMS_WAKE_TYPE] != NVT_TS_SUPPORTED_WAKE_TYPE || 265 - data->buf[NVT_TS_PARAMS_CHIP_ID] != NVT_TS_SUPPORTED_CHIP_ID) { 228 + data->buf[NVT_TS_PARAMS_WAKE_TYPE] != chip->wake_type || 229 + data->buf[NVT_TS_PARAMS_CHIP_ID] != chip->chip_id) { 266 230 dev_err(dev, "Unsupported touchscreen parameters: %*ph\n", 267 231 NVT_TS_PARAMS_SIZE, data->buf); 268 232 return -EIO; ··· 313 277 return 0; 314 278 } 315 279 280 + static const struct nvt_ts_i2c_chip_data nvt_nt11205_ts_data = { 281 + .wake_type = 0x05, 282 + .chip_id = 0x05, 283 + }; 284 + 285 + static const struct nvt_ts_i2c_chip_data nvt_nt36672a_ts_data = { 286 + .wake_type = 0x01, 287 + .chip_id = 0x08, 288 + }; 289 + 290 + static const struct of_device_id nvt_ts_of_match[] = { 291 + { .compatible = "novatek,nt11205-ts", .data = &nvt_nt11205_ts_data }, 292 + { .compatible = "novatek,nt36672a-ts", .data = &nvt_nt36672a_ts_data }, 293 + { } 294 + }; 295 + MODULE_DEVICE_TABLE(of, nvt_ts_of_match); 296 + 316 297 static const struct i2c_device_id nvt_ts_i2c_id[] = { 317 - { "NVT-ts" }, 298 + { "nt11205-ts", (unsigned long) &nvt_nt11205_ts_data }, 299 + { "nt36672a-ts", (unsigned long) &nvt_nt36672a_ts_data }, 318 300 { } 319 301 }; 320 302 MODULE_DEVICE_TABLE(i2c, nvt_ts_i2c_id); ··· 341 287 .driver = { 342 288 .name = "novatek-nvt-ts", 343 289 .pm = pm_sleep_ptr(&nvt_ts_pm_ops), 290 + .of_match_table = nvt_ts_of_match, 344 291 }, 345 292 .probe = nvt_ts_probe, 346 293 .id_table = nvt_ts_i2c_id,
+1 -1
drivers/input/touchscreen/pcap_ts.c
··· 238 238 239 239 static struct platform_driver pcap_ts_driver = { 240 240 .probe = pcap_ts_probe, 241 - .remove_new = pcap_ts_remove, 241 + .remove = pcap_ts_remove, 242 242 .driver = { 243 243 .name = "pcap-ts", 244 244 .pm = PCAP_TS_PM_OPS,
+1 -1
drivers/input/touchscreen/pixcir_i2c_ts.c
··· 44 44 45 45 /* 46 46 * Interrupt modes: 47 - * periodical: interrupt is asserted periodicaly 47 + * periodical: interrupt is asserted periodically 48 48 * diff coordinates: interrupt is asserted when coordinates change 49 49 * level on touch: interrupt level asserted during touch 50 50 * pulse on touch: interrupt pulse asserted during touch
+1 -3
drivers/input/touchscreen/raspberrypi-ts.c
··· 122 122 struct device *dev = &pdev->dev; 123 123 struct device_node *np = dev->of_node; 124 124 struct input_dev *input; 125 - struct device_node *fw_node; 126 125 struct rpi_firmware *fw; 127 126 struct rpi_ts *ts; 128 127 u32 touchbuf; 129 128 int error; 130 129 131 - fw_node = of_get_parent(np); 130 + struct device_node *fw_node __free(device_node) = of_get_parent(np); 132 131 if (!fw_node) { 133 132 dev_err(dev, "Missing firmware node\n"); 134 133 return -ENOENT; 135 134 } 136 135 137 136 fw = devm_rpi_firmware_get(&pdev->dev, fw_node); 138 - of_node_put(fw_node); 139 137 if (!fw) 140 138 return -EPROBE_DEFER; 141 139
+2 -2
drivers/input/touchscreen/rohm_bu21023.c
··· 388 388 err_y = (int)READ_CALIB_BUF(PRM1_Y_H) << 2 | 389 389 READ_CALIB_BUF(PRM1_Y_L); 390 390 391 - /* X axis ajust */ 391 + /* X axis adjust */ 392 392 if (err_x <= 4) 393 393 calib_x -= AXIS_ADJUST; 394 394 else if (err_x >= 60) 395 395 calib_x += AXIS_ADJUST; 396 396 397 - /* Y axis ajust */ 397 + /* Y axis adjust */ 398 398 if (err_y <= 4) 399 399 calib_y -= AXIS_ADJUST; 400 400 else if (err_y >= 60)
+3 -3
drivers/input/touchscreen/stmpe-ts.c
··· 107 107 108 108 /* 109 109 * touch_det sometimes get desasserted or just get stuck. This appears 110 - * to be a silicon bug, We still have to clearify this with the 110 + * to be a silicon bug, We still have to clarify this with the 111 111 * manufacture. As a workaround We release the key anyway if the 112 112 * touch_det keeps coming in after 4ms, while the FIFO contains no value 113 113 * during the whole time. ··· 140 140 141 141 /* 142 142 * The FIFO sometimes just crashes and stops generating interrupts. This 143 - * appears to be a silicon bug. We still have to clearify this with 143 + * appears to be a silicon bug. We still have to clarify this with 144 144 * the manufacture. As a workaround we disable the TSC while we are 145 145 * collecting data and flush the FIFO after reading 146 146 */ ··· 362 362 .name = STMPE_TS_NAME, 363 363 }, 364 364 .probe = stmpe_input_probe, 365 - .remove_new = stmpe_ts_remove, 365 + .remove = stmpe_ts_remove, 366 366 }; 367 367 module_platform_driver(stmpe_ts_driver); 368 368
+2 -2
drivers/input/touchscreen/sun4i-ts.c
··· 396 396 MODULE_DEVICE_TABLE(of, sun4i_ts_of_match); 397 397 398 398 static struct platform_driver sun4i_ts_driver = { 399 - .driver = { 399 + .driver = { 400 400 .name = "sun4i-ts", 401 401 .of_match_table = sun4i_ts_of_match, 402 402 }, 403 403 .probe = sun4i_ts_probe, 404 - .remove_new = sun4i_ts_remove, 404 + .remove = sun4i_ts_remove, 405 405 }; 406 406 407 407 module_platform_driver(sun4i_ts_driver);
+2 -2
drivers/input/touchscreen/ti_am335x_tsc.c
··· 550 550 551 551 static struct platform_driver ti_tsc_driver = { 552 552 .probe = titsc_probe, 553 - .remove_new = titsc_remove, 553 + .remove = titsc_remove, 554 554 .driver = { 555 - .name = "TI-am335x-tsc", 555 + .name = "TI-am335x-tsc", 556 556 .pm = pm_sleep_ptr(&titsc_pm_ops), 557 557 .of_match_table = ti_tsc_dt_ids, 558 558 },
+2 -3
drivers/input/touchscreen/ts4800-ts.c
··· 110 110 { 111 111 struct device *dev = &pdev->dev; 112 112 struct device_node *np = dev->of_node; 113 - struct device_node *syscon_np; 114 113 u32 reg, bit; 115 114 int error; 116 115 117 - syscon_np = of_parse_phandle(np, "syscon", 0); 116 + struct device_node *syscon_np __free(device_node) = 117 + of_parse_phandle(np, "syscon", 0); 118 118 if (!syscon_np) { 119 119 dev_err(dev, "no syscon property\n"); 120 120 return -ENODEV; 121 121 } 122 122 123 123 ts->regmap = syscon_node_to_regmap(syscon_np); 124 - of_node_put(syscon_np); 125 124 if (IS_ERR(ts->regmap)) { 126 125 dev_err(dev, "cannot get parent's regmap\n"); 127 126 return PTR_ERR(ts->regmap);
+1 -1
drivers/input/touchscreen/wm831x-ts.c
··· 387 387 .name = "wm831x-touch", 388 388 }, 389 389 .probe = wm831x_ts_probe, 390 - .remove_new = wm831x_ts_remove, 390 + .remove = wm831x_ts_remove, 391 391 }; 392 392 module_platform_driver(wm831x_ts_driver); 393 393
+3 -3
drivers/input/touchscreen/wm97xx-core.c
··· 222 222 223 223 /* 224 224 * Codec GPIO pin configuration, this sets pin direction, polarity, 225 - * stickyness and wake up. 225 + * stickiness and wake up. 226 226 */ 227 227 void wm97xx_config_gpio(struct wm97xx *wm, u32 gpio, enum wm97xx_gpio_dir dir, 228 228 enum wm97xx_gpio_pol pol, enum wm97xx_gpio_sticky sticky, ··· 403 403 * is actively working with the touchscreen we 404 404 * don't want to lose the quick response. So we 405 405 * will slowly increase sleep time after the 406 - * pen is up and quicky restore it to ~one task 406 + * pen is up and quickly restore it to ~one task 407 407 * switch when pen is down again. 408 408 */ 409 409 if (wm->ts_reader_interval < HZ / 10) ··· 876 876 .pm = pm_sleep_ptr(&wm97xx_pm_ops), 877 877 }, 878 878 .probe = wm97xx_mfd_probe, 879 - .remove_new = wm97xx_mfd_remove, 879 + .remove = wm97xx_mfd_remove, 880 880 }; 881 881 882 882 static int __init wm97xx_init(void)
+1 -1
drivers/platform/x86/x86-android-tablets/other.c
··· 41 41 { 42 42 /* Novatek NVT-ts touchscreen */ 43 43 .board_info = { 44 - .type = "NVT-ts", 44 + .type = "nt11205-ts", 45 45 .addr = 0x34, 46 46 .dev_name = "NVT-ts", 47 47 },
+5
include/linux/input.h
··· 286 286 * @start: starts handler for given handle. This function is called by 287 287 * input core right after connect() method and also when a process 288 288 * that "grabbed" a device releases it 289 + * @passive_observer: set to %true by drivers only interested in observing 290 + * data stream from devices if there are other users present. Such 291 + * drivers will not result in starting underlying hardware device 292 + * when input_open_device() is called for their handles 289 293 * @legacy_minors: set to %true by drivers using legacy minor ranges 290 294 * @minor: beginning of range of 32 legacy minors for devices this driver 291 295 * can provide ··· 325 321 void (*disconnect)(struct input_handle *handle); 326 322 void (*start)(struct input_handle *handle); 327 323 324 + bool passive_observer; 328 325 bool legacy_minors; 329 326 int minor; 330 327 const char *name;
+3
include/linux/serio.h
··· 6 6 #define _SERIO_H 7 7 8 8 9 + #include <linux/cleanup.h> 9 10 #include <linux/types.h> 10 11 #include <linux/interrupt.h> 11 12 #include <linux/list.h> ··· 161 160 { 162 161 spin_unlock_irq(&serio->lock); 163 162 } 163 + 164 + DEFINE_GUARD(serio_pause_rx, struct serio *, serio_pause_rx(_T), serio_continue_rx(_T)) 164 165 165 166 #endif