Skip to content

Commit 9ac6678

Browse files
skomraJiri Kosina
authored andcommitted
HID: wacom: remove the battery when the EKR is off
Currently the EKR battery remains even after we stop getting information from the device. This can lead to a stale battery persisting indefinitely in userspace. The remote sends a heartbeat every 10 seconds. Delete the battery if we miss two heartbeats (after 21 seconds). Restore the battery once we see a heartbeat again. Signed-off-by: Aaron Skomra <[email protected]> Signed-off-by: Aaron Armstrong Skomra <[email protected]> Reviewed-by: Jason Gerecke <[email protected]> Fixes: 9f1015d ("HID: wacom: EKR: attach the power_supply on first connection") CC: [email protected] Signed-off-by: Jiri Kosina <[email protected]>
1 parent 1d75460 commit 9ac6678

File tree

4 files changed

+24
-4
lines changed

4 files changed

+24
-4
lines changed

drivers/hid/wacom.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,7 @@ struct wacom_remote {
150150
struct input_dev *input;
151151
bool registered;
152152
struct wacom_battery battery;
153+
ktime_t active_time;
153154
} remotes[WACOM_MAX_REMOTES];
154155
};
155156

drivers/hid/wacom_sys.c

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2523,6 +2523,18 @@ static void wacom_wireless_work(struct work_struct *work)
25232523
return;
25242524
}
25252525

2526+
static void wacom_remote_destroy_battery(struct wacom *wacom, int index)
2527+
{
2528+
struct wacom_remote *remote = wacom->remote;
2529+
2530+
if (remote->remotes[index].battery.battery) {
2531+
devres_release_group(&wacom->hdev->dev,
2532+
&remote->remotes[index].battery.bat_desc);
2533+
remote->remotes[index].battery.battery = NULL;
2534+
remote->remotes[index].active_time = 0;
2535+
}
2536+
}
2537+
25262538
static void wacom_remote_destroy_one(struct wacom *wacom, unsigned int index)
25272539
{
25282540
struct wacom_remote *remote = wacom->remote;
@@ -2537,17 +2549,14 @@ static void wacom_remote_destroy_one(struct wacom *wacom, unsigned int index)
25372549
remote->remotes[i].registered = false;
25382550
spin_unlock_irqrestore(&remote->remote_lock, flags);
25392551

2540-
if (remote->remotes[i].battery.battery)
2541-
devres_release_group(&wacom->hdev->dev,
2542-
&remote->remotes[i].battery.bat_desc);
2552+
wacom_remote_destroy_battery(wacom, i);
25432553

25442554
if (remote->remotes[i].group.name)
25452555
devres_release_group(&wacom->hdev->dev,
25462556
&remote->remotes[i]);
25472557

25482558
remote->remotes[i].serial = 0;
25492559
remote->remotes[i].group.name = NULL;
2550-
remote->remotes[i].battery.battery = NULL;
25512560
wacom->led.groups[i].select = WACOM_STATUS_UNKNOWN;
25522561
}
25532562
}
@@ -2632,6 +2641,9 @@ static int wacom_remote_attach_battery(struct wacom *wacom, int index)
26322641
if (remote->remotes[index].battery.battery)
26332642
return 0;
26342643

2644+
if (!remote->remotes[index].active_time)
2645+
return 0;
2646+
26352647
if (wacom->led.groups[index].select == WACOM_STATUS_UNKNOWN)
26362648
return 0;
26372649

@@ -2647,6 +2659,7 @@ static void wacom_remote_work(struct work_struct *work)
26472659
{
26482660
struct wacom *wacom = container_of(work, struct wacom, remote_work);
26492661
struct wacom_remote *remote = wacom->remote;
2662+
ktime_t kt = ktime_get();
26502663
struct wacom_remote_data data;
26512664
unsigned long flags;
26522665
unsigned int count;
@@ -2673,6 +2686,10 @@ static void wacom_remote_work(struct work_struct *work)
26732686
serial = data.remote[i].serial;
26742687
if (data.remote[i].connected) {
26752688

2689+
if (kt - remote->remotes[i].active_time > WACOM_REMOTE_BATTERY_TIMEOUT
2690+
&& remote->remotes[i].active_time != 0)
2691+
wacom_remote_destroy_battery(wacom, i);
2692+
26762693
if (remote->remotes[i].serial == serial) {
26772694
wacom_remote_attach_battery(wacom, i);
26782695
continue;

drivers/hid/wacom_wac.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1134,6 +1134,7 @@ static int wacom_remote_irq(struct wacom_wac *wacom_wac, size_t len)
11341134
if (index < 0 || !remote->remotes[index].registered)
11351135
goto out;
11361136

1137+
remote->remotes[i].active_time = ktime_get();
11371138
input = remote->remotes[index].input;
11381139

11391140
input_report_key(input, BTN_0, (data[9] & 0x01));

drivers/hid/wacom_wac.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#define WACOM_NAME_MAX 64
1414
#define WACOM_MAX_REMOTES 5
1515
#define WACOM_STATUS_UNKNOWN 255
16+
#define WACOM_REMOTE_BATTERY_TIMEOUT 21000000000ll
1617

1718
/* packet length for individual models */
1819
#define WACOM_PKGLEN_BBFUN 9

0 commit comments

Comments
 (0)