diff options
| author | Linus Torvalds <torvalds@linux-foundation.org> | 2010-03-19 16:39:42 -0400 |
|---|---|---|
| committer | Linus Torvalds <torvalds@linux-foundation.org> | 2010-03-19 16:39:42 -0400 |
| commit | 2eb645e7b5662da47646f76b41b4141f2c9bf13a (patch) | |
| tree | b5b99f8111a72a81d085cc3e3acca706de43062e | |
| parent | 8fdb7e9f612b7c6ba6c3ba460c14263b5ce90f79 (diff) | |
| parent | 12ee3c0a0ac42bed0939420468fd35f5cdceae4f (diff) | |
Merge git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/driver-core-2.6
* git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/driver-core-2.6:
driver core: numa: fix BUILD_BUG_ON for node_read_distance
driver-core: document ERR_PTR() return values
kobject: documentation: Update to refer to kset-example.c.
sysdev: the cpu probe/release attributes should be sysdev_class_attributes
kobject: documentation: Fix erroneous example in kobject doc.
driver-core: fix missing kernel-doc in firmware_class
Driver core: Early platform kernel-doc update
sysfs: fix sysfs lockdep warning in mlx4 code
sysfs: fix sysfs lockdep warning in infiniband code
sysfs: fix sysfs lockdep warning in ipmi code
sysfs: Initialised pci bus legacy_mem field before use
sysfs: use sysfs_bin_attr_init in firmware class driver
| -rw-r--r-- | Documentation/kobject.txt | 60 | ||||
| -rw-r--r-- | drivers/base/class.c | 2 | ||||
| -rw-r--r-- | drivers/base/core.c | 6 | ||||
| -rw-r--r-- | drivers/base/cpu.c | 16 | ||||
| -rw-r--r-- | drivers/base/firmware_class.c | 2 | ||||
| -rw-r--r-- | drivers/base/node.c | 7 | ||||
| -rw-r--r-- | drivers/base/platform.c | 33 | ||||
| -rw-r--r-- | drivers/char/ipmi/ipmi_msghandler.c | 10 | ||||
| -rw-r--r-- | drivers/infiniband/core/sysfs.c | 1 | ||||
| -rw-r--r-- | drivers/net/mlx4/main.c | 1 | ||||
| -rw-r--r-- | drivers/pci/pci-sysfs.c | 2 |
11 files changed, 102 insertions, 38 deletions
diff --git a/Documentation/kobject.txt b/Documentation/kobject.txt index bdb13817e1e9..3ab2472509cb 100644 --- a/Documentation/kobject.txt +++ b/Documentation/kobject.txt | |||
| @@ -59,37 +59,56 @@ nice to have in other objects. The C language does not allow for the | |||
| 59 | direct expression of inheritance, so other techniques - such as structure | 59 | direct expression of inheritance, so other techniques - such as structure |
| 60 | embedding - must be used. | 60 | embedding - must be used. |
| 61 | 61 | ||
| 62 | So, for example, the UIO code has a structure that defines the memory | 62 | (As an aside, for those familiar with the kernel linked list implementation, |
| 63 | region associated with a uio device: | 63 | this is analogous as to how "list_head" structs are rarely useful on |
| 64 | their own, but are invariably found embedded in the larger objects of | ||
| 65 | interest.) | ||
| 64 | 66 | ||
| 65 | struct uio_mem { | 67 | So, for example, the UIO code in drivers/uio/uio.c has a structure that |
| 68 | defines the memory region associated with a uio device: | ||
| 69 | |||
| 70 | struct uio_map { | ||
| 66 | struct kobject kobj; | 71 | struct kobject kobj; |
| 67 | unsigned long addr; | 72 | struct uio_mem *mem; |
| 68 | unsigned long size; | 73 | }; |
| 69 | int memtype; | ||
| 70 | void __iomem *internal_addr; | ||
| 71 | }; | ||
| 72 | 74 | ||
| 73 | If you have a struct uio_mem structure, finding its embedded kobject is | 75 | If you have a struct uio_map structure, finding its embedded kobject is |
| 74 | just a matter of using the kobj member. Code that works with kobjects will | 76 | just a matter of using the kobj member. Code that works with kobjects will |
| 75 | often have the opposite problem, however: given a struct kobject pointer, | 77 | often have the opposite problem, however: given a struct kobject pointer, |
| 76 | what is the pointer to the containing structure? You must avoid tricks | 78 | what is the pointer to the containing structure? You must avoid tricks |
| 77 | (such as assuming that the kobject is at the beginning of the structure) | 79 | (such as assuming that the kobject is at the beginning of the structure) |
| 78 | and, instead, use the container_of() macro, found in <linux/kernel.h>: | 80 | and, instead, use the container_of() macro, found in <linux/kernel.h>: |
| 79 | 81 | ||
| 80 | container_of(pointer, type, member) | 82 | container_of(pointer, type, member) |
| 83 | |||
| 84 | where: | ||
| 85 | |||
| 86 | * "pointer" is the pointer to the embedded kobject, | ||
| 87 | * "type" is the type of the containing structure, and | ||
| 88 | * "member" is the name of the structure field to which "pointer" points. | ||
| 89 | |||
| 90 | The return value from container_of() is a pointer to the corresponding | ||
| 91 | container type. So, for example, a pointer "kp" to a struct kobject | ||
| 92 | embedded *within* a struct uio_map could be converted to a pointer to the | ||
| 93 | *containing* uio_map structure with: | ||
| 94 | |||
| 95 | struct uio_map *u_map = container_of(kp, struct uio_map, kobj); | ||
| 96 | |||
| 97 | For convenience, programmers often define a simple macro for "back-casting" | ||
| 98 | kobject pointers to the containing type. Exactly this happens in the | ||
| 99 | earlier drivers/uio/uio.c, as you can see here: | ||
| 100 | |||
| 101 | struct uio_map { | ||
| 102 | struct kobject kobj; | ||
| 103 | struct uio_mem *mem; | ||
| 104 | }; | ||
| 81 | 105 | ||
| 82 | where pointer is the pointer to the embedded kobject, type is the type of | 106 | #define to_map(map) container_of(map, struct uio_map, kobj) |
| 83 | the containing structure, and member is the name of the structure field to | ||
| 84 | which pointer points. The return value from container_of() is a pointer to | ||
| 85 | the given type. So, for example, a pointer "kp" to a struct kobject | ||
| 86 | embedded within a struct uio_mem could be converted to a pointer to the | ||
| 87 | containing uio_mem structure with: | ||
| 88 | 107 | ||
| 89 | struct uio_mem *u_mem = container_of(kp, struct uio_mem, kobj); | 108 | where the macro argument "map" is a pointer to the struct kobject in |
| 109 | question. That macro is subsequently invoked with: | ||
| 90 | 110 | ||
| 91 | Programmers often define a simple macro for "back-casting" kobject pointers | 111 | struct uio_map *map = to_map(kobj); |
| 92 | to the containing type. | ||
| 93 | 112 | ||
| 94 | 113 | ||
| 95 | Initialization of kobjects | 114 | Initialization of kobjects |
| @@ -387,4 +406,5 @@ called, and the objects in the former circle release each other. | |||
| 387 | Example code to copy from | 406 | Example code to copy from |
| 388 | 407 | ||
| 389 | For a more complete example of using ksets and kobjects properly, see the | 408 | For a more complete example of using ksets and kobjects properly, see the |
| 390 | sample/kobject/kset-example.c code. | 409 | example programs samples/kobject/{kobject-example.c,kset-example.c}, |
| 410 | which will be built as loadable modules if you select CONFIG_SAMPLE_KOBJECT. | ||
diff --git a/drivers/base/class.c b/drivers/base/class.c index 0147f476b8a9..9c6a0d6408e7 100644 --- a/drivers/base/class.c +++ b/drivers/base/class.c | |||
| @@ -219,6 +219,8 @@ static void class_create_release(struct class *cls) | |||
| 219 | * This is used to create a struct class pointer that can then be used | 219 | * This is used to create a struct class pointer that can then be used |
| 220 | * in calls to device_create(). | 220 | * in calls to device_create(). |
| 221 | * | 221 | * |
| 222 | * Returns &struct class pointer on success, or ERR_PTR() on error. | ||
| 223 | * | ||
| 222 | * Note, the pointer created here is to be destroyed when finished by | 224 | * Note, the pointer created here is to be destroyed when finished by |
| 223 | * making a call to class_destroy(). | 225 | * making a call to class_destroy(). |
| 224 | */ | 226 | */ |
diff --git a/drivers/base/core.c b/drivers/base/core.c index ef55df34ddd0..b56a0ba31d4a 100644 --- a/drivers/base/core.c +++ b/drivers/base/core.c | |||
| @@ -1345,6 +1345,8 @@ static void root_device_release(struct device *dev) | |||
| 1345 | * 'module' symlink which points to the @owner directory | 1345 | * 'module' symlink which points to the @owner directory |
| 1346 | * in sysfs. | 1346 | * in sysfs. |
| 1347 | * | 1347 | * |
| 1348 | * Returns &struct device pointer on success, or ERR_PTR() on error. | ||
| 1349 | * | ||
| 1348 | * Note: You probably want to use root_device_register(). | 1350 | * Note: You probably want to use root_device_register(). |
| 1349 | */ | 1351 | */ |
| 1350 | struct device *__root_device_register(const char *name, struct module *owner) | 1352 | struct device *__root_device_register(const char *name, struct module *owner) |
| @@ -1432,6 +1434,8 @@ static void device_create_release(struct device *dev) | |||
| 1432 | * Any further sysfs files that might be required can be created using this | 1434 | * Any further sysfs files that might be required can be created using this |
| 1433 | * pointer. | 1435 | * pointer. |
| 1434 | * | 1436 | * |
| 1437 | * Returns &struct device pointer on success, or ERR_PTR() on error. | ||
| 1438 | * | ||
| 1435 | * Note: the struct class passed to this function must have previously | 1439 | * Note: the struct class passed to this function must have previously |
| 1436 | * been created with a call to class_create(). | 1440 | * been created with a call to class_create(). |
| 1437 | */ | 1441 | */ |
| @@ -1492,6 +1496,8 @@ EXPORT_SYMBOL_GPL(device_create_vargs); | |||
| 1492 | * Any further sysfs files that might be required can be created using this | 1496 | * Any further sysfs files that might be required can be created using this |
| 1493 | * pointer. | 1497 | * pointer. |
| 1494 | * | 1498 | * |
| 1499 | * Returns &struct device pointer on success, or ERR_PTR() on error. | ||
| 1500 | * | ||
| 1495 | * Note: the struct class passed to this function must have previously | 1501 | * Note: the struct class passed to this function must have previously |
| 1496 | * been created with a call to class_create(). | 1502 | * been created with a call to class_create(). |
| 1497 | */ | 1503 | */ |
diff --git a/drivers/base/cpu.c b/drivers/base/cpu.c index 7036e8e96ab8..b5242e1e8bc4 100644 --- a/drivers/base/cpu.c +++ b/drivers/base/cpu.c | |||
| @@ -79,24 +79,24 @@ void unregister_cpu(struct cpu *cpu) | |||
| 79 | } | 79 | } |
| 80 | 80 | ||
| 81 | #ifdef CONFIG_ARCH_CPU_PROBE_RELEASE | 81 | #ifdef CONFIG_ARCH_CPU_PROBE_RELEASE |
| 82 | static ssize_t cpu_probe_store(struct sys_device *dev, | 82 | static ssize_t cpu_probe_store(struct sysdev_class *class, |
| 83 | struct sysdev_attribute *attr, | 83 | struct sysdev_class_attribute *attr, |
| 84 | const char *buf, | 84 | const char *buf, |
| 85 | size_t count) | 85 | size_t count) |
| 86 | { | 86 | { |
| 87 | return arch_cpu_probe(buf, count); | 87 | return arch_cpu_probe(buf, count); |
| 88 | } | 88 | } |
| 89 | 89 | ||
| 90 | static ssize_t cpu_release_store(struct sys_device *dev, | 90 | static ssize_t cpu_release_store(struct sysdev_class *class, |
| 91 | struct sysdev_attribute *attr, | 91 | struct sysdev_class_attribute *attr, |
| 92 | const char *buf, | 92 | const char *buf, |
| 93 | size_t count) | 93 | size_t count) |
| 94 | { | 94 | { |
| 95 | return arch_cpu_release(buf, count); | 95 | return arch_cpu_release(buf, count); |
| 96 | } | 96 | } |
| 97 | 97 | ||
| 98 | static SYSDEV_ATTR(probe, S_IWUSR, NULL, cpu_probe_store); | 98 | static SYSDEV_CLASS_ATTR(probe, S_IWUSR, NULL, cpu_probe_store); |
