struct quickstart_btn {
char *name;
unsigned int id;
- struct quickstart_btn *next;
+ struct list_head list;
};
struct quickstart_acpi {
struct quickstart_btn *btn;
};
-static struct quickstart_btn *btn_list;
+static LIST_HEAD(buttons);
static struct quickstart_btn *pressed;
static struct input_dev *quickstart_input;
char *buf)
{
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");
- while (ptr && (count < PAGE_SIZE)) {
- if (ptr->name) {
- count += snprintf(buf + count,
- PAGE_SIZE - count,
- "%d\t%s\n", ptr->id, ptr->name);
+ list_for_each_entry(b, &buttons, list) {
+ count += snprintf(buf + count, PAGE_SIZE - count, "%d\t%s\n",
+ b->id, b->name);
+
+ if (count >= PAGE_SIZE) {
+ count = PAGE_SIZE;
+ break;
}
- ptr = ptr->next;
}
return count;
}
/* 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)
- ptr = &((*ptr)->next);
+ b = kzalloc(sizeof(*b), GFP_KERNEL);
+ if (!b)
+ return NULL;
- *ptr = kzalloc(sizeof(struct quickstart_btn), GFP_KERNEL);
- if (!*ptr) {
- *data = NULL;
- return -ENOMEM;
- }
- *data = *ptr;
+ list_add_tail(&b->list, &buttons);
- 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)
return;
- while (*ptr) {
- if (*ptr == data) {
- *ptr = (*ptr)->next;
- kfree(data);
- return;
- }
- ptr = &((*ptr)->next);
- }
-
- return;
+ list_del(&data->list);
+ kfree(data->name);
+ kfree(data);
}
-static void quickstart_btnlst_free(void)
+static void quickstart_buttons_free(void)
{
- struct quickstart_btn *ptr = btn_list;
- struct quickstart_btn *lptr = NULL;
-
- while (ptr) {
- lptr = ptr;
- ptr = ptr->next;
- kfree(lptr->name);
- kfree(lptr);
- }
+ struct quickstart_btn *b, *n;
- return;
+ list_for_each_entry_safe(b, n, &buttons, list)
+ quickstart_button_del(b);
}
/* ACPI Driver functions */
{
char *bid = acpi_device_bid(quickstart->device);
char *name;
- int ret;
name = kmalloc(strlen(bid) + 1, GFP_KERNEL);
if (!name)
return -ENOMEM;
- /* Add button to list */
- ret = quickstart_btnlst_add(&quickstart->btn);
- if (ret < 0) {
+ /* Add new button to list */
+ quickstart->btn = quickstart_buttons_add();
+ if (!quickstart->btn) {
kfree(name);
- return ret;
+ return -ENOMEM;
}
quickstart->btn->name = name;
quickstart_acpi_notify);
fail_installnotify:
- quickstart_btnlst_del(quickstart->btn);
+ quickstart_button_del(quickstart->btn);
fail_config:
acpi_bus_unregister_driver(&quickstart_acpi_driver);
- quickstart_btnlst_free();
+ quickstart_buttons_free();
}
static int __init quickstart_init_input(void)
{
- struct quickstart_btn **ptr = &btn_list;
- int count;
+ struct quickstart_btn *b;
int ret;
quickstart_input = input_allocate_device();
quickstart_input->name = "Quickstart ACPI Buttons";
quickstart_input->id.bustype = BUS_HOST;
- while (*ptr) {
- count++;
+ list_for_each_entry(b, &buttons, list) {
set_bit(EV_KEY, quickstart_input->evbit);
- set_bit((*ptr)->id, quickstart_input->keybit);
- ptr = &((*ptr)->next);
+ set_bit(b->id, quickstart_input->keybit);
}
ret = input_register_device(quickstart_input);
return ret;
/* If existing bus with no devices */
- if (!btn_list) {
+ if (list_empty(&buttons)) {
ret = -ENODEV;
goto fail_pfdrv_reg;
}