mirror of
https://github.com/torvalds/linux.git
synced 2026-09-22 12:44:03 +02:00
HID: sony: use guard() and scoped_guard()
This replaces the spin_lock_irqsave() and spin_unlock_irqrestore() calls with the RAII guard() and scoped_guard(). Signed-off-by: Rosalie Wanders <rosalie@mailbox.org> Signed-off-by: Jiri Kosina <jkosina@suse.com>
This commit is contained in:
parent
5acb364edd
commit
da4f817ad2
|
|
@ -29,6 +29,7 @@
|
|||
* There will be no PIN request from the device.
|
||||
*/
|
||||
|
||||
#include <linux/cleanup.h>
|
||||
#include <linux/device.h>
|
||||
#include <linux/hid.h>
|
||||
#include <linux/module.h>
|
||||
|
|
@ -571,14 +572,12 @@ static void sony_set_leds(struct sony_sc *sc);
|
|||
static inline void sony_schedule_work(struct sony_sc *sc,
|
||||
enum sony_worker which)
|
||||
{
|
||||
unsigned long flags;
|
||||
|
||||
switch (which) {
|
||||
case SONY_WORKER_STATE:
|
||||
spin_lock_irqsave(&sc->lock, flags);
|
||||
if (!sc->defer_initialization && sc->state_worker_initialized)
|
||||
schedule_work(&sc->state_worker);
|
||||
spin_unlock_irqrestore(&sc->lock, flags);
|
||||
scoped_guard(spinlock_irqsave, &sc->lock) {
|
||||
if (!sc->defer_initialization && sc->state_worker_initialized)
|
||||
schedule_work(&sc->state_worker);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
@ -951,7 +950,6 @@ static const u8 *sony_report_fixup(struct hid_device *hdev, u8 *rdesc,
|
|||
static int sixaxis_raw_event(struct sony_sc *sc, u8 *rd, int size)
|
||||
{
|
||||
static const u8 sixaxis_battery_capacity[] = { 0, 1, 25, 50, 75, 100 };
|
||||
unsigned long flags;
|
||||
int offset;
|
||||
u8 index;
|
||||
u8 battery_capacity;
|
||||
|
|
@ -999,10 +997,10 @@ static int sixaxis_raw_event(struct sony_sc *sc, u8 *rd, int size)
|
|||
battery_status = POWER_SUPPLY_STATUS_DISCHARGING;
|
||||
}
|
||||
|
||||
spin_lock_irqsave(&sc->lock, flags);
|
||||
sc->battery_capacity = battery_capacity;
|
||||
sc->battery_status = battery_status;
|
||||
spin_unlock_irqrestore(&sc->lock, flags);
|
||||
scoped_guard(spinlock_irqsave, &sc->lock) {
|
||||
sc->battery_capacity = battery_capacity;
|
||||
sc->battery_status = battery_status;
|
||||
}
|
||||
|
||||
if (sc->quirks & SIXAXIS_CONTROLLER) {
|
||||
int val;
|
||||
|
|
@ -1148,7 +1146,6 @@ static int rb4_ps5_guitar_raw_event(struct sony_sc *sc, u8 *rd, int size)
|
|||
u8 battery_data;
|
||||
u8 battery_capacity;
|
||||
u8 battery_status;
|
||||
unsigned long flags;
|
||||
|
||||
if (unlikely(size != 64 || rd[0] != 0x01))
|
||||
return 0;
|
||||
|
|
@ -1191,10 +1188,10 @@ static int rb4_ps5_guitar_raw_event(struct sony_sc *sc, u8 *rd, int size)
|
|||
break;
|
||||
}
|
||||
|
||||
spin_lock_irqsave(&sc->lock, flags);
|
||||
sc->battery_capacity = battery_capacity;
|
||||
sc->battery_status = battery_status;
|
||||
spin_unlock_irqrestore(&sc->lock, flags);
|
||||
scoped_guard(spinlock_irqsave, &sc->lock) {
|
||||
sc->battery_capacity = battery_capacity;
|
||||
sc->battery_status = battery_status;
|
||||
}
|
||||
|
||||
input_sync(sc->input_dev);
|
||||
return 0;
|
||||
|
|
@ -1885,15 +1882,14 @@ static int sony_battery_get_property(struct power_supply *psy,
|
|||
union power_supply_propval *val)
|
||||
{
|
||||
struct sony_sc *sc = power_supply_get_drvdata(psy);
|
||||
unsigned long flags;
|
||||
int ret = 0;
|
||||
u8 battery_capacity;
|
||||
int battery_status;
|
||||
|
||||
spin_lock_irqsave(&sc->lock, flags);
|
||||
battery_capacity = sc->battery_capacity;
|
||||
battery_status = sc->battery_status;
|
||||
spin_unlock_irqrestore(&sc->lock, flags);
|
||||
scoped_guard(spinlock_irqsave, &sc->lock) {
|
||||
battery_capacity = sc->battery_capacity;
|
||||
battery_status = sc->battery_status;
|
||||
}
|
||||
|
||||
switch (psp) {
|
||||
case POWER_SUPPLY_PROP_PRESENT:
|
||||
|
|
@ -1975,10 +1971,9 @@ static inline int sony_compare_connection_type(struct sony_sc *sc0,
|
|||
static int sony_check_add_dev_list(struct sony_sc *sc)
|
||||
{
|
||||
struct sony_sc *entry;
|
||||
unsigned long flags;
|
||||
int ret;
|
||||
|
||||
spin_lock_irqsave(&sony_dev_list_lock, flags);
|
||||
guard(spinlock_irqsave)(&sony_dev_list_lock);
|
||||
|
||||
list_for_each_entry(entry, &sony_device_list, list_node) {
|
||||
ret = memcmp(sc->mac_address, entry->mac_address,
|
||||
|
|
@ -1992,26 +1987,23 @@ static int sony_check_add_dev_list(struct sony_sc *sc)
|
|||
"controller with MAC address %pMR already connected\n",
|
||||
sc->mac_address);
|
||||
}
|
||||
goto unlock;
|
||||
goto out;
|
||||
}
|
||||
}
|
||||
|
||||
ret = 0;
|
||||
list_add(&(sc->list_node), &sony_device_list);
|
||||
|
||||
unlock:
|
||||
spin_unlock_irqrestore(&sony_dev_list_lock, flags);
|
||||
out:
|
||||
return ret;
|
||||
}
|
||||
|
||||
static void sony_remove_dev_list(struct sony_sc *sc)
|
||||
{
|
||||
unsigned long flags;
|
||||
|
||||
if (sc->list_node.next) {
|
||||
spin_lock_irqsave(&sony_dev_list_lock, flags);
|
||||
list_del(&(sc->list_node));
|
||||
spin_unlock_irqrestore(&sony_dev_list_lock, flags);
|
||||
scoped_guard(spinlock_irqsave, &sony_dev_list_lock) {
|
||||
list_del(&(sc->list_node));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -2145,12 +2137,10 @@ static inline void sony_init_output_report(struct sony_sc *sc,
|
|||
|
||||
static inline void sony_cancel_work_sync(struct sony_sc *sc)
|
||||
{
|
||||
unsigned long flags;
|
||||
|
||||
if (sc->state_worker_initialized) {
|
||||
spin_lock_irqsave(&sc->lock, flags);
|
||||
sc->state_worker_initialized = 0;
|
||||
spin_unlock_irqrestore(&sc->lock, flags);
|
||||
scoped_guard(spinlock_irqsave, &sc->lock) {
|
||||
sc->state_worker_initialized = 0;
|
||||
}
|
||||
cancel_work_sync(&sc->state_worker);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user