mirror of
https://github.com/adulau/aha.git
synced 2024-12-28 11:46:19 +00:00
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
786d7e1612
"Fix rmmod/read/write races in
/proc entries"
Signed-off-by: Alexey Dobriyan <adobriyan@gmail.com>
Cc: Richard Henderson <rth@twiddle.net>
Cc: Ivan Kokshaysky <ink@jurassic.park.msu.ru>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
This commit is contained in:
parent
4614a696bd
commit
0ead0f84e8
1 changed files with 34 additions and 33 deletions
|
@ -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[] = {
|
||||||
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 nbytes;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int srm_env_proc_open(struct inode *inode, struct file *file)
|
||||||
srm_env_write(struct file *file, const char __user *buffer, unsigned long count,
|
{
|
||||||
void *data)
|
return single_open(file, srm_env_proc_show, PDE(inode)->data);
|
||||||
|
}
|
||||||
|
|
||||||
|
static ssize_t srm_env_proc_write(struct file *file, const char __user *buffer,
|
||||||
|
size_t count, loff_t *pos)
|
||||||
{
|
{
|
||||||
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,
|
||||||
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)
|
||||||
*/
|
*/
|
||||||
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)
|
||||||
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,
|
||||||
|
|
Loading…
Reference in a new issue