Skip to content

Commit

Permalink
proc: introduce proc_create_single{,_data}
Browse files Browse the repository at this point in the history
Variants of proc_create{,_data} that directly take a seq_file show
callback and drastically reduces the boilerplate code in the callers.

All trivial callers converted over.

Signed-off-by: Christoph Hellwig <[email protected]>
  • Loading branch information
Christoph Hellwig committed May 16, 2018
1 parent 44414d8 commit 3f3942a
Show file tree
Hide file tree
Showing 85 changed files with 235 additions and 1,509 deletions.
14 changes: 1 addition & 13 deletions arch/arm/kernel/dma.c
Original file line number Diff line number Diff line change
Expand Up @@ -276,21 +276,9 @@ static int proc_dma_show(struct seq_file *m, void *v)
return 0;
}

static int proc_dma_open(struct inode *inode, struct file *file)
{
return single_open(file, proc_dma_show, NULL);
}

static const struct file_operations proc_dma_operations = {
.open = proc_dma_open,
.read = seq_read,
.llseek = seq_lseek,
.release = single_release,
};

static int __init proc_dma_init(void)
{
proc_create("dma", 0, NULL, &proc_dma_operations);
proc_create_single("dma", 0, NULL, proc_dma_show);
return 0;
}

Expand Down
15 changes: 2 additions & 13 deletions arch/arm/kernel/swp_emulate.c
Original file line number Diff line number Diff line change
Expand Up @@ -91,18 +91,6 @@ static int proc_status_show(struct seq_file *m, void *v)
seq_printf(m, "Last process:\t\t%d\n", previous_pid);
return 0;
}

static int proc_status_open(struct inode *inode, struct file *file)
{
return single_open(file, proc_status_show, PDE_DATA(inode));
}

static const struct file_operations proc_status_fops = {
.open = proc_status_open,
.read = seq_read,
.llseek = seq_lseek,
.release = single_release,
};
#endif

/*
Expand Down Expand Up @@ -260,7 +248,8 @@ static int __init swp_emulation_init(void)
return 0;

#ifdef CONFIG_PROC_FS
if (!proc_create("cpu/swp_emulation", S_IRUGO, NULL, &proc_status_fops))
if (!proc_create_single("cpu/swp_emulation", S_IRUGO, NULL,
proc_status_show))
return -ENOMEM;
#endif /* CONFIG_PROC_FS */

Expand Down
16 changes: 2 additions & 14 deletions arch/arm/mach-rpc/ecard.c
Original file line number Diff line number Diff line change
Expand Up @@ -657,25 +657,13 @@ static int ecard_devices_proc_show(struct seq_file *m, void *v)
return 0;
}

static int ecard_devices_proc_open(struct inode *inode, struct file *file)
{
return single_open(file, ecard_devices_proc_show, NULL);
}

static const struct file_operations bus_ecard_proc_fops = {
.owner = THIS_MODULE,
.open = ecard_devices_proc_open,
.read = seq_read,
.llseek = seq_lseek,
.release = single_release,
};

static struct proc_dir_entry *proc_bus_ecard_dir = NULL;

static void ecard_proc_init(void)
{
proc_bus_ecard_dir = proc_mkdir("bus/ecard", NULL);
proc_create("devices", 0, proc_bus_ecard_dir, &bus_ecard_proc_fops);
proc_create_single("devices", 0, proc_bus_ecard_dir,
ecard_devices_proc_show);
}

#define ec_set_resource(ec,nr,st,sz) \
Expand Down
16 changes: 2 additions & 14 deletions arch/ia64/kernel/palinfo.c
Original file line number Diff line number Diff line change
Expand Up @@ -920,18 +920,6 @@ static int proc_palinfo_show(struct seq_file *m, void *v)
return 0;
}

static int proc_palinfo_open(struct inode *inode, struct file *file)
{
return single_open(file, proc_palinfo_show, PDE_DATA(inode));
}

static const struct file_operations proc_palinfo_fops = {
.open = proc_palinfo_open,
.read = seq_read,
.llseek = seq_lseek,
.release = single_release,
};

