Commit 505d2ad2 authored by Szymon Janc's avatar Szymon Janc Committed by Greg Kroah-Hartman

Staging: quickstart: Use list.h API for buttons list

Signed-off-by: default avatarSzymon Janc <szymon@janc.net.pl>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent 3991eae9
...@@ -55,7 +55,7 @@ MODULE_LICENSE("GPL"); ...@@ -55,7 +55,7 @@ MODULE_LICENSE("GPL");
struct quickstart_btn { struct quickstart_btn {
char *name; char *name;
unsigned int id; unsigned int id;
struct quickstart_btn *next; struct list_head list;
}; };
struct quickstart_acpi { struct quickstart_acpi {
...@@ -63,7 +63,7 @@ struct quickstart_acpi { ...@@ -63,7 +63,7 @@ struct quickstart_acpi {
struct quickstart_btn *btn; struct quickstart_btn *btn;
}; };
static struct quickstart_btn *btn_list; static LIST_HEAD(buttons);
static struct quickstart_btn *pressed; static struct quickstart_btn *pressed;
static struct input_dev *quickstart_input; static struct input_dev *quickstart_input;
...@@ -74,18 +74,19 @@ static ssize_t quickstart_buttons_show(struct device *dev, ...@@ -74,18 +74,19 @@ static ssize_t quickstart_buttons_show(struct device *dev,
char *buf) char *buf)
{ {
int count = 0; int count = 0;
struct quickstart_btn *ptr = btn_list; struct quickstart_btn *b;
if (!ptr) if (list_empty(&buttons))
return snprintf(buf, PAGE_SIZE, "none"); return snprintf(buf, PAGE_SIZE, "none");
while (ptr && (count < PAGE_SIZE)) { list_for_each_entry(b, &buttons, list) {
if (ptr->name) { count += snprintf(buf + count, PAGE_SIZE - count, "%d\t%s\n",
count += snprintf(buf + count, b->id, b->name);
PAGE_SIZE - count,
"%d\t%s\n", ptr->id, ptr->name); if (count >= PAGE_SIZE) {
count = PAGE_SIZE;
break;
} }
ptr = ptr->next;
} }
return count; return count;
...@@ -115,55 +116,35 @@ static ssize_t quickstart_pressed_button_store(struct device *dev, ...@@ -115,55 +116,35 @@ static ssize_t quickstart_pressed_button_store(struct device *dev,
} }
/* Helper functions */ /* Helper functions */
static int quickstart_btnlst_add(struct quickstart_btn **data) static struct quickstart_btn *quickstart_buttons_add(void)
{ {
struct quickstart_btn **ptr = &btn_list; struct quickstart_btn *b;
while (*ptr) b = kzalloc(sizeof(*b), GFP_KERNEL);
ptr = &((*ptr)->next); if (!b)
return NULL;
*ptr = kzalloc(sizeof(struct quickstart_btn), GFP_KERNEL); list_add_tail(&b->list, &buttons);
if (!*ptr) {
*data = NULL;
return -ENOMEM;
}
*data = *ptr;
return 0; return b;
} }
static void quickstart_btnlst_del(struct quickstart_btn *data) static void quickstart_button_del(struct quickstart_btn *data)
{ {
struct quickstart_btn **ptr = &btn_list;
if (!data) if (!data)
return; return;
while (*ptr) { list_del(&data->list);
if (*ptr == data) { kfree(data->name);
*ptr = (*ptr)->next;
kfree(data); kfree(data);
return;
}
ptr = &((*ptr)->next);
}
return;
} }
static void quickstart_btnlst_free(void) static void quickstart_buttons_free(void)
{ {
struct quickstart_btn *ptr = btn_list; struct quickstart_btn *b, *n;
struct quickstart_btn *lptr = NULL;
while (ptr) {
lptr = ptr;
ptr = ptr->next;
kfree(lptr->name);
kfree(lptr);
}
return; list_for_each_entry_safe(b, n, &buttons, list)
quickstart_button_del(b);
} }
/* ACPI Driver functions */ /* ACPI Driver functions */
...@@ -242,17 +223,16 @@ static int quickstart_acpi_config(struct quickstart_acpi *quickstart) ...@@ -242,17 +223,16 @@ static int quickstart_acpi_config(struct quickstart_acpi *quickstart)
{ {
char *bid = acpi_device_bid(quickstart->device); char *bid = acpi_device_bid(quickstart->device);
char *name; char *name;
int ret;
name = kmalloc(strlen(bid) + 1, GFP_KERNEL); name = kmalloc(strlen(bid) + 1, GFP_KERNEL);
if (!name) if (!name)
return -ENOMEM; return -ENOMEM;
/* Add button to list */ /* Add new button to list */
ret = quickstart_btnlst_add(&quickstart->btn); quickstart->btn = quickstart_buttons_add();
if (ret < 0) { if (!quickstart->btn) {
kfree(name); kfree(name);
return ret; return -ENOMEM;
} }
quickstart->btn->name = name; quickstart->btn->name = name;
...@@ -305,7 +285,7 @@ static int quickstart_acpi_add(struct acpi_device *device) ...@@ -305,7 +285,7 @@ static int quickstart_acpi_add(struct acpi_device *device)
quickstart_acpi_notify); quickstart_acpi_notify);
fail_installnotify: fail_installnotify:
quickstart_btnlst_del(quickstart->btn); quickstart_button_del(quickstart->btn);
fail_config: fail_config:
...@@ -377,13 +357,12 @@ static void quickstart_exit(void) ...@@ -377,13 +357,12 @@ static void quickstart_exit(void)
acpi_bus_unregister_driver(&quickstart_acpi_driver); acpi_bus_unregister_driver(&quickstart_acpi_driver);
quickstart_btnlst_free(); quickstart_buttons_free();
} }
static int __init quickstart_init_input(void) static int __init quickstart_init_input(void)
{ {
struct quickstart_btn **ptr = &btn_list; struct quickstart_btn *b;
int count;
int ret; int ret;
quickstart_input = input_allocate_device(); quickstart_input = input_allocate_device();
...@@ -394,11 +373,9 @@ static int __init quickstart_init_input(void) ...@@ -394,11 +373,9 @@ static int __init quickstart_init_input(void)
quickstart_input->name = "Quickstart ACPI Buttons"; quickstart_input->name = "Quickstart ACPI Buttons";
quickstart_input->id.bustype = BUS_HOST; quickstart_input->id.bustype = BUS_HOST;
while (*ptr) { list_for_each_entry(b, &buttons, list) {
count++;
set_bit(EV_KEY, quickstart_input->evbit); set_bit(EV_KEY, quickstart_input->evbit);
set_bit((*ptr)->id, quickstart_input->keybit); set_bit(b->id, quickstart_input->keybit);
ptr = &((*ptr)->next);
} }
ret = input_register_device(quickstart_input); ret = input_register_device(quickstart_input);
...@@ -424,7 +401,7 @@ static int __init quickstart_init(void) ...@@ -424,7 +401,7 @@ static int __init quickstart_init(void)
return ret; return ret;
/* If existing bus with no devices */ /* If existing bus with no devices */
if (!btn_list) { if (list_empty(&buttons)) {
ret = -ENODEV; ret = -ENODEV;
goto fail_pfdrv_reg; goto fail_pfdrv_reg;
} }
......
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