aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/acpi/dock.c
diff options
context:
space:
mode:
authorAlex Chiang <achiang@hp.com>2009-10-19 17:14:24 -0400
committerLen Brown <len.brown@intel.com>2009-11-03 15:57:13 -0500
commit5f46c2f25cfbb5faca7550738ac42c4d1491ddc8 (patch)
treebace354f58682fe00a60625c0311bfa528cbbb4d /drivers/acpi/dock.c
parent012abeea669ea49636cf952d13298bb68654146a (diff)
ACPI: dock: convert sysfs attributes to an attribute_group
As suggested by Dmitry Torokhov, convert the individual sysfs attributes into an attribute group. This change eliminates quite a bit of copy/paste code in the error handling paths. Signed-off-by: Alex Chiang <achiang@hp.com> Reviewed-by: Dmitry Torokhov <dtor@mail.ru> Acked-by: Shaohua Li <shaohua.li@intel.com> Signed-off-by: Len Brown <len.brown@intel.com>
Diffstat (limited to 'drivers/acpi/dock.c')
-rw-r--r--drivers/acpi/dock.c81
1 files changed, 24 insertions, 57 deletions
diff --git a/drivers/acpi/dock.c b/drivers/acpi/dock.c
index 7338b6a3e049..4f2aa98e2cee 100644
--- a/drivers/acpi/dock.c
+++ b/drivers/acpi/dock.c
@@ -936,6 +936,19 @@ static ssize_t show_dock_type(struct device *dev,
936} 936}
937static DEVICE_ATTR(type, S_IRUGO, show_dock_type, NULL); 937static DEVICE_ATTR(type, S_IRUGO, show_dock_type, NULL);
938 938
939static struct attribute *dock_attributes[] = {
940 &dev_attr_docked.attr,
941 &dev_attr_flags.attr,
942 &dev_attr_undock.attr,
943 &dev_attr_uid.attr,
944 &dev_attr_type.attr,
945 NULL
946};
947
948static struct attribute_group dock_attribute_group = {
949 .attrs = dock_attributes
950};
951
939/** 952/**
940 * dock_add - add a new dock station 953 * dock_add - add a new dock station
941 * @handle: the dock station handle 954 * @handle: the dock station handle
@@ -969,9 +982,8 @@ static int dock_add(acpi_handle handle)
969 dock_station_count, NULL, 0); 982 dock_station_count, NULL, 0);
970 dock_device = dock_station->dock_device; 983 dock_device = dock_station->dock_device;
971 if (IS_ERR(dock_device)) { 984 if (IS_ERR(dock_device)) {
972 kfree(dock_station); 985 ret = PTR_ERR(dock_device);
973 dock_station = NULL; 986 goto out;
974 return PTR_ERR(dock_device);
975 } 987 }
976 platform_device_add_data(dock_device, &dock_station, 988 platform_device_add_data(dock_device, &dock_station,
977 sizeof(struct dock_station *)); 989 sizeof(struct dock_station *));
@@ -986,47 +998,9 @@ static int dock_add(acpi_handle handle)
986 if (is_battery(handle)) 998 if (is_battery(handle))
987 dock_station->flags |= DOCK_IS_BAT; 999 dock_station->flags |= DOCK_IS_BAT;
988 1000
989 ret = device_create_file(&dock_device->dev, &dev_attr_docked); 1001 ret = sysfs_create_group(&dock_device->dev.kobj, &dock_attribute_group);
990 if (ret) {
991 printk(KERN_ERR "Error %d adding sysfs file\n", ret);
992 platform_device_unregister(dock_device);
993 kfree(dock_station);
994 dock_station = NULL;
995 return ret;
996 }
997 ret = device_create_file(&dock_device->dev, &dev_attr_undock);
998 if (ret) {
999 printk(KERN_ERR "Error %d adding sysfs file\n", ret);
1000 device_remove_file(&dock_device->dev, &dev_attr_docked);
1001 platform_device_unregister(dock_device);
1002 kfree(dock_station);
1003 dock_station = NULL;
1004 return ret;
1005 }
1006 ret = device_create_file(&dock_device->dev, &dev_attr_uid);
1007 if (ret) {
1008 printk(KERN_ERR "Error %d adding sysfs file\n", ret);
1009 device_remove_file(&dock_device->dev, &dev_attr_docked);
1010 device_remove_file(&dock_device->dev, &dev_attr_undock);
1011 platform_device_unregister(dock_device);
1012 kfree(dock_station);
1013 dock_station = NULL;
1014 return ret;
1015 }
1016 ret = device_create_file(&dock_device->dev, &dev_attr_flags);
1017 if (ret) {
1018 printk(KERN_ERR "Error %d adding sysfs file\n", ret);
1019 device_remove_file(&dock_device->dev, &dev_attr_docked);
1020 device_remove_file(&dock_device->dev, &dev_attr_undock);
1021 device_remove_file(&dock_device->dev, &dev_attr_uid);
1022 platform_device_unregister(dock_device);
1023 kfree(dock_station);
1024 dock_station = NULL;
1025 return ret;
1026 }
1027 ret = device_create_file(&dock_device->dev, &dev_attr_type);
1028 if (ret) 1002 if (ret)
1029 printk(KERN_ERR"Error %d adding sysfs file\n", ret); 1003 goto err_unregister;
1030 1004
1031 /* Find dependent devices */ 1005 /* Find dependent devices */
1032 acpi_walk_namespace(ACPI_TYPE_DEVICE, ACPI_ROOT_OBJECT, 1006 acpi_walk_namespace(ACPI_TYPE_DEVICE, ACPI_ROOT_OBJECT,
@@ -1036,10 +1010,8 @@ static int dock_add(acpi_handle handle)
1036 /* add the dock station as a device dependent on itself */ 1010 /* add the dock station as a device dependent on itself */
1037 dd = alloc_dock_dependent_device(handle); 1011 dd = alloc_dock_dependent_device(handle);
1038 if (!dd) { 1012 if (!dd) {
1039 kfree(dock_station);
1040 dock_station = NULL;
1041 ret = -ENOMEM; 1013 ret = -ENOMEM;
1042 goto dock_add_err_unregister; 1014 goto err_rmgroup;
1043 } 1015 }
1044 add_dock_dependent_device(dock_station, dd); 1016 add_dock_dependent_device(dock_station, dd);
1045 1017
@@ -1047,15 +1019,14 @@ static int dock_add(acpi_handle handle)
1047 list_add(&dock_station->sibling, &dock_stations); 1019 list_add(&dock_station->sibling, &dock_stations);
1048 return 0; 1020 return 0;
1049 1021
1050dock_add_err_unregister: 1022err_rmgroup:
1051 device_remove_file(&dock_device->dev, &dev_attr_type); 1023 sysfs_remove_group(&dock_device->dev.kobj, &dock_attribute_group);
1052 device_remove_file(&dock_device->dev, &dev_attr_docked); 1024err_unregister:
1053 device_remove_file(&dock_device->dev, &dev_attr_undock);
1054 device_remove_file(&dock_device->dev, &dev_attr_uid);
1055 device_remove_file(&dock_device->dev, &dev_attr_flags);
1056 platform_device_unregister(dock_device); 1025 platform_device_unregister(dock_device);
1026out:
1057 kfree(dock_station); 1027 kfree(dock_station);
1058 dock_station = NULL; 1028 dock_station = NULL;
1029 printk(KERN_ERR "%s encountered error %d\n", __func__, ret);
1059 return ret; 1030 return ret;
1060} 1031}
1061 1032
@@ -1076,11 +1047,7 @@ static int dock_remove(struct dock_station *dock_station)
1076 kfree(dd); 1047 kfree(dd);
1077 1048
1078 /* cleanup sysfs */ 1049 /* cleanup sysfs */
1079 device_remove_file(&dock_device->dev, &dev_attr_type); 1050 sysfs_remove_group(&dock_device->dev.kobj, &dock_attribute_group);
1080 device_remove_file(&dock_device->dev, &dev_attr_docked);
1081 device_remove_file(&dock_device->dev, &dev_attr_undock);
1082 device_remove_file(&dock_device->dev, &dev_attr_uid);
1083 device_remove_file(&dock_device->dev, &dev_attr_flags);
1084 platform_device_unregister(dock_device); 1051 platform_device_unregister(dock_device);
1085 1052
1086 /* free dock station memory */ 1053 /* free dock station memory */