提交 0ead0f84 编写于 作者: A Alexey Dobriyan 提交者: 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: NAlexey Dobriyan <adobriyan@gmail.com>
Cc: Richard Henderson <rth@twiddle.net>
Cc: Ivan Kokshaysky <ink@jurassic.park.msu.ru>
Signed-off-by: NAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: NLinus Torvalds <torvalds@linux-foundation.org>
上级 4614a696
......@@ -33,6 +33,7 @@
#include <linux/module.h>
#include <linux/init.h>
#include <linux/proc_fs.h>
#include <linux/seq_file.h>
#include <asm/console.h>
#include <asm/uaccess.h>
#include <asm/machvec.h>
......@@ -79,42 +80,41 @@ static srm_env_t srm_named_entries[] = {
static srm_env_t srm_numbered_entries[256];
static int
srm_env_read(char *page, char **start, off_t off, int count, int *eof,
void *data)
static int srm_env_proc_show(struct seq_file *m, void *v)
{
int nbytes;
unsigned long ret;
srm_env_t *entry;
char *page;
if (off != 0) {
*eof = 1;
return 0;
}
entry = (srm_env_t *)m->private;
page = (char *)__get_free_page(GFP_USER);
if (!page)
return -ENOMEM;
entry = (srm_env_t *) data;
ret = callback_getenv(entry->id, page, count);
ret = callback_getenv(entry->id, page, PAGE_SIZE);
if ((ret >> 61) == 0) {
nbytes = (int) ret;
*eof = 1;
seq_write(m, page, ret);
ret = 0;
} 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
srm_env_write(struct file *file, const char __user *buffer, unsigned long count,
void *data)
static ssize_t srm_env_proc_write(struct file *file, const char __user *buffer,
size_t count, loff_t *pos)
{
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);
unsigned long ret1, ret2;
entry = (srm_env_t *) data;
if (!buf)
return -ENOMEM;
......@@ -140,6 +140,15 @@ srm_env_write(struct file *file, const char __user *buffer, unsigned long count,
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
srm_env_cleanup(void)
{
......@@ -245,15 +254,10 @@ srm_env_init(void)
*/
entry = srm_named_entries;
while (entry->name && entry->id) {
entry->proc_entry = create_proc_entry(entry->name,
0644, named_dir);
entry->proc_entry = proc_create_data(entry->name, 0644, named_dir,
&srm_env_proc_fops, entry);
if (!entry->proc_entry)
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++;
}
......@@ -264,15 +268,12 @@ srm_env_init(void)
entry = &srm_numbered_entries[var_num];
entry->name = number[var_num];
entry->proc_entry = create_proc_entry(entry->name,
0644, numbered_dir);
entry->proc_entry = proc_create_data(entry->name, 0644, numbered_dir,
&srm_env_proc_fops, entry);
if (!entry->proc_entry)
goto cleanup;
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,
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册