Commit b087e1f3 authored by Dmitry Torokhov's avatar Dmitry Torokhov

Input: aiptek - use attribute group

Use attribute group to simplify error handling and reduce code.

[Rene: add missing NULL to properly terminate aiptek_attributes]
Signed-off-by: default avatarRene van Paassen <rene.vanpaassen@gmail.com>
Signed-off-by: default avatarDmitry Torokhov <dtor@mail.ru>
parent 5c659c62
...@@ -1795,67 +1795,33 @@ static ssize_t show_firmwareCode(struct device *dev, struct device_attribute *at ...@@ -1795,67 +1795,33 @@ static ssize_t show_firmwareCode(struct device *dev, struct device_attribute *at
static DEVICE_ATTR(firmware_code, S_IRUGO, show_firmwareCode, NULL); static DEVICE_ATTR(firmware_code, S_IRUGO, show_firmwareCode, NULL);
/*********************************************************************** static struct attribute *aiptek_attributes[] = {
* This routine removes all existing sysfs files managed by this device &dev_attr_size.attr,
* driver. &dev_attr_pointer_mode.attr,
*/ &dev_attr_coordinate_mode.attr,
static void aiptek_delete_files(struct device *dev) &dev_attr_tool_mode.attr,
{ &dev_attr_xtilt.attr,
device_remove_file(dev, &dev_attr_size); &dev_attr_ytilt.attr,
device_remove_file(dev, &dev_attr_pointer_mode); &dev_attr_jitter.attr,
device_remove_file(dev, &dev_attr_coordinate_mode); &dev_attr_delay.attr,
device_remove_file(dev, &dev_attr_tool_mode); &dev_attr_event_count.attr,
device_remove_file(dev, &dev_attr_xtilt); &dev_attr_diagnostic.attr,
device_remove_file(dev, &dev_attr_ytilt); &dev_attr_odm_code.attr,
device_remove_file(dev, &dev_attr_jitter); &dev_attr_model_code.attr,
device_remove_file(dev, &dev_attr_delay); &dev_attr_firmware_code.attr,
device_remove_file(dev, &dev_attr_event_count); &dev_attr_stylus_lower.attr,
device_remove_file(dev, &dev_attr_diagnostic); &dev_attr_stylus_upper.attr,
device_remove_file(dev, &dev_attr_odm_code); &dev_attr_mouse_left.attr,
device_remove_file(dev, &dev_attr_model_code); &dev_attr_mouse_middle.attr,
device_remove_file(dev, &dev_attr_firmware_code); &dev_attr_mouse_right.attr,
device_remove_file(dev, &dev_attr_stylus_lower); &dev_attr_wheel.attr,
device_remove_file(dev, &dev_attr_stylus_upper); &dev_attr_execute.attr,
device_remove_file(dev, &dev_attr_mouse_left); NULL
device_remove_file(dev, &dev_attr_mouse_middle); };
device_remove_file(dev, &dev_attr_mouse_right);
device_remove_file(dev, &dev_attr_wheel);
device_remove_file(dev, &dev_attr_execute);
}
/***********************************************************************
* This routine creates the sysfs files managed by this device
* driver.
*/
static int aiptek_add_files(struct device *dev)
{
int ret;
if ((ret = device_create_file(dev, &dev_attr_size)) || static struct attribute_group aiptek_attribute_group = {
(ret = device_create_file(dev, &dev_attr_pointer_mode)) || .attrs = aiptek_attributes,
(ret = device_create_file(dev, &dev_attr_coordinate_mode)) || };
(ret = device_create_file(dev, &dev_attr_tool_mode)) ||
(ret = device_create_file(dev, &dev_attr_xtilt)) ||
(ret = device_create_file(dev, &dev_attr_ytilt)) ||
(ret = device_create_file(dev, &dev_attr_jitter)) ||
(ret = device_create_file(dev, &dev_attr_delay)) ||
(ret = device_create_file(dev, &dev_attr_event_count)) ||
(ret = device_create_file(dev, &dev_attr_diagnostic)) ||
(ret = device_create_file(dev, &dev_attr_odm_code)) ||
(ret = device_create_file(dev, &dev_attr_model_code)) ||
(ret = device_create_file(dev, &dev_attr_firmware_code)) ||
(ret = device_create_file(dev, &dev_attr_stylus_lower)) ||
(ret = device_create_file(dev, &dev_attr_stylus_upper)) ||
(ret = device_create_file(dev, &dev_attr_mouse_left)) ||
(ret = device_create_file(dev, &dev_attr_mouse_middle)) ||
(ret = device_create_file(dev, &dev_attr_mouse_right)) ||
(ret = device_create_file(dev, &dev_attr_wheel)) ||
(ret = device_create_file(dev, &dev_attr_execute))) {
err("aiptek: killing own sysfs device files\n");
aiptek_delete_files(dev);
}
return ret;
}
/*********************************************************************** /***********************************************************************
* This routine is called when a tablet has been identified. It basically * This routine is called when a tablet has been identified. It basically
...@@ -2039,25 +2005,30 @@ aiptek_probe(struct usb_interface *intf, const struct usb_device_id *id) ...@@ -2039,25 +2005,30 @@ aiptek_probe(struct usb_interface *intf, const struct usb_device_id *id)
} }
} }
/* Register the tablet as an Input Device
*/
err = input_register_device(aiptek->inputdev);
if (err)
goto fail2;
/* Associate this driver's struct with the usb interface. /* Associate this driver's struct with the usb interface.
*/ */
usb_set_intfdata(intf, aiptek); usb_set_intfdata(intf, aiptek);
/* Set up the sysfs files /* Set up the sysfs files
*/ */
aiptek_add_files(&intf->dev); err = sysfs_create_group(&intf->dev.kobj, &aiptek_attribute_group);
if (err)
goto fail3;
/* Register the tablet as an Input Device
*/
err = input_register_device(aiptek->inputdev);
if (err)
goto fail4;
return 0; return 0;
fail4: sysfs_remove_group(&intf->dev.kobj, &aiptek_attribute_group);
fail3: usb_free_urb(aiptek->urb);
fail2: usb_buffer_free(usbdev, AIPTEK_PACKET_LENGTH, aiptek->data, fail2: usb_buffer_free(usbdev, AIPTEK_PACKET_LENGTH, aiptek->data,
aiptek->data_dma); aiptek->data_dma);
fail1: input_free_device(inputdev); fail1: usb_set_intfdata(intf, NULL);
input_free_device(inputdev);
kfree(aiptek); kfree(aiptek);
return err; return err;
} }
...@@ -2077,7 +2048,7 @@ static void aiptek_disconnect(struct usb_interface *intf) ...@@ -2077,7 +2048,7 @@ static void aiptek_disconnect(struct usb_interface *intf)
*/ */
usb_kill_urb(aiptek->urb); usb_kill_urb(aiptek->urb);
input_unregister_device(aiptek->inputdev); input_unregister_device(aiptek->inputdev);
aiptek_delete_files(&intf->dev); sysfs_remove_group(&intf->dev.kobj, &aiptek_attribute_group);
usb_free_urb(aiptek->urb); usb_free_urb(aiptek->urb);
usb_buffer_free(interface_to_usbdev(intf), usb_buffer_free(interface_to_usbdev(intf),
AIPTEK_PACKET_LENGTH, AIPTEK_PACKET_LENGTH,
......
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