static int palinfo_add_proc(unsigned int cpu)
{
pal_func_cpu_u_t f;
Expand All @@ -948,8 +936,8 @@ static int palinfo_add_proc(unsigned int cpu)

for (j=0; j < NR_PALINFO_ENTRIES; j++) {
f.func_id = j;
proc_create_data(palinfo_entries[j].name, 0, cpu_dir,
&proc_palinfo_fops, (void *)f.value);
proc_create_single_data(palinfo_entries[j].name, 0, cpu_dir,
proc_palinfo_show, (void *)f.value);
}
return 0;
}
Expand Down
42 changes: 14 additions & 28 deletions arch/ia64/kernel/salinfo.c
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,6 @@ MODULE_AUTHOR("Jesse Barnes <[email protected]>");
MODULE_DESCRIPTION("/proc interface to IA-64 SAL features");
MODULE_LICENSE("GPL");

static const struct file_operations proc_salinfo_fops;

typedef struct {
const char *name; /* name of the proc entry */
unsigned long feature; /* feature bit */
Expand Down Expand Up @@ -578,6 +576,17 @@ static int salinfo_cpu_pre_down(unsigned int cpu)
return 0;
}

/*
* 'data' contains an integer that corresponds to the feature we're
* testing
*/
static int proc_salinfo_show(struct seq_file *m, void *v)
{
unsigned long data = (unsigned long)v;
seq_puts(m, (sal_platform_features & data) ? "1\n" : "0\n");
return 0;
}

static int __init
salinfo_init(void)
{
Expand All @@ -593,9 +602,9 @@ salinfo_init(void)

for (i=0; i < NR_SALINFO_ENTRIES; i++) {
/* pass the feature bit in question as misc data */
*sdir++ = proc_create_data(salinfo_entries[i].name, 0, salinfo_dir,
&proc_salinfo_fops,
(void *)salinfo_entries[i].feature);
*sdir++ = proc_create_single_data(salinfo_entries[i].name, 0,
salinfo_dir, proc_salinfo_show,
(void *)salinfo_entries[i].feature);
}

for (i = 0; i < ARRAY_SIZE(salinfo_log_name); i++) {
Expand Down Expand Up @@ -633,27 +642,4 @@ salinfo_init(void)
return 0;
}

/*
* 'data' contains an integer that corresponds to the feature we're
* testing
*/
static int proc_salinfo_show(struct seq_file *m, void *v)
{
unsigned long data = (unsigned long)v;
seq_puts(m, (sal_platform_features & data) ? "1\n" : "0\n");
return 0;
}

static int proc_salinfo_open(struct inode *inode, struct file *file)
{
return single_open(file, proc_salinfo_show, PDE_DATA(inode));
}

static const struct file_operations proc_salinfo_fops = {
.open = proc_salinfo_open,
.read = seq_read,
.llseek = seq_lseek,
.release = single_release,
};

module_init(salinfo_init);
32 changes: 4 additions & 28 deletions arch/ia64/sn/kernel/sn2/prominfo_proc.c
Original file line number Diff line number Diff line change
Expand Up @@ -140,18 +140,6 @@ static int proc_fit_show(struct seq_file *m, void *v)
return 0;
}

static int proc_fit_open(struct inode *inode, struct file *file)
{
return single_open(file, proc_fit_show, PDE_DATA(inode));
}

static const struct file_operations proc_fit_fops = {
.open = proc_fit_open,
.read = seq_read,
.llseek = seq_lseek,
.release = single_release,
};

static int proc_version_show(struct seq_file *m, void *v)
{
unsigned long nasid = (unsigned long)m->private;
Expand All @@ -174,18 +162,6 @@ static int proc_version_show(struct seq_file *m, void *v)
return 0;
}

static int proc_version_open(struct inode *inode, struct file *file)
{
return single_open(file, proc_version_show, PDE_DATA(inode));
}

static const struct file_operations proc_version_fops = {
.open = proc_version_open,
.read = seq_read,
.llseek = seq_lseek,
.release = single_release,
};

/* module entry points */
int __init prominfo_init(void);
void __exit prominfo_exit(void);
Expand Down Expand Up @@ -217,10 +193,10 @@ int __init prominfo_init(void)
if (!dir)
continue;
nasid = cnodeid_to_nasid(cnodeid);
proc_create_data("fit", 0, dir,
&proc_fit_fops, (void *)nasid);
proc_create_data("version", 0, dir,
&proc_version_fops, (void *)nasid);
proc_create_single_data("fit", 0, dir, proc_fit_show,
(void *)nasid);
proc_create_single_data("version", 0, dir, proc_version_show,
(void *)nasid);
}
return 0;
}
Expand Down
62 changes: 7 additions & 55 deletions arch/ia64/sn/kernel/sn2/sn_proc_fs.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,77 +18,29 @@ static int partition_id_show(struct seq_file *s, void *p)
return 0;
}

