Commit c7705f34 authored by Denis V. Lunev's avatar Denis V. Lunev Committed by Linus Torvalds

drivers: use non-racy method for proc entries creation (2)

Use proc_create()/proc_create_data() to make sure that ->proc_fops and ->data
be setup before gluing PDE to main tree.
Signed-off-by: default avatarDenis V. Lunev <den@openvz.org>
Cc: Greg Kroah-Hartman <gregkh@suse.de>
Cc: Alexey Dobriyan <adobriyan@gmail.com>
Cc: "Eric W. Biederman" <ebiederm@xmission.com>
Cc: Peter Osterlund <petero2@telia.com>
Cc: Bartlomiej Zolnierkiewicz <bzolnier@gmail.com>
Cc: Dmitry Torokhov <dtor@mail.ru>
Cc: Neil Brown <neilb@suse.de>
Cc: Mauro Carvalho Chehab <mchehab@infradead.org>
Cc: Bjorn Helgaas <bjorn.helgaas@hp.com>
Cc: Alessandro Zummo <a.zummo@towertech.it>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent 1b502217
...@@ -2744,7 +2744,6 @@ static int pkt_new_dev(struct pktcdvd_device *pd, dev_t dev) ...@@ -2744,7 +2744,6 @@ static int pkt_new_dev(struct pktcdvd_device *pd, dev_t dev)
int i; int i;
int ret = 0; int ret = 0;
char b[BDEVNAME_SIZE]; char b[BDEVNAME_SIZE];
struct proc_dir_entry *proc;
struct block_device *bdev; struct block_device *bdev;
if (pd->pkt_dev == dev) { if (pd->pkt_dev == dev) {
...@@ -2788,11 +2787,7 @@ static int pkt_new_dev(struct pktcdvd_device *pd, dev_t dev) ...@@ -2788,11 +2787,7 @@ static int pkt_new_dev(struct pktcdvd_device *pd, dev_t dev)
goto out_mem; goto out_mem;
} }
proc = create_proc_entry(pd->name, 0, pkt_proc); proc_create_data(pd->name, 0, pkt_proc, &pkt_proc_fops, pd);
if (proc) {
proc->data = pd;
proc->proc_fops = &pkt_proc_fops;
}
DPRINTK(DRIVER_NAME": writer %s mapped to %s\n", pd->name, bdevname(bdev, b)); DPRINTK(DRIVER_NAME": writer %s mapped to %s\n", pd->name, bdevname(bdev, b));
return 0; return 0;
......
...@@ -144,6 +144,7 @@ static int proc_viocd_open(struct inode *inode, struct file *file) ...@@ -144,6 +144,7 @@ static int proc_viocd_open(struct inode *inode, struct file *file)
} }
static const struct file_operations proc_viocd_operations = { static const struct file_operations proc_viocd_operations = {
.owner = THIS_MODULE,
.open = proc_viocd_open, .open = proc_viocd_open,
.read = seq_read, .read = seq_read,
.llseek = seq_lseek, .llseek = seq_lseek,
...@@ -679,7 +680,6 @@ static struct vio_driver viocd_driver = { ...@@ -679,7 +680,6 @@ static struct vio_driver viocd_driver = {
static int __init viocd_init(void) static int __init viocd_init(void)
{ {
struct proc_dir_entry *e;
int ret = 0; int ret = 0;
if (!firmware_has_feature(FW_FEATURE_ISERIES)) if (!firmware_has_feature(FW_FEATURE_ISERIES))
...@@ -719,12 +719,8 @@ static int __init viocd_init(void) ...@@ -719,12 +719,8 @@ static int __init viocd_init(void)
if (ret) if (ret)
goto out_free_info; goto out_free_info;
e = create_proc_entry("iSeries/viocd", S_IFREG|S_IRUGO, NULL); proc_create("iSeries/viocd", S_IFREG|S_IRUGO, NULL,
if (e) { &proc_viocd_operations);
e->owner = THIS_MODULE;
e->proc_fops = &proc_viocd_operations;
}
return 0; return 0;
out_free_info: out_free_info:
......
...@@ -822,6 +822,7 @@ static int ide_drivers_open(struct inode *inode, struct file *file) ...@@ -822,6 +822,7 @@ static int ide_drivers_open(struct inode *inode, struct file *file)
} }
static const struct file_operations ide_drivers_operations = { static const struct file_operations ide_drivers_operations = {
.owner = THIS_MODULE,
.open = ide_drivers_open, .open = ide_drivers_open,
.read = seq_read, .read = seq_read,
.llseek = seq_lseek, .llseek = seq_lseek,
...@@ -830,16 +831,12 @@ static const struct file_operations ide_drivers_operations = { ...@@ -830,16 +831,12 @@ static const struct file_operations ide_drivers_operations = {
void proc_ide_create(void) void proc_ide_create(void)
{ {
struct proc_dir_entry *entry;
proc_ide_root = proc_mkdir("ide", NULL); proc_ide_root = proc_mkdir("ide", NULL);
if (!proc_ide_root) if (!proc_ide_root)
return; return;
entry = create_proc_entry("drivers", 0, proc_ide_root); proc_create("drivers", 0, proc_ide_root, &ide_drivers_operations);
if (entry)
entry->proc_fops = &ide_drivers_operations;
} }
void proc_ide_destroy(void) void proc_ide_destroy(void)
......
...@@ -904,20 +904,16 @@ static int __init input_proc_init(void) ...@@ -904,20 +904,16 @@ static int __init input_proc_init(void)
proc_bus_input_dir->owner = THIS_MODULE; proc_bus_input_dir->owner = THIS_MODULE;
entry = create_proc_entry("devices", 0, proc_bus_input_dir); entry = proc_create("devices", 0, proc_bus_input_dir,
&input_devices_fileops);
if (!entry) if (!entry)
goto fail1; goto fail1;
entry->owner = THIS_MODULE; entry = proc_create("handlers", 0, proc_bus_input_dir,
entry->proc_fops = &input_devices_fileops; &input_handlers_fileops);
entry = create_proc_entry("handlers", 0, proc_bus_input_dir);
if (!entry) if (!entry)
goto fail2; goto fail2;
entry->owner = THIS_MODULE;
entry->proc_fops = &input_handlers_fileops;
return 0; return 0;
fail2: remove_proc_entry("devices", proc_bus_input_dir); fail2: remove_proc_entry("devices", proc_bus_input_dir);
......
...@@ -5947,13 +5947,9 @@ static struct notifier_block md_notifier = { ...@@ -5947,13 +5947,9 @@ static struct notifier_block md_notifier = {
static void md_geninit(void) static void md_geninit(void)
{ {
struct proc_dir_entry *p;
dprintk("md: sizeof(mdp_super_t) = %d\n", (int)sizeof(mdp_super_t)); dprintk("md: sizeof(mdp_super_t) = %d\n", (int)sizeof(mdp_super_t));
p = create_proc_entry("mdstat", S_IRUGO, NULL); proc_create("mdstat", S_IRUGO, NULL, &md_seq_fops);
if (p)
p->proc_fops = &md_seq_fops;
} }
static int __init md_init(void) static int __init md_init(void)
......
...@@ -180,6 +180,7 @@ static ssize_t zoran_write(struct file *file, const char __user *buffer, ...@@ -180,6 +180,7 @@ static ssize_t zoran_write(struct file *file, const char __user *buffer,
} }
static const struct file_operations zoran_operations = { static const struct file_operations zoran_operations = {
.owner = THIS_MODULE,
.open = zoran_open, .open = zoran_open,
.read = seq_read, .read = seq_read,
.write = zoran_write, .write = zoran_write,
...@@ -195,10 +196,8 @@ zoran_proc_init (struct zoran *zr) ...@@ -195,10 +196,8 @@ zoran_proc_init (struct zoran *zr)
char name[8]; char name[8];
snprintf(name, 7, "zoran%d", zr->id); snprintf(name, 7, "zoran%d", zr->id);
if ((zr->zoran_proc = create_proc_entry(name, 0, NULL))) { zr->zoran_proc = proc_create_data(name, 0, NULL, &zoran_operations, zr);
zr->zoran_proc->data = zr; if (zr->zoran_proc != NULL) {
zr->zoran_proc->owner = THIS_MODULE;
zr->zoran_proc->proc_fops = &zoran_operations;
dprintk(2, dprintk(2,
KERN_INFO KERN_INFO
"%s: procfs entry /proc/%s allocated. data=%p\n", "%s: procfs entry /proc/%s allocated. data=%p\n",
......
...@@ -1893,13 +1893,11 @@ static int i2o_proc_create_entries(struct proc_dir_entry *dir, ...@@ -1893,13 +1893,11 @@ static int i2o_proc_create_entries(struct proc_dir_entry *dir,
struct proc_dir_entry *tmp; struct proc_dir_entry *tmp;
while (i2o_pe->name) { while (i2o_pe->name) {
tmp = create_proc_entry(i2o_pe->name, i2o_pe->mode, dir); tmp = proc_create_data(i2o_pe->name, i2o_pe->mode, dir,
i2o_pe->fops, data);
if (!tmp) if (!tmp)
return -1; return -1;
tmp->data = data;
tmp->proc_fops = i2o_pe->fops;
i2o_pe++; i2o_pe++;
} }
......
...@@ -210,13 +210,10 @@ static int hdpu_cpustate_probe(struct platform_device *pdev) ...@@ -210,13 +210,10 @@ static int hdpu_cpustate_probe(struct platform_device *pdev)
return ret; return ret;
} }
proc_de = create_proc_entry("sky_cpustate", 0666, NULL); proc_de = proc_create("sky_cpustate", 0666, NULL, &proc_cpustate);
if (!proc_de) { if (!proc_de) {
printk(KERN_WARNING "sky_cpustate: " printk(KERN_WARNING "sky_cpustate: "
"Unable to create proc entry\n"); "Unable to create proc entry\n");
} else {
proc_de->proc_fops = &proc_cpustate;
proc_de->owner = THIS_MODULE;
} }
printk(KERN_INFO "Sky CPU State Driver v" SKY_CPUSTATE_VERSION "\n"); printk(KERN_INFO "Sky CPU State Driver v" SKY_CPUSTATE_VERSION "\n");
......
...@@ -102,22 +102,17 @@ static int hdpu_nexus_probe(struct platform_device *pdev) ...@@ -102,22 +102,17 @@ static int hdpu_nexus_probe(struct platform_device *pdev)
printk(KERN_ERR "sky_nexus: Could not map slot id\n"); printk(KERN_ERR "sky_nexus: Could not map slot id\n");
} }
hdpu_slot_id = create_proc_entry("sky_slot_id", 0666, NULL); hdpu_slot_id = proc_create("sky_slot_id", 0666, NULL, &proc_slot_id);
if (!hdpu_slot_id) if (!hdpu_slot_id) {
printk(KERN_WARNING "sky_nexus: " printk(KERN_WARNING "sky_nexus: "
"Unable to create proc dir entry: sky_slot_id\n"); "Unable to create proc dir entry: sky_slot_id\n");
} else {
hdpu_slot_id->proc_fops = &proc_slot_id;
hdpu_slot_id->owner = THIS_MODULE;
} }
hdpu_chassis_id = create_proc_entry("sky_chassis_id", 0666, NULL); hdpu_chassis_id = proc_create("sky_chassis_id", 0666, NULL,
&proc_chassis_id);
if (!hdpu_chassis_id) if (!hdpu_chassis_id)
printk(KERN_WARNING "sky_nexus: " printk(KERN_WARNING "sky_nexus: "
"Unable to create proc dir entry: sky_chassis_id\n"); "Unable to create proc dir entry: sky_chassis_id\n");
} else {
hdpu_chassis_id->proc_fops = &proc_chassis_id;
hdpu_chassis_id->owner = THIS_MODULE;
} }
return 0; return 0;
......
...@@ -293,6 +293,7 @@ static int proc_bus_pci_release(struct inode *inode, struct file *file) ...@@ -293,6 +293,7 @@ static int proc_bus_pci_release(struct inode *inode, struct file *file)
#endif /* HAVE_PCI_MMAP */ #endif /* HAVE_PCI_MMAP */
static const struct file_operations proc_bus_pci_operations = { static const struct file_operations proc_bus_pci_operations = {
.owner = THIS_MODULE,
.llseek = proc_bus_pci_lseek, .llseek = proc_bus_pci_lseek,
.read = proc_bus_pci_read, .read = proc_bus_pci_read,
.write = proc_bus_pci_write, .write = proc_bus_pci_write,
...@@ -406,11 +407,10 @@ int pci_proc_attach_device(struct pci_dev *dev) ...@@ -406,11 +407,10 @@ int pci_proc_attach_device(struct pci_dev *dev)
} }
sprintf(name, "%02x.%x", PCI_SLOT(dev->devfn), PCI_FUNC(dev->devfn)); sprintf(name, "%02x.%x", PCI_SLOT(dev->devfn), PCI_FUNC(dev->devfn));
e = create_proc_entry(name, S_IFREG | S_IRUGO | S_IWUSR, bus->procdir); e = proc_create_data(name, S_IFREG | S_IRUGO | S_IWUSR, bus->procdir,
&proc_bus_pci_operations, dev);
if (!e) if (!e)
return -ENOMEM; return -ENOMEM;
e->proc_fops = &proc_bus_pci_operations;
e->data = dev;
e->size = dev->cfg_size; e->size = dev->cfg_size;
dev->procent = e; dev->procent = e;
...@@ -462,6 +462,7 @@ static int proc_bus_pci_dev_open(struct inode *inode, struct file *file) ...@@ -462,6 +462,7 @@ static int proc_bus_pci_dev_open(struct inode *inode, struct file *file)
return seq_open(file, &proc_bus_pci_devices_op); return seq_open(file, &proc_bus_pci_devices_op);
} }
static const struct file_operations proc_bus_pci_dev_operations = { static const struct file_operations proc_bus_pci_dev_operations = {
.owner = THIS_MODULE,
.open = proc_bus_pci_dev_open, .open = proc_bus_pci_dev_open,
.read = seq_read, .read = seq_read,
.llseek = seq_lseek, .llseek = seq_lseek,
...@@ -470,12 +471,10 @@ static const struct file_operations proc_bus_pci_dev_operations = { ...@@ -470,12 +471,10 @@ static const struct file_operations proc_bus_pci_dev_operations = {
static int __init pci_proc_init(void) static int __init pci_proc_init(void)
{ {
struct proc_dir_entry *entry;
struct pci_dev *dev = NULL; struct pci_dev *dev = NULL;
proc_bus_pci_dir = proc_mkdir("bus/pci", NULL); proc_bus_pci_dir = proc_mkdir("bus/pci", NULL);
entry = create_proc_entry("devices", 0, proc_bus_pci_dir); proc_create("devices", 0, proc_bus_pci_dir,
if (entry) &proc_bus_pci_dev_operations);
entry->proc_fops = &proc_bus_pci_dev_operations;
proc_initialized = 1; proc_initialized = 1;
while ((dev = pci_get_device(PCI_ANY_ID, PCI_ANY_ID, dev)) != NULL) { while ((dev = pci_get_device(PCI_ANY_ID, PCI_ANY_ID, dev)) != NULL) {
pci_proc_attach_device(dev); pci_proc_attach_device(dev);
......
...@@ -85,6 +85,7 @@ static ssize_t isapnp_proc_bus_read(struct file *file, char __user * buf, ...@@ -85,6 +85,7 @@ static ssize_t isapnp_proc_bus_read(struct file *file, char __user * buf,
} }
static const struct file_operations isapnp_proc_bus_file_operations = { static const struct file_operations isapnp_proc_bus_file_operations = {
.owner = THIS_MODULE,
.llseek = isapnp_proc_bus_lseek, .llseek = isapnp_proc_bus_lseek,
.read = isapnp_proc_bus_read, .read = isapnp_proc_bus_read,
}; };
...@@ -102,12 +103,10 @@ static int isapnp_proc_attach_device(struct pnp_dev *dev) ...@@ -102,12 +103,10 @@ static int isapnp_proc_attach_device(struct pnp_dev *dev)
return -ENOMEM; return -ENOMEM;
} }
sprintf(name, "%02x", dev->number); sprintf(name, "%02x", dev->number);
e = dev->procent = create_proc_entry(name, S_IFREG | S_IRUGO, de); e = dev->procent = proc_create_data(name, S_IFREG | S_IRUGO, de,
&isapnp_proc_bus_file_operations, dev);
if (!e) if (!e)
return -ENOMEM; return -ENOMEM;
e->proc_fops = &isapnp_proc_bus_file_operations;
e->owner = THIS_MODULE;
e->data = dev;
e->size = 256; e->size = 256;
return 0; return 0;
} }
......
...@@ -108,12 +108,10 @@ void rtc_proc_add_device(struct rtc_device *rtc) ...@@ -108,12 +108,10 @@ void rtc_proc_add_device(struct rtc_device *rtc)
if (rtc->id == 0) { if (rtc->id == 0) {
struct proc_dir_entry *ent; struct proc_dir_entry *ent;
ent = create_proc_entry("driver/rtc", 0, NULL); ent = proc_create_data("driver/rtc", 0, NULL,
if (ent) { &rtc_proc_fops, rtc);
ent->proc_fops = &rtc_proc_fops; if (ent)
ent->owner = rtc->owner; ent->owner = rtc->owner;
ent->data = rtc;
}
} }
} }
......
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