Skip to content

Commit

Permalink
driver core: create a private portion of struct device
Browse files Browse the repository at this point in the history
This is to be used to move things out of struct device that no code
outside of the driver core should ever touch.

Cc: Kay Sievers <kay.sievers@vrfy.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
  • Loading branch information
Greg Kroah-Hartman committed Mar 24, 2009
1 parent b23530e commit fb069a5
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 0 deletions.
12 changes: 12 additions & 0 deletions drivers/base/base.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,18 @@ struct class_private {
#define to_class(obj) \
container_of(obj, struct class_private, class_subsys.kobj)

/**
* struct device_private - structure to hold the private to the driver core portions of the device structure.
*
* @device - pointer back to the struct class that this structure is
* associated with.
*
* Nothing outside of the driver core should ever touch these fields.
*/
struct device_private {
struct device *device;
};

/* initialisation functions */
extern int devices_init(void);
extern int buses_init(void);
Expand Down
9 changes: 9 additions & 0 deletions drivers/base/core.c
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ static struct sysfs_ops dev_sysfs_ops = {
static void device_release(struct kobject *kobj)
{
struct device *dev = to_dev(kobj);
struct device_private *p = dev->p;

if (dev->release)
dev->release(dev);
Expand All @@ -120,6 +121,7 @@ static void device_release(struct kobject *kobj)
WARN(1, KERN_ERR "Device '%s' does not have a release() "
"function, it is broken and must be fixed.\n",
dev_name(dev));
kfree(p);
}

static struct kobj_type device_ktype = {
Expand Down Expand Up @@ -859,6 +861,13 @@ int device_add(struct device *dev)
if (!dev)
goto done;

dev->p = kzalloc(sizeof(*dev->p), GFP_KERNEL);
if (!dev->p) {
error = -ENOMEM;
goto done;
}
dev->p->device = dev;

/*
* for statically allocated devices, which should all be converted
* some day, we need to initialize the name. We prevent reading back
Expand Down
3 changes: 3 additions & 0 deletions include/linux/device.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#define BUS_ID_SIZE 20

struct device;
struct device_private;
struct device_driver;
struct driver_private;
struct class;
Expand Down Expand Up @@ -373,6 +374,8 @@ struct device {
struct klist_node knode_bus;
struct device *parent;

struct device_private *p;

struct kobject kobj;
unsigned uevent_suppress:1;
const char *init_name; /* initial name of the device */
Expand Down

0 comments on commit fb069a5

Please sign in to comment.