Browse Source

driver-core: Move kobj_to_dev from genhd.h to device.h

This function is not really specific to the genhd layer and there are various
re-implementations or open-coded variants of it all throughout the kernel. To
avoid further duplications move the function to a more generic place.

While moving also convert it from a macro to a inline function.

Potential users of this function can be detected and converted using the
following coccinelle patch:

// <smpl>
@@
expression k;
@@
-container_of(k, struct device, kobj)
+kobj_to_dev(kobj)
// </smpl>

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Lars-Peter Clausen 13 years ago
parent
commit
a423296375
2 changed files with 5 additions and 1 deletions
  1. 5 0
      include/linux/device.h
  2. 0 1
      include/linux/genhd.h

+ 5 - 0
include/linux/device.h

@@ -689,6 +689,11 @@ struct device {
 	void	(*release)(struct device *dev);
 	void	(*release)(struct device *dev);
 };
 };
 
 
+static inline struct device *kobj_to_dev(struct kobject *kobj)
+{
+	return container_of(kobj, struct device, kobj);
+}
+
 /* Get the wakeup routines, which depend on struct device */
 /* Get the wakeup routines, which depend on struct device */
 #include <linux/pm_wakeup.h>
 #include <linux/pm_wakeup.h>
 
 

+ 0 - 1
include/linux/genhd.h

@@ -16,7 +16,6 @@
 
 
 #ifdef CONFIG_BLOCK
 #ifdef CONFIG_BLOCK
 
 
-#define kobj_to_dev(k)		container_of((k), struct device, kobj)
 #define dev_to_disk(device)	container_of((device), struct gendisk, part0.__dev)
 #define dev_to_disk(device)	container_of((device), struct gendisk, part0.__dev)
 #define dev_to_part(device)	container_of((device), struct hd_struct, __dev)
 #define dev_to_part(device)	container_of((device), struct hd_struct, __dev)
 #define disk_to_dev(disk)	(&(disk)->part0.__dev)
 #define disk_to_dev(disk)	(&(disk)->part0.__dev)