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)
if (!kobj || !attr)
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
* itself, and use ops for it.
*/
......@@ -300,6 +306,7 @@ static int check_perm(struct inode * inode, struct file * file)
goto Done;
Eaccess:
error = -EACCES;
module_put(attr->owner);
Done:
if (error && kobj)
kobject_put(kobj);
......@@ -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)
{
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;
if (kobj)
kobject_put(kobj);
module_put(attr->owner);
if (buffer) {
if (buffer->page)
......
......@@ -18,6 +18,7 @@
#include <linux/spinlock.h>
#include <linux/types.h>
#include <linux/ioport.h>
#include <linux/module.h>
#include <asm/semaphore.h>
#include <asm/atomic.h>
......@@ -95,7 +96,7 @@ struct bus_attribute {
#define BUS_ATTR(_name,_mode,_show,_store) \
struct bus_attribute bus_attr_##_name = { \
.attr = {.name = __stringify(_name), .mode = _mode }, \
.attr = {.name = __stringify(_name), .mode = _mode, .owner = THIS_MODULE }, \
.show = _show, \
.store = _store, \
};
......@@ -136,7 +137,7 @@ struct driver_attribute {
#define DRIVER_ATTR(_name,_mode,_show,_store) \
struct driver_attribute driver_attr_##_name = { \
.attr = {.name = __stringify(_name), .mode = _mode }, \
.attr = {.name = __stringify(_name), .mode = _mode, .owner = THIS_MODULE }, \
.show = _show, \
.store = _store, \
};
......@@ -176,7 +177,7 @@ struct class_attribute {
#define CLASS_ATTR(_name,_mode,_show,_store) \
struct class_attribute class_attr_##_name = { \
.attr = {.name = __stringify(_name), .mode = _mode }, \
.attr = {.name = __stringify(_name), .mode = _mode, .owner = THIS_MODULE }, \
.show = _show, \
.store = _store, \
};
......@@ -226,7 +227,7 @@ struct class_device_attribute {
#define CLASS_DEVICE_ATTR(_name,_mode,_show,_store) \
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, \
.store = _store, \
};
......@@ -324,7 +325,7 @@ struct device_attribute {
#define DEVICE_ATTR(_name,_mode,_show,_store) \
struct device_attribute dev_attr_##_name = { \
.attr = {.name = __stringify(_name), .mode = _mode }, \
.attr = {.name = __stringify(_name), .mode = _mode, .owner = THIS_MODULE }, \
.show = _show, \
.store = _store, \
};
......
......@@ -10,9 +10,11 @@
#define _SYSFS_H_
struct kobject;
struct module;
struct attribute {
char * name;
struct module * owner;
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