Commit 0ead0f84 authored by Alexey Dobriyan's avatar Alexey Dobriyan Committed by Linus Torvalds

alpha: convert srm code to seq_file

Convert code away from ->read_proc/->write_proc interfaces.  Switch to
proc_create()/proc_create_data() which make addition of proc entries
reliable wrt NULL ->proc_fops, NULL ->data and so on.

Problem with ->read_proc et al is described here commit
786d7e16 "Fix rmmod/read/write races in
/proc entries"
Signed-off-by: default avatarAlexey Dobriyan <adobriyan@gmail.com>
Cc: Richard Henderson <rth@twiddle.net>
Cc: Ivan Kokshaysky <ink@jurassic.park.msu.ru>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent 4614a696
...@@ -33,6 +33,7 @@ ...@@ -33,6 +33,7 @@
#include <linux/module.h> #include <linux/module.h>
#include <linux/init.h> #include <linux/init.h>
#include <linux/proc_fs.h> #include <linux/proc_fs.h>
#include <linux/seq_file.h>
#include <asm/console.h> #include <asm/console.h>
#include <asm/uaccess.h> #include <asm/uaccess.h>
#include <asm/machvec.h> #include <asm/machvec.h>
...@@ -79,42 +80,41 @@ static srm_env_t srm_named_entries[] = { ...@@ -79,42 +80,41 @@ static srm_env_t srm_named_entries[] = {
static srm_env_t srm_numbered_entries[256]; static srm_env_t srm_numbered_entries[256];
static int static int srm_env_proc_show(struct seq_file *m, void *v)
srm_env_read(char *page, char **start, off_t off, int count, int *eof,
void *data)
{ {
int nbytes;
unsigned long ret; unsigned long ret;
srm_env_t *entry; srm_env_t *entry;
char *page;
if (off != 0) { entry = (srm_env_t *)m->private;
*eof = 1; page = (char *)__get_free_page(GFP_USER);
return 0; if (!page)
} return -ENOMEM;
entry = (srm_env_t *) data; ret = callback_getenv(entry->id, page, PAGE_SIZE);
ret = callback_getenv(entry->id, page, count);
if ((ret >> 61) == 0) { if ((ret >> 61) == 0) {
nbytes = (int) ret; seq_write(m, page, ret);
*eof = 1; ret = 0;
} else } else
nbytes = -EFAULT; ret = -EFAULT;
free_page((unsigned long)page);
return ret;
}
return nbytes; static int srm_env_proc_open(struct inode *inode, struct file *file)
{
return single_open(file, srm_env_proc_show, PDE(inode)->data);
} }
static int static ssize_t srm_env_proc_write(struct file *file, const char __user *buffer,
srm_env_write(struct file *file, const char __user *buffer, unsigned long count, size_t count, loff_t *pos)
void *data)
{ {
int res; int res;
srm_env_t *entry; srm_env_t *entry = PDE(file->f_path.dentry->d_inode)->data;
char *buf = (char *) __get_free_page(GFP_USER); char *buf = (char *) __get_free_page(GFP_USER);
unsigned long ret1, ret2; unsigned long ret1, ret2;
entry = (srm_env_t *) data;
if (!buf) if (!buf)
return -ENOMEM; return -ENOMEM;
...@@ -140,6 +140,15 @@ srm_env_write(struct file *file, const char __user *buffer, unsigned long count, ...@@ -140,6 +140,15 @@ srm_env_write(struct file *file, const char __user *buffer, unsigned long count,
return res; return res;
} }
static const struct file_operations srm_env_proc_fops = {
.owner = THIS_MODULE,
.open = srm_env_proc_open,
.read = seq_read,
.llseek = seq_lseek,
.release = single_release,
.write = srm_env_proc_write,
};
static void static void
srm_env_cleanup(void) srm_env_cleanup(void)
{ {
...@@ -245,15 +254,10 @@ srm_env_init(void) ...@@ -245,15 +254,10 @@ srm_env_init(void)
*/ */
entry = srm_named_entries; entry = srm_named_entries;
while (entry->name && entry->id) { while (entry->name && entry->id) {
entry->proc_entry = create_proc_entry(entry->name, entry->proc_entry = proc_create_data(entry->name, 0644, named_dir,
0644, named_dir); &srm_env_proc_fops, entry);
if (!entry->proc_entry) if (!entry->proc_entry)
goto cleanup; goto cleanup;
entry->proc_entry->data = (void *) entry;
entry->proc_entry->read_proc = srm_env_read;
entry->proc_entry->write_proc = srm_env_write;
entry++; entry++;
} }
...@@ -264,15 +268,12 @@ srm_env_init(void) ...@@ -264,15 +268,12 @@ srm_env_init(void)
entry = &srm_numbered_entries[var_num]; entry = &srm_numbered_entries[var_num];
entry->name = number[var_num]; entry->name = number[var_num];
entry->proc_entry = create_proc_entry(entry->name, entry->proc_entry = proc_create_data(entry->name, 0644, numbered_dir,
0644, numbered_dir); &srm_env_proc_fops, entry);
if (!entry->proc_entry) if (!entry->proc_entry)
goto cleanup; goto cleanup;
entry->id = var_num; entry->id = var_num;
entry->proc_entry->data = (void *) entry;
entry->proc_entry->read_proc = srm_env_read;
entry->proc_entry->write_proc = srm_env_write;
} }
printk(KERN_INFO "%s: version %s loaded successfully\n", NAME, printk(KERN_INFO "%s: version %s loaded successfully\n", NAME,
......
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