You've already forked linux-apfs
mirror of
https://github.com/linux-apfs/linux-apfs.git
synced 2026-05-01 15:00:59 -07:00
proc 2/2: remove struct proc_dir_entry::owner
Setting ->owner as done currently (pde->owner = THIS_MODULE) is racy as correctly noted at bug #12454. Someone can lookup entry with NULL ->owner, thus not pinning enything, and release it later resulting in module refcount underflow. We can keep ->owner and supply it at registration time like ->proc_fops and ->data. But this leaves ->owner as easy-manipulative field (just one C assignment) and somebody will forget to unpin previous/pin current module when switching ->owner. ->proc_fops is declared as "const" which should give some thoughts. ->read_proc/->write_proc were just fixed to not require ->owner for protection. rmmod'ed directories will be empty and return "." and ".." -- no harm. And directories with tricky enough readdir and lookup shouldn't be modular. We definitely don't want such modular code. Removing ->owner will also make PDE smaller. So, let's nuke it. Kudos to Jeff Layton for reminding about this, let's say, oversight. http://bugzilla.kernel.org/show_bug.cgi?id=12454 Signed-off-by: Alexey Dobriyan <adobriyan@gmail.com>
This commit is contained in:
@@ -117,9 +117,6 @@ static int __init init_procfs_example(void)
|
||||
rv = -ENOMEM;
|
||||
goto out;
|
||||
}
|
||||
|
||||
example_dir->owner = THIS_MODULE;
|
||||
|
||||
/* create jiffies using convenience function */
|
||||
jiffies_file = create_proc_read_entry("jiffies",
|
||||
0444, example_dir,
|
||||
@@ -130,8 +127,6 @@ static int __init init_procfs_example(void)
|
||||
goto no_jiffies;
|
||||
}
|
||||
|
||||
jiffies_file->owner = THIS_MODULE;
|
||||
|
||||
/* create foo and bar files using same callback
|
||||
* functions
|
||||
*/
|
||||
@@ -146,7 +141,6 @@ static int __init init_procfs_example(void)
|
||||
foo_file->data = &foo_data;
|
||||
foo_file->read_proc = proc_read_foobar;
|
||||
foo_file->write_proc = proc_write_foobar;
|
||||
foo_file->owner = THIS_MODULE;
|
||||
|
||||
bar_file = create_proc_entry("bar", 0644, example_dir);
|
||||
if(bar_file == NULL) {
|
||||
@@ -159,7 +153,6 @@ static int __init init_procfs_example(void)
|
||||
bar_file->data = &bar_data;
|
||||
bar_file->read_proc = proc_read_foobar;
|
||||
bar_file->write_proc = proc_write_foobar;
|
||||
bar_file->owner = THIS_MODULE;
|
||||
|
||||
/* create symlink */
|
||||
symlink = proc_symlink("jiffies_too", example_dir,
|
||||
@@ -169,8 +162,6 @@ static int __init init_procfs_example(void)
|
||||
goto no_symlink;
|
||||
}
|
||||
|
||||
symlink->owner = THIS_MODULE;
|
||||
|
||||
/* everything OK */
|
||||
printk(KERN_INFO "%s %s initialised\n",
|
||||
MODULE_NAME, MODULE_VERS);
|
||||
|
||||
@@ -218,7 +218,6 @@ srm_env_init(void)
|
||||
BASE_DIR);
|
||||
goto cleanup;
|
||||
}
|
||||
base_dir->owner = THIS_MODULE;
|
||||
|
||||
/*
|
||||
* Create per-name subdirectory
|
||||
@@ -229,7 +228,6 @@ srm_env_init(void)
|
||||
BASE_DIR, NAMED_DIR);
|
||||
goto cleanup;
|
||||
}
|
||||
named_dir->owner = THIS_MODULE;
|
||||
|
||||
/*
|
||||
* Create per-number subdirectory
|
||||
@@ -241,7 +239,6 @@ srm_env_init(void)
|
||||
goto cleanup;
|
||||
|
||||
}
|
||||
numbered_dir->owner = THIS_MODULE;
|
||||
|
||||
/*
|
||||
* Create all named nodes
|
||||
@@ -254,7 +251,6 @@ srm_env_init(void)
|
||||
goto cleanup;
|
||||
|
||||
entry->proc_entry->data = (void *) entry;
|
||||
entry->proc_entry->owner = THIS_MODULE;
|
||||
entry->proc_entry->read_proc = srm_env_read;
|
||||
entry->proc_entry->write_proc = srm_env_write;
|
||||
|
||||
@@ -275,7 +271,6 @@ srm_env_init(void)
|
||||
|
||||
entry->id = var_num;
|
||||
entry->proc_entry->data = (void *) entry;
|
||||
entry->proc_entry->owner = THIS_MODULE;
|
||||
entry->proc_entry->read_proc = srm_env_read;
|
||||
entry->proc_entry->write_proc = srm_env_write;
|
||||
}
|
||||
|
||||
@@ -854,7 +854,6 @@ static int __init sram_proc_init(void)
|
||||
printk(KERN_WARNING "unable to create /proc/sram\n");
|
||||
return -1;
|
||||
}
|
||||
ptr->owner = THIS_MODULE;
|
||||
ptr->read_proc = sram_proc_read;
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -1002,8 +1002,6 @@ create_palinfo_proc_entries(unsigned int cpu)
|
||||
*pdir = create_proc_read_entry(
|
||||
palinfo_entries[j].name, 0, cpu_dir,
|
||||
palinfo_read_entry, (void *)f.value);
|
||||
if (*pdir)
|
||||
(*pdir)->owner = THIS_MODULE;
|
||||
pdir++;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -225,7 +225,6 @@ static struct proc_dir_entry *sgi_prominfo_entry;
|
||||
int __init prominfo_init(void)
|
||||
{
|
||||
struct proc_dir_entry **entp;
|
||||
struct proc_dir_entry *p;
|
||||
cnodeid_t cnodeid;
|
||||
unsigned long nasid;
|
||||
int size;
|
||||
@@ -246,14 +245,10 @@ int __init prominfo_init(void)
|
||||
sprintf(name, "node%d", cnodeid);
|
||||
*entp = proc_mkdir(name, sgi_prominfo_entry);
|
||||
nasid = cnodeid_to_nasid(cnodeid);
|
||||
p = create_proc_read_entry("fit", 0, *entp, read_fit_entry,
|
||||
create_proc_read_entry("fit", 0, *entp, read_fit_entry,
|
||||
(void *)nasid);
|
||||
if (p)
|
||||
p->owner = THIS_MODULE;
|
||||
p = create_proc_read_entry("version", 0, *entp,
|
||||
create_proc_read_entry("version", 0, *entp,
|
||||
read_version_entry, (void *)nasid);
|
||||
if (p)
|
||||
p->owner = THIS_MODULE;
|
||||
entp++;
|
||||
}
|
||||
|
||||
|
||||
@@ -669,7 +669,6 @@ static void remove_flash_pde(struct proc_dir_entry *dp)
|
||||
{
|
||||
if (dp) {
|
||||
kfree(dp->data);
|
||||
dp->owner = NULL;
|
||||
remove_proc_entry(dp->name, dp->parent);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -126,7 +126,6 @@ static int __init led_init(void)
|
||||
led = proc_create("led", 0, NULL, &led_proc_fops);
|
||||
if (!led)
|
||||
return -ENOMEM;
|
||||
led->owner = THIS_MODULE;
|
||||
|
||||
printk(KERN_INFO
|
||||
"led: version %s, Lars Kotthoff <metalhead@metalhead.ws>\n",
|
||||
|
||||
@@ -377,10 +377,6 @@ static const struct file_operations mtrr_fops = {
|
||||
.release = mtrr_close,
|
||||
};
|
||||
|
||||
|
||||
static struct proc_dir_entry *proc_root_mtrr;
|
||||
|
||||
|
||||
static int mtrr_seq_show(struct seq_file *seq, void *offset)
|
||||
{
|
||||
char factor;
|
||||
@@ -423,11 +419,7 @@ static int __init mtrr_if_init(void)
|
||||
(!cpu_has(c, X86_FEATURE_CENTAUR_MCR)))
|
||||
return -ENODEV;
|
||||
|
||||
proc_root_mtrr =
|
||||
proc_create("mtrr", S_IWUSR | S_IRUGO, NULL, &mtrr_fops);
|
||||
|
||||
if (proc_root_mtrr)
|
||||
proc_root_mtrr->owner = THIS_MODULE;
|
||||
proc_create("mtrr", S_IWUSR | S_IRUGO, NULL, &mtrr_fops);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
@@ -191,7 +191,6 @@ static int acpi_ac_add_fs(struct acpi_device *device)
|
||||
acpi_ac_dir);
|
||||
if (!acpi_device_dir(device))
|
||||
return -ENODEV;
|
||||
acpi_device_dir(device)->owner = THIS_MODULE;
|
||||
}
|
||||
|
||||
/* 'state' [R] */
|
||||
|
||||
@@ -760,7 +760,6 @@ static int acpi_battery_add_fs(struct acpi_device *device)
|
||||
acpi_battery_dir);
|
||||
if (!acpi_device_dir(device))
|
||||
return -ENODEV;
|
||||
acpi_device_dir(device)->owner = THIS_MODULE;
|
||||
}
|
||||
|
||||
for (i = 0; i < ACPI_BATTERY_NUMFILES; ++i) {
|
||||
|
||||
@@ -200,12 +200,10 @@ static int acpi_button_add_fs(struct acpi_device *device)
|
||||
|
||||
if (!entry)
|
||||
return -ENODEV;
|
||||
entry->owner = THIS_MODULE;
|
||||
|
||||
acpi_device_dir(device) = proc_mkdir(acpi_device_bid(device), entry);
|
||||
if (!acpi_device_dir(device))
|
||||
return -ENODEV;
|
||||
acpi_device_dir(device)->owner = THIS_MODULE;
|
||||
|
||||
/* 'info' [R] */
|
||||
entry = proc_create_data(ACPI_BUTTON_FILE_INFO,
|
||||
@@ -522,7 +520,6 @@ static int __init acpi_button_init(void)
|
||||
acpi_button_dir = proc_mkdir(ACPI_BUTTON_CLASS, acpi_root_dir);
|
||||
if (!acpi_button_dir)
|
||||
return -ENODEV;
|
||||
acpi_button_dir->owner = THIS_MODULE;
|
||||
result = acpi_bus_register_driver(&acpi_button_driver);
|
||||
if (result < 0) {
|
||||
remove_proc_entry(ACPI_BUTTON_CLASS, acpi_root_dir);
|
||||
|
||||
@@ -193,7 +193,6 @@ static int acpi_fan_add_fs(struct acpi_device *device)
|
||||
acpi_fan_dir);
|
||||
if (!acpi_device_dir(device))
|
||||
return -ENODEV;
|
||||
acpi_device_dir(device)->owner = THIS_MODULE;
|
||||
}
|
||||
|
||||
/* 'status' [R/W] */
|
||||
@@ -347,7 +346,6 @@ static int __init acpi_fan_init(void)
|
||||
acpi_fan_dir = proc_mkdir(ACPI_FAN_CLASS, acpi_root_dir);
|
||||
if (!acpi_fan_dir)
|
||||
return -ENODEV;
|
||||
acpi_fan_dir->owner = THIS_MODULE;
|
||||
#endif
|
||||
|
||||
result = acpi_bus_register_driver(&acpi_fan_driver);
|
||||
|
||||
@@ -359,7 +359,6 @@ static int acpi_processor_add_fs(struct acpi_device *device)
|
||||
if (!acpi_device_dir(device))
|
||||
return -ENODEV;
|
||||
}
|
||||
acpi_device_dir(device)->owner = THIS_MODULE;
|
||||
|
||||
/* 'info' [R] */
|
||||
entry = proc_create_data(ACPI_PROCESSOR_FILE_INFO,
|
||||
@@ -1137,7 +1136,6 @@ static int __init acpi_processor_init(void)
|
||||
acpi_processor_dir = proc_mkdir(ACPI_PROCESSOR_CLASS, acpi_root_dir);
|
||||
if (!acpi_processor_dir)
|
||||
return -ENOMEM;
|
||||
acpi_processor_dir->owner = THIS_MODULE;
|
||||
|
||||
/*
|
||||
* Check whether the system is DMI table. If yes, OSPM
|
||||
|
||||
@@ -488,7 +488,6 @@ acpi_sbs_add_fs(struct proc_dir_entry **dir,
|
||||
if (!*dir) {
|
||||
return -ENODEV;
|
||||
}
|
||||
(*dir)->owner = THIS_MODULE;
|
||||
}
|
||||
|
||||
/* 'info' [R] */
|
||||
|
||||
@@ -1506,7 +1506,6 @@ static int acpi_thermal_add_fs(struct acpi_device *device)
|
||||
acpi_thermal_dir);
|
||||
if (!acpi_device_dir(device))
|
||||
return -ENODEV;
|
||||
acpi_device_dir(device)->owner = THIS_MODULE;
|
||||
}
|
||||
|
||||
/* 'state' [R] */
|
||||
@@ -1875,7 +1874,6 @@ static int __init acpi_thermal_init(void)
|
||||
acpi_thermal_dir = proc_mkdir(ACPI_THERMAL_CLASS, acpi_root_dir);
|
||||
if (!acpi_thermal_dir)
|
||||
return -ENODEV;
|
||||
acpi_thermal_dir->owner = THIS_MODULE;
|
||||
|
||||
result = acpi_bus_register_driver(&acpi_thermal_driver);
|
||||
if (result < 0) {
|
||||
|
||||
@@ -1125,8 +1125,6 @@ static int acpi_video_device_add_fs(struct acpi_device *device)
|
||||
if (!device_dir)
|
||||
return -ENOMEM;
|
||||
|
||||
device_dir->owner = THIS_MODULE;
|
||||
|
||||
/* 'info' [R] */
|
||||
entry = proc_create_data("info", S_IRUGO, device_dir,
|
||||
&acpi_video_device_info_fops, acpi_driver_data(device));
|
||||
@@ -1403,8 +1401,6 @@ static int acpi_video_bus_add_fs(struct acpi_device *device)
|
||||
if (!device_dir)
|
||||
return -ENOMEM;
|
||||
|
||||
device_dir->owner = THIS_MODULE;
|
||||
|
||||
/* 'info' [R] */
|
||||
entry = proc_create_data("info", S_IRUGO, device_dir,
|
||||
&acpi_video_bus_info_fops,
|
||||
@@ -2131,7 +2127,6 @@ static int __init acpi_video_init(void)
|
||||
acpi_video_dir = proc_mkdir(ACPI_VIDEO_CLASS, acpi_root_dir);
|
||||
if (!acpi_video_dir)
|
||||
return -ENODEV;
|
||||
acpi_video_dir->owner = THIS_MODULE;
|
||||
|
||||
result = acpi_bus_register_driver(&acpi_video_bus);
|
||||
if (result < 0) {
|
||||
|
||||
@@ -551,8 +551,6 @@ static void __devinit ps3vram_proc_init(struct ps3_system_bus_device *dev)
|
||||
dev_warn(&dev->core, "failed to create /proc entry\n");
|
||||
return;
|
||||
}
|
||||
|
||||
pde->owner = THIS_MODULE;
|
||||
pde->data = priv;
|
||||
}
|
||||
|
||||
|
||||
@@ -1944,7 +1944,7 @@ static int stat_file_read_proc(char *page, char **start, off_t off,
|
||||
|
||||
int ipmi_smi_add_proc_entry(ipmi_smi_t smi, char *name,
|
||||
read_proc_t *read_proc,
|
||||
void *data, struct module *owner)
|
||||
void *data)
|
||||
{
|
||||
int rv = 0;
|
||||
#ifdef CONFIG_PROC_FS
|
||||
@@ -1970,7 +1970,6 @@ int ipmi_smi_add_proc_entry(ipmi_smi_t smi, char *name,
|
||||
} else {
|
||||
file->data = data;
|
||||
file->read_proc = read_proc;
|
||||
file->owner = owner;
|
||||
|
||||
mutex_lock(&smi->proc_entry_lock);
|
||||
/* Stick it on the list. */
|
||||
@@ -1993,23 +1992,21 @@ static int add_proc_entries(ipmi_smi_t smi, int num)
|
||||
smi->proc_dir = proc_mkdir(smi->proc_dir_name, proc_ipmi_root);
|
||||
if (!smi->proc_dir)
|
||||
rv = -ENOMEM;
|
||||
else
|
||||
smi->proc_dir->owner = THIS_MODULE;
|
||||
|
||||
if (rv == 0)
|
||||
rv = ipmi_smi_add_proc_entry(smi, "stats",
|
||||
stat_file_read_proc,
|
||||
smi, THIS_MODULE);
|
||||
smi);
|
||||
|
||||
if (rv == 0)
|
||||
rv = ipmi_smi_add_proc_entry(smi, "ipmb",
|
||||
ipmb_file_read_proc,
|
||||
smi, THIS_MODULE);
|
||||
smi);
|
||||
|
||||
if (rv == 0)
|
||||
rv = ipmi_smi_add_proc_entry(smi, "version",
|
||||
version_file_read_proc,
|
||||
smi, THIS_MODULE);
|
||||
smi);
|
||||
#endif /* CONFIG_PROC_FS */
|
||||
|
||||
return rv;
|
||||
@@ -4265,7 +4262,6 @@ static int ipmi_init_msghandler(void)
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
||||
proc_ipmi_root->owner = THIS_MODULE;
|
||||
#endif /* CONFIG_PROC_FS */
|
||||
|
||||
setup_timer(&ipmi_timer, ipmi_timeout, 0);
|
||||
|
||||
@@ -2899,7 +2899,7 @@ static int try_smi_init(struct smi_info *new_smi)
|
||||
|
||||
rv = ipmi_smi_add_proc_entry(new_smi->intf, "type",
|
||||
type_file_read_proc,
|
||||
new_smi, THIS_MODULE);
|
||||
new_smi);
|
||||
if (rv) {
|
||||
printk(KERN_ERR
|
||||
"ipmi_si: Unable to create proc entry: %d\n",
|
||||
@@ -2909,7 +2909,7 @@ static int try_smi_init(struct smi_info *new_smi)
|
||||
|
||||
rv = ipmi_smi_add_proc_entry(new_smi->intf, "si_stats",
|
||||
stat_file_read_proc,
|
||||
new_smi, THIS_MODULE);
|
||||
new_smi);
|
||||
if (rv) {
|
||||
printk(KERN_ERR
|
||||
"ipmi_si: Unable to create proc entry: %d\n",
|
||||
@@ -2919,7 +2919,7 @@ static int try_smi_init(struct smi_info *new_smi)
|
||||
|
||||
rv = ipmi_smi_add_proc_entry(new_smi->intf, "params",
|
||||
param_read_proc,
|
||||
new_smi, THIS_MODULE);
|
||||
new_smi);
|
||||
if (rv) {
|
||||
printk(KERN_ERR
|
||||
"ipmi_si: Unable to create proc entry: %d\n",
|
||||
|
||||
@@ -903,8 +903,6 @@ static int __init input_proc_init(void)
|
||||
if (!proc_bus_input_dir)
|
||||
return -ENOMEM;
|
||||
|
||||
proc_bus_input_dir->owner = THIS_MODULE;
|
||||
|
||||
entry = proc_create("devices", 0, proc_bus_input_dir,
|
||||
&input_devices_fileops);
|
||||
if (!entry)
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user