static int partition_id_open(struct inode *inode, struct file *file)
{
return single_open(file, partition_id_show, NULL);
}

static int system_serial_number_show(struct seq_file *s, void *p)
{
seq_printf(s, "%s\n", sn_system_serial_number());
return 0;
}

static int system_serial_number_open(struct inode *inode, struct file *file)
{
return single_open(file, system_serial_number_show, NULL);
}

static int licenseID_show(struct seq_file *s, void *p)
{
seq_printf(s, "0x%llx\n", sn_partition_serial_number_val());
return 0;
}

static int licenseID_open(struct inode *inode, struct file *file)
{
return single_open(file, licenseID_show, NULL);
}

static int coherence_id_show(struct seq_file *s, void *p)
{
seq_printf(s, "%d\n", partition_coherence_id());

return 0;
}

static int coherence_id_open(struct inode *inode, struct file *file)
{
return single_open(file, coherence_id_show, NULL);
}

/* /proc/sgi_sn/sn_topology uses seq_file, see sn_hwperf.c */
extern int sn_topology_open(struct inode *, struct file *);
extern int sn_topology_release(struct inode *, struct file *);

static const struct file_operations proc_partition_id_fops = {
.open = partition_id_open,
.read = seq_read,
.llseek = seq_lseek,
.release = single_release,
};

static const struct file_operations proc_system_sn_fops = {
.open = system_serial_number_open,
.read = seq_read,
.llseek = seq_lseek,
.release = single_release,
};

static const struct file_operations proc_license_id_fops = {
.open = licenseID_open,
.read = seq_read,
.llseek = seq_lseek,
.release = single_release,
};

static const struct file_operations proc_coherence_id_fops = {
.open = coherence_id_open,
.read = seq_read,
.llseek = seq_lseek,
.release = single_release,
};

static const struct file_operations proc_sn_topo_fops = {
.open = sn_topology_open,
.read = seq_read,
Expand All @@ -104,13 +56,13 @@ void register_sn_procfs(void)
if (!(sgi_proc_dir = proc_mkdir("sgi_sn", NULL)))
return;

proc_create("partition_id", 0444, sgi_proc_dir,
&proc_partition_id_fops);
proc_create("system_serial_number", 0444, sgi_proc_dir,
&proc_system_sn_fops);
proc_create("licenseID", 0444, sgi_proc_dir, &proc_license_id_fops);
proc_create("coherence_id", 0444, sgi_proc_dir,
&proc_coherence_id_fops);
proc_create_single("partition_id", 0444, sgi_proc_dir,
partition_id_show);
proc_create_single("system_serial_number", 0444, sgi_proc_dir,
system_serial_number_show);
proc_create_single("licenseID", 0444, sgi_proc_dir, licenseID_show);
proc_create_single("coherence_id", 0444, sgi_proc_dir,
coherence_id_show);
proc_create("sn_topology", 0444, sgi_proc_dir, &proc_sn_topo_fops);
}

Expand Down
14 changes: 1 addition & 13 deletions arch/m68k/kernel/setup_mm.c
Original file line number Diff line number Diff line change
Expand Up @@ -527,21 +527,9 @@ static int hardware_proc_show(struct seq_file *m, void *v)
return 0;
}

static int hardware_proc_open(struct inode *inode, struct file *file)
{
return single_open(file, hardware_proc_show, NULL);
}

static const struct file_operations hardware_proc_fops = {
.open = hardware_proc_open,
.read = seq_read,
.llseek = seq_lseek,
.release = single_release,
};

static int __init proc_hardware_init(void)
{
proc_create("hardware", 0, NULL, &hardware_proc_fops);
proc_create_single("hardware", 0, NULL, hardware_proc_show);
return 0;
}
module_init(proc_hardware_init);
Expand Down
Loading

0 comments on commit 3f3942a

Please sign in to comment.