diff options
author | Christoph Hellwig <hch@lst.de> | 2018-04-11 10:27:14 -0400 |
---|---|---|
committer | Christoph Hellwig <hch@lst.de> | 2018-05-16 01:24:30 -0400 |
commit | e7b087fc6bb60234bb6d84d73b74c1e9cf03d5b7 (patch) | |
tree | d5c6db8b192ab84e84b1918cd2752d42c35d682e | |
parent | 3617d9496cd92dcca4d0893191d95554590d8d9f (diff) |
acpi/battery: simplify procfs code
Use remove_proc_subtree to remove the whole subtree on cleanup, and
unwind the registration loop into individual calls. Switch to use
proc_create_seq where applicable.
Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
-rw-r--r-- | drivers/acpi/battery.c | 121 |
1 files changed, 26 insertions, 95 deletions
diff --git a/drivers/acpi/battery.c b/drivers/acpi/battery.c index bdb24d636d9a..76550689ce10 100644 --- a/drivers/acpi/battery.c +++ b/drivers/acpi/battery.c | |||
@@ -81,14 +81,6 @@ MODULE_PARM_DESC(cache_time, "cache time in milliseconds"); | |||
81 | #ifdef CONFIG_ACPI_PROCFS_POWER | 81 | #ifdef CONFIG_ACPI_PROCFS_POWER |
82 | extern struct proc_dir_entry *acpi_lock_battery_dir(void); | 82 | extern struct proc_dir_entry *acpi_lock_battery_dir(void); |
83 | extern void *acpi_unlock_battery_dir(struct proc_dir_entry *acpi_battery_dir); | 83 | extern void *acpi_unlock_battery_dir(struct proc_dir_entry *acpi_battery_dir); |
84 | |||
85 | enum acpi_battery_files { | ||
86 | info_tag = 0, | ||
87 | state_tag, | ||
88 | alarm_tag, | ||
89 | ACPI_BATTERY_NUMFILES, | ||
90 | }; | ||
91 | |||
92 | #endif | 84 | #endif |
93 | 85 | ||
94 | static const struct acpi_device_id battery_device_ids[] = { | 86 | static const struct acpi_device_id battery_device_ids[] = { |
@@ -985,9 +977,10 @@ static const char *acpi_battery_units(const struct acpi_battery *battery) | |||
985 | "mA" : "mW"; | 977 | "mA" : "mW"; |
986 | } | 978 | } |
987 | 979 | ||
988 | static int acpi_battery_print_info(struct seq_file *seq, int result) | 980 | static int acpi_battery_info_proc_show(struct seq_file *seq, void *offset) |
989 | { | 981 | { |
990 | struct acpi_battery *battery = seq->private; | 982 | struct acpi_battery *battery = seq->private; |
983 | int result = acpi_battery_update(battery, false); | ||
991 | 984 | ||
992 | if (result) | 985 | if (result) |
993 | goto end; | 986 | goto end; |
@@ -1041,9 +1034,10 @@ static int acpi_battery_print_info(struct seq_file *seq, int result) | |||
1041 | return result; | 1034 | return result; |
1042 | } | 1035 | } |
1043 | 1036 | ||
1044 | static int acpi_battery_print_state(struct seq_file *seq, int result) | 1037 | static int acpi_battery_state_proc_show(struct seq_file *seq, void *offset) |
1045 | { | 1038 | { |
1046 | struct acpi_battery *battery = seq->private; | 1039 | struct acpi_battery *battery = seq->private; |
1040 | int result = acpi_battery_update(battery, false); | ||
1047 | 1041 | ||
1048 | if (result) | 1042 | if (result) |
1049 | goto end; | 1043 | goto end; |
@@ -1088,9 +1082,10 @@ static int acpi_battery_print_state(struct seq_file *seq, int result) | |||
1088 | return result; | 1082 | return result; |
1089 | } | 1083 | } |
1090 | 1084 | ||
1091 | static int acpi_battery_print_alarm(struct seq_file *seq, int result) | 1085 | static int acpi_battery_alarm_proc_show(struct seq_file *seq, void *offset) |
1092 | { | 1086 | { |
1093 | struct acpi_battery *battery = seq->private; | 1087 | struct acpi_battery *battery = seq->private; |
1088 | int result = acpi_battery_update(battery, false); | ||
1094 | 1089 | ||
1095 | if (result) | 1090 | if (result) |
1096 | goto end; | 1091 | goto end; |
@@ -1142,82 +1137,22 @@ static ssize_t acpi_battery_write_alarm(struct file *file, | |||
1142 | return result; | 1137 | return result; |
1143 | } | 1138 | } |
1144 | 1139 | ||
1145 | typedef int(*print_func)(struct seq_file *seq, int result); | 1140 | static int acpi_battery_alarm_proc_open(struct inode *inode, struct file *file) |
1146 | |||
1147 | static print_func acpi_print_funcs[ACPI_BATTERY_NUMFILES] = { | ||
1148 | acpi_battery_print_info, | ||
1149 | acpi_battery_print_state, | ||
1150 | acpi_battery_print_alarm, | ||
1151 | }; | ||
1152 | |||
1153 | static int acpi_battery_read(int fid, struct seq_file *seq) | ||
1154 | { | 1141 | { |
1155 | struct acpi_battery *battery = seq->private; | 1142 | return single_open(file, acpi_battery_alarm_proc_show, PDE_DATA(inode)); |
1156 | int result = acpi_battery_update(battery, false); | ||
1157 | return acpi_print_funcs[fid](seq, result); | ||
1158 | } | 1143 | } |
1159 | 1144 | ||
1160 | #define DECLARE_FILE_FUNCTIONS(_name) \ | 1145 | static const struct file_operations acpi_battery_alarm_fops = { |
1161 | static int acpi_battery_read_##_name(struct seq_file *seq, void *offset) \ | 1146 | .owner = THIS_MODULE, |
1162 | { \ | 1147 | .open = acpi_battery_alarm_proc_open, |
1163 | return acpi_battery_read(_name##_tag, seq); \ | 1148 | .read = seq_read, |
1164 | } \ | 1149 | .write = acpi_battery_write_alarm, |
1165 | static int acpi_battery_##_name##_open_fs(struct inode *inode, struct file *file) \ | 1150 | .llseek = seq_lseek, |
1166 | { \ | 1151 | .release = single_release, |
1167 | return single_open(file, acpi_battery_read_##_name, PDE_DATA(inode)); \ | ||
1168 | } | ||
1169 | |||
1170 | DECLARE_FILE_FUNCTIONS(info); | ||
1171 | DECLARE_FILE_FUNCTIONS(state); | ||
1172 | DECLARE_FILE_FUNCTIONS(alarm); | ||
1173 | |||
1174 | #undef DECLARE_FILE_FUNCTIONS | ||
1175 | |||
1176 | #define FILE_DESCRIPTION_RO(_name) \ | ||
1177 | { \ | ||
1178 | .name = __stringify(_name), \ | ||
1179 | .mode = S_IRUGO, \ | ||
1180 | .ops = { \ | ||
1181 | .open = acpi_battery_##_name##_open_fs, \ | ||
1182 | .read = seq_read, \ | ||
1183 | .llseek = seq_lseek, \ | ||
1184 | .release = single_release, \ | ||
1185 | .owner = THIS_MODULE, \ | ||
1186 | }, \ | ||
1187 | } | ||
1188 | |||
1189 | #define FILE_DESCRIPTION_RW(_name) \ | ||
1190 | { \ | ||
1191 | .name = __stringify(_name), \ | ||
1192 | .mode = S_IFREG | S_IRUGO | S_IWUSR, \ | ||
1193 | .ops = { \ | ||
1194 | .open = acpi_battery_##_name##_open_fs, \ | ||
1195 | .read = seq_read, \ | ||
1196 | .llseek = seq_lseek, \ | ||
1197 | .write = acpi_battery_write_##_name, \ | ||
1198 | .release = single_release, \ | ||
1199 | .owner = THIS_MODULE, \ | ||
1200 | }, \ | ||
1201 | } | ||
1202 | |||
1203 | static const struct battery_file { | ||
1204 | struct file_operations ops; | ||
1205 | umode_t mode; | ||
1206 | const char *name; | ||
1207 | } acpi_battery_file[] = { | ||
1208 | FILE_DESCRIPTION_RO(info), | ||
1209 | FILE_DESCRIPTION_RO(state), | ||
1210 | FILE_DESCRIPTION_RW(alarm), | ||
1211 | }; | 1152 | }; |
1212 | 1153 | ||
1213 | #undef FILE_DESCRIPTION_RO | ||
1214 | #undef FILE_DESCRIPTION_RW | ||
1215 | |||
1216 | static int acpi_battery_add_fs(struct acpi_device *device) | 1154 | static int acpi_battery_add_fs(struct acpi_device *device) |
1217 | { | 1155 | { |
1218 | struct proc_dir_entry *entry = NULL; | ||
1219 | int i; | ||
1220 | |||
1221 | printk(KERN_WARNING PREFIX "Deprecated procfs I/F for battery is loaded," | 1156 | printk(KERN_WARNING PREFIX "Deprecated procfs I/F for battery is loaded," |
1222 | " please retry with CONFIG_ACPI_PROCFS_POWER cleared\n"); | 1157 | " please retry with CONFIG_ACPI_PROCFS_POWER cleared\n"); |
1223 | if (!acpi_device_dir(device)) { | 1158 | if (!acpi_device_dir(device)) { |
@@ -1227,28 +1162,24 @@ static int acpi_battery_add_fs(struct acpi_device *device) | |||
1227 | return -ENODEV; | 1162 | return -ENODEV; |
1228 | } | 1163 | } |
1229 | 1164 | ||
1230 | for (i = 0; i < ACPI_BATTERY_NUMFILES; ++i) { | 1165 | if (!proc_create_single_data("info", S_IRUGO, acpi_device_dir(device), |
1231 | entry = proc_create_data(acpi_battery_file[i].name, | 1166 | acpi_battery_info_proc_show, acpi_driver_data(device))) |
1232 | acpi_battery_file[i].mode, | 1167 | return -ENODEV; |
1233 | acpi_device_dir(device), | 1168 | if (!proc_create_single_data("state", S_IRUGO, acpi_device_dir(device), |
1234 | &acpi_battery_file[i].ops, | 1169 | acpi_battery_state_proc_show, acpi_driver_data(device))) |
1235 | acpi_driver_data(device)); | 1170 | return -ENODEV; |
1236 | if (!entry) | 1171 | if (!proc_create_data("alarm", S_IFREG | S_IRUGO | S_IWUSR, |
1237 | return -ENODEV; | 1172 | acpi_device_dir(device), &acpi_battery_alarm_fops, |
1238 | } | 1173 | acpi_driver_data(device))) |
1174 | return -ENODEV; | ||
1239 | return 0; | 1175 | return 0; |
1240 | } | 1176 | } |
1241 | 1177 | ||
1242 | static void acpi_battery_remove_fs(struct acpi_device *device) | 1178 | static void acpi_battery_remove_fs(struct acpi_device *device) |
1243 | { | 1179 | { |
1244 | int i; | ||
1245 | if (!acpi_device_dir(device)) | 1180 | if (!acpi_device_dir(device)) |
1246 | return; | 1181 | return; |
1247 | for (i = 0; i < ACPI_BATTERY_NUMFILES; ++i) | 1182 | remove_proc_subtree(acpi_device_bid(device), acpi_battery_dir); |
1248 | remove_proc_entry(acpi_battery_file[i].name, | ||
1249 | acpi_device_dir(device)); | ||
1250 | |||
1251 | remove_proc_entry(acpi_device_bid(device), acpi_battery_dir); | ||
1252 | acpi_device_dir(device) = NULL; | 1183 | acpi_device_dir(device) = NULL; |
1253 | } | 1184 | } |
1254 | 1185 | ||