Commit 1cf6d20f authored by Greg Kroah-Hartman's avatar Greg Kroah-Hartman

[PATCH] SYSFS: add module referencing to sysfs attribute files.

parent 687c7f9e
...@@ -247,6 +247,12 @@ static int check_perm(struct inode * inode, struct file * file) ...@@ -247,6 +247,12 @@ static int check_perm(struct inode * inode, struct file * file)
if (!kobj || !attr) if (!kobj || !attr)
goto Einval; goto Einval;
/* Grab the module reference for this attribute if we have one */
if (!try_module_get(attr->owner)) {
error = -ENODEV;
goto Done;
}
/* if the kobject has no ktype, then we assume that it is a subsystem /* if the kobject has no ktype, then we assume that it is a subsystem
* itself, and use ops for it. * itself, and use ops for it.
*/ */
...@@ -300,6 +306,7 @@ static int check_perm(struct inode * inode, struct file * file) ...@@ -300,6 +306,7 @@ static int check_perm(struct inode * inode, struct file * file)
goto Done; goto Done;
Eaccess: Eaccess:
error = -EACCES; error = -EACCES;
module_put(attr->owner);
Done: Done:
if (error && kobj) if (error && kobj)
kobject_put(kobj); kobject_put(kobj);
...@@ -314,10 +321,12 @@ static int sysfs_open_file(struct inode * inode, struct file * filp) ...@@ -314,10 +321,12 @@ static int sysfs_open_file(struct inode * inode, struct file * filp)
static int sysfs_release(struct inode * inode, struct file * filp) static int sysfs_release(struct inode * inode, struct file * filp)
{ {
struct kobject * kobj = filp->f_dentry->d_parent->d_fsdata; struct kobject * kobj = filp->f_dentry->d_parent->d_fsdata;
struct attribute * attr = filp->f_dentry->d_fsdata;
struct sysfs_buffer * buffer = filp->private_data; struct sysfs_buffer * buffer = filp->private_data;
if (kobj) if (kobj)
kobject_put(kobj); kobject_put(kobj);
module_put(attr->owner);
if (buffer) { if (buffer) {
if (buffer->page) if (buffer->page)
......
...@@ -18,6 +18,7 @@ ...@@ -18,6 +18,7 @@
#include <linux/spinlock.h> #include <linux/spinlock.h>
#include <linux/types.h> #include <linux/types.h>
#include <linux/ioport.h> #include <linux/ioport.h>
#include <linux/module.h>
#include <asm/semaphore.h> #include <asm/semaphore.h>
#include <asm/atomic.h> #include <asm/atomic.h>
...@@ -95,7 +96,7 @@ struct bus_attribute { ...@@ -95,7 +96,7 @@ struct bus_attribute {
#define BUS_ATTR(_name,_mode,_show,_store) \ #define BUS_ATTR(_name,_mode,_show,_store) \
struct bus_attribute bus_attr_##_name = { \ struct bus_attribute bus_attr_##_name = { \
.attr = {.name = __stringify(_name), .mode = _mode }, \ .attr = {.name = __stringify(_name), .mode = _mode, .owner = THIS_MODULE }, \
.show = _show, \ .show = _show, \
.store = _store, \ .store = _store, \
}; };
...@@ -136,7 +137,7 @@ struct driver_attribute { ...@@ -136,7 +137,7 @@ struct driver_attribute {
#define DRIVER_ATTR(_name,_mode,_show,_store) \ #define DRIVER_ATTR(_name,_mode,_show,_store) \
struct driver_attribute driver_attr_##_name = { \ struct driver_attribute driver_attr_##_name = { \
.attr = {.name = __stringify(_name), .mode = _mode }, \ .attr = {.name = __stringify(_name), .mode = _mode, .owner = THIS_MODULE }, \
.show = _show, \ .show = _show, \
.store = _store, \ .store = _store, \
}; };
...@@ -176,7 +177,7 @@ struct class_attribute { ...@@ -176,7 +177,7 @@ struct class_attribute {
#define CLASS_ATTR(_name,_mode,_show,_store) \ #define CLASS_ATTR(_name,_mode,_show,_store) \
struct class_attribute class_attr_##_name = { \ struct class_attribute class_attr_##_name = { \
.attr = {.name = __stringify(_name), .mode = _mode }, \ .attr = {.name = __stringify(_name), .mode = _mode, .owner = THIS_MODULE }, \
.show = _show, \ .show = _show, \
.store = _store, \ .store = _store, \
}; };
...@@ -226,7 +227,7 @@ struct class_device_attribute { ...@@ -226,7 +227,7 @@ struct class_device_attribute {
#define CLASS_DEVICE_ATTR(_name,_mode,_show,_store) \ #define CLASS_DEVICE_ATTR(_name,_mode,_show,_store) \
struct class_device_attribute class_device_attr_##_name = { \ struct class_device_attribute class_device_attr_##_name = { \
.attr = {.name = __stringify(_name), .mode = _mode }, \ .attr = {.name = __stringify(_name), .mode = _mode, .owner = THIS_MODULE }, \
.show = _show, \ .show = _show, \
.store = _store, \ .store = _store, \
}; };
...@@ -324,7 +325,7 @@ struct device_attribute { ...@@ -324,7 +325,7 @@ struct device_attribute {
#define DEVICE_ATTR(_name,_mode,_show,_store) \ #define DEVICE_ATTR(_name,_mode,_show,_store) \
struct device_attribute dev_attr_##_name = { \ struct device_attribute dev_attr_##_name = { \
.attr = {.name = __stringify(_name), .mode = _mode }, \ .attr = {.name = __stringify(_name), .mode = _mode, .owner = THIS_MODULE }, \
.show = _show, \ .show = _show, \
.store = _store, \ .store = _store, \
}; };
......
...@@ -10,9 +10,11 @@ ...@@ -10,9 +10,11 @@
#define _SYSFS_H_ #define _SYSFS_H_
struct kobject; struct kobject;
struct module;
struct attribute { struct attribute {
char * name; char * name;
struct module * owner;
mode_t mode; mode_t mode;
}; };
......
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