Commit e7b087fc authored by Christoph Hellwig's avatar Christoph Hellwig

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: default avatarChristoph Hellwig <hch@lst.de>
Reviewed-by: default avatarRafael J. Wysocki <rafael.j.wysocki@intel.com>
parent 3617d949
...@@ -81,14 +81,6 @@ MODULE_PARM_DESC(cache_time, "cache time in milliseconds"); ...@@ -81,14 +81,6 @@ MODULE_PARM_DESC(cache_time, "cache time in milliseconds");
#ifdef CONFIG_ACPI_PROCFS_POWER #ifdef CONFIG_ACPI_PROCFS_POWER
extern struct proc_dir_entry *acpi_lock_battery_dir(void); extern struct proc_dir_entry *acpi_lock_battery_dir(void);
extern void *acpi_unlock_battery_dir(struct proc_dir_entry *acpi_battery_dir); extern void *acpi_unlock_battery_dir(struct proc_dir_entry *acpi_battery_dir);
enum acpi_battery_files {
info_tag = 0,
state_tag,
alarm_tag,
ACPI_BATTERY_NUMFILES,
};
#endif #endif
static const struct acpi_device_id battery_device_ids[] = { 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,9 +977,10 @@ static const char *acpi_battery_units(const struct acpi_battery *battery)
"mA" : "mW"; "mA" : "mW";
} }
static int acpi_battery_print_info(struct seq_file *seq, int result) static int acpi_battery_info_proc_show(struct seq_file *seq, void *offset)
{ {
struct acpi_battery *battery = seq->private; struct acpi_battery *battery = seq->private;
int result = acpi_battery_update(battery, false);
if (result) if (result)
goto end; goto end;
...@@ -1041,9 +1034,10 @@ static int acpi_battery_print_info(struct seq_file *seq, int result) ...@@ -1041,9 +1034,10 @@ static int acpi_battery_print_info(struct seq_file *seq, int result)
return result; return result;
} }
static int acpi_battery_print_state(struct seq_file *seq, int result) static int acpi_battery_state_proc_show(struct seq_file *seq, void *offset)
{ {
struct acpi_battery *battery = seq->private; struct acpi_battery *battery = seq->private;
int result = acpi_battery_update(battery, false);
if (result) if (result)
goto end; goto end;
...@@ -1088,9 +1082,10 @@ static int acpi_battery_print_state(struct seq_file *seq, int result) ...@@ -1088,9 +1082,10 @@ static int acpi_battery_print_state(struct seq_file *seq, int result)
return result; return result;
} }
static int acpi_battery_print_alarm(struct seq_file *seq, int result) static int acpi_battery_alarm_proc_show(struct seq_file *seq, void *offset)
{ {
struct acpi_battery *battery = seq->private; struct acpi_battery *battery = seq->private;
int result = acpi_battery_update(battery, false);
if (result) if (result)
goto end; goto end;
...@@ -1142,82 +1137,22 @@ static ssize_t acpi_battery_write_alarm(struct file *file, ...@@ -1142,82 +1137,22 @@ static ssize_t acpi_battery_write_alarm(struct file *file,
return result; return result;
} }
typedef int(*print_func)(struct seq_file *seq, int result); static int acpi_battery_alarm_proc_open(struct inode *inode, struct file *file)
static print_func acpi_print_funcs[ACPI_BATTERY_NUMFILES] = {
acpi_battery_print_info,
acpi_battery_print_state,
acpi_battery_print_alarm,
};
static int acpi_battery_read(int fid, struct seq_file *seq)
{ {
struct acpi_battery *battery = seq->private; return single_open(file, acpi_battery_alarm_proc_show, PDE_DATA(inode));
int result = acpi_battery_update(battery, false);
return acpi_print_funcs[fid](seq, result);
} }
#define DECLARE_FILE_FUNCTIONS(_name) \ static const struct file_operations acpi_battery_alarm_fops = {
static int acpi_battery_read_##_name(struct seq_file *seq, void *offset) \ .owner = THIS_MODULE,
{ \ .open = acpi_battery_alarm_proc_open,
return acpi_battery_read(_name##_tag, seq); \ .read = seq_read,
} \ .write = acpi_battery_write_alarm,
static int acpi_battery_##_name##_open_fs(struct inode *inode, struct file *file) \ .llseek = seq_lseek,
{ \ .release = single_release,
return single_open(file, acpi_battery_read_##_name, PDE_DATA(inode)); \
}
DECLARE_FILE_FUNCTIONS(info);
DECLARE_FILE_FUNCTIONS(state);
DECLARE_FILE_FUNCTIONS(alarm);
#undef DECLARE_FILE_FUNCTIONS
#define FILE_DESCRIPTION_RO(_name) \
{ \
.name = __stringify(_name), \
.mode = S_IRUGO, \
.ops = { \
.open = acpi_battery_##_name##_open_fs, \
.read = seq_read, \
.llseek = seq_lseek, \
.release = single_release, \
.owner = THIS_MODULE, \
}, \
}
#define FILE_DESCRIPTION_RW(_name) \
{ \
.name = __stringify(_name), \
.mode = S_IFREG | S_IRUGO | S_IWUSR, \
.ops = { \
.open = acpi_battery_##_name##_open_fs, \
.read = seq_read, \
.llseek = seq_lseek, \
.write = acpi_battery_write_##_name, \
.release = single_release, \
.owner = THIS_MODULE, \
}, \
}
static const struct battery_file {
struct file_operations ops;
umode_t mode;
const char *name;
} acpi_battery_file[] = {
FILE_DESCRIPTION_RO(info),
FILE_DESCRIPTION_RO(state),
FILE_DESCRIPTION_RW(alarm),
}; };
#undef FILE_DESCRIPTION_RO
#undef FILE_DESCRIPTION_RW
static int acpi_battery_add_fs(struct acpi_device *device) static int acpi_battery_add_fs(struct acpi_device *device)
{ {
struct proc_dir_entry *entry = NULL;
int i;
printk(KERN_WARNING PREFIX "Deprecated procfs I/F for battery is loaded," printk(KERN_WARNING PREFIX "Deprecated procfs I/F for battery is loaded,"
" please retry with CONFIG_ACPI_PROCFS_POWER cleared\n"); " please retry with CONFIG_ACPI_PROCFS_POWER cleared\n");
if (!acpi_device_dir(device)) { if (!acpi_device_dir(device)) {
...@@ -1227,28 +1162,24 @@ static int acpi_battery_add_fs(struct acpi_device *device) ...@@ -1227,28 +1162,24 @@ static int acpi_battery_add_fs(struct acpi_device *device)
return -ENODEV; return -ENODEV;
} }
for (i = 0; i < ACPI_BATTERY_NUMFILES; ++i) { if (!proc_create_single_data("info", S_IRUGO, acpi_device_dir(device),
entry = proc_create_data(acpi_battery_file[i].name, acpi_battery_info_proc_show, acpi_driver_data(device)))
acpi_battery_file[i].mode, return -ENODEV;
acpi_device_dir(device), if (!proc_create_single_data("state", S_IRUGO, acpi_device_dir(device),
&acpi_battery_file[i].ops, acpi_battery_state_proc_show, acpi_driver_data(device)))
acpi_driver_data(device)); return -ENODEV;
if (!entry) if (!proc_create_data("alarm", S_IFREG | S_IRUGO | S_IWUSR,
return -ENODEV; acpi_device_dir(device), &acpi_battery_alarm_fops,
} acpi_driver_data(device)))
return -ENODEV;
return 0; return 0;
} }
static void acpi_battery_remove_fs(struct acpi_device *device) static void acpi_battery_remove_fs(struct acpi_device *device)
{ {
int i;
if (!acpi_device_dir(device)) if (!acpi_device_dir(device))
return; return;
for (i = 0; i < ACPI_BATTERY_NUMFILES; ++i) remove_proc_subtree(acpi_device_bid(device), acpi_battery_dir);
remove_proc_entry(acpi_battery_file[i].name,
acpi_device_dir(device));
remove_proc_entry(acpi_device_bid(device), acpi_battery_dir);
acpi_device_dir(device) = NULL; acpi_device_dir(device) = NULL;
} }
......
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