Commit 04bfa27b authored by Benjamin Tissoires's avatar Benjamin Tissoires Committed by Jiri Kosina

HID: wacom: EKR: have proper allocator and destructor

The wacom_remote_create_attr_group() and wacom_remote_destroy_attr_group()
functions were both allocating/destroying the sysfs groups but also
initializing the parameters for the remotes. Have proper functions
that can be called and extended.
Signed-off-by: default avatarBenjamin Tissoires <benjamin.tissoires@redhat.com>
Acked-by: default avatarPing Cheng <pingc@wacom.com>
Signed-off-by: default avatarJiri Kosina <jkosina@suse.cz>
parent 3888b0d5
...@@ -1300,8 +1300,6 @@ static int wacom_remote_create_attr_group(struct wacom *wacom, __u32 serial, ...@@ -1300,8 +1300,6 @@ static int wacom_remote_create_attr_group(struct wacom *wacom, __u32 serial,
int error = 0; int error = 0;
struct wacom_remote *remote = wacom->remote; struct wacom_remote *remote = wacom->remote;
remote->serial[index] = serial;
remote->remote_group[index].name = devm_kasprintf(&wacom->hdev->dev, remote->remote_group[index].name = devm_kasprintf(&wacom->hdev->dev,
GFP_KERNEL, GFP_KERNEL,
"%d", serial); "%d", serial);
...@@ -1319,27 +1317,13 @@ static int wacom_remote_create_attr_group(struct wacom *wacom, __u32 serial, ...@@ -1319,27 +1317,13 @@ static int wacom_remote_create_attr_group(struct wacom *wacom, __u32 serial,
return 0; return 0;
} }
static void wacom_remote_destroy_attr_group(struct wacom *wacom, __u32 serial) static void wacom_remote_destroy_attr_group(struct wacom *wacom, unsigned int i)
{ {
struct wacom_remote *remote = wacom->remote; struct wacom_remote *remote = wacom->remote;
int i;
if (!serial) sysfs_remove_group(remote->remote_dir, &remote->remote_group[i]);
return; devm_kfree(&wacom->hdev->dev, (char *)remote->remote_group[i].name);
remote->remote_group[i].name = NULL;
for (i = 0; i < WACOM_MAX_REMOTES; i++) {
if (remote->serial[i] == serial) {
remote->serial[i] = 0;
wacom->led.groups[i].select = WACOM_STATUS_UNKNOWN;
if (remote->remote_group[i].name) {
sysfs_remove_group(remote->remote_dir,
&remote->remote_group[i]);
devm_kfree(&wacom->hdev->dev,
(char *)remote->remote_group[i].name);
remote->remote_group[i].name = NULL;
}
}
}
} }
static int wacom_cmd_unpair_remote(struct wacom *wacom, unsigned char selector) static int wacom_cmd_unpair_remote(struct wacom *wacom, unsigned char selector)
...@@ -1916,6 +1900,50 @@ static void wacom_wireless_work(struct work_struct *work) ...@@ -1916,6 +1900,50 @@ static void wacom_wireless_work(struct work_struct *work)
return; return;
} }
static void wacom_remote_destroy_one(struct wacom *wacom, unsigned int index)
{
struct wacom_remote *remote = wacom->remote;
u32 serial = remote->serial[index];
int i;
wacom_remote_destroy_attr_group(wacom, index);
for (i = 0; i < WACOM_MAX_REMOTES; i++) {
if (remote->serial[i] == serial) {
remote->serial[i] = 0;
wacom->led.groups[i].select = WACOM_STATUS_UNKNOWN;
}
}
}
static int wacom_remote_create_one(struct wacom *wacom, u32 serial,
unsigned int index)
{
struct wacom_remote *remote = wacom->remote;
int error, k;
/* A remote can pair more than once with an EKR,
* check to make sure this serial isn't already paired.
*/
for (k = 0; k < WACOM_MAX_REMOTES; k++) {
if (remote->serial[k] == serial)
break;
}
if (k < WACOM_MAX_REMOTES) {
remote->serial[index] = serial;
return 0;
}
error = wacom_remote_create_attr_group(wacom, serial, index);
if (error)
return error;
remote->serial[index] = serial;
return 0;
}
static void wacom_remote_work(struct work_struct *work) static void wacom_remote_work(struct work_struct *work)
{ {
struct wacom *wacom = container_of(work, struct wacom, remote_work); struct wacom *wacom = container_of(work, struct wacom, remote_work);
...@@ -1924,7 +1952,7 @@ static void wacom_remote_work(struct work_struct *work) ...@@ -1924,7 +1952,7 @@ static void wacom_remote_work(struct work_struct *work)
unsigned long flags; unsigned long flags;
unsigned int count; unsigned int count;
u32 serial; u32 serial;
int i, k; int i;
spin_lock_irqsave(&remote->remote_lock, flags); spin_lock_irqsave(&remote->remote_lock, flags);
...@@ -1949,28 +1977,13 @@ static void wacom_remote_work(struct work_struct *work) ...@@ -1949,28 +1977,13 @@ static void wacom_remote_work(struct work_struct *work)
if (remote->serial[i] == serial) if (remote->serial[i] == serial)
continue; continue;
if (remote->serial[i]) { if (remote->serial[i])
wacom_remote_destroy_attr_group(wacom, wacom_remote_destroy_one(wacom, i);
remote->serial[i]);
}
/* A remote can pair more than once with an EKR,
* check to make sure this serial isn't already paired.
*/
for (k = 0; k < WACOM_MAX_REMOTES; k++) {
if (remote->serial[k] == serial)
break;
}
if (k < WACOM_MAX_REMOTES) { wacom_remote_create_one(wacom, serial, i);
remote->serial[i] = serial;
continue;
}
wacom_remote_create_attr_group(wacom, serial, i);
} else if (remote->serial[i]) { } else if (remote->serial[i]) {
wacom_remote_destroy_attr_group(wacom, wacom_remote_destroy_one(wacom, i);
remote->serial[i]);
} }
} }
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment