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

+102 -38
+40 -20
Documentation/kobject.txt
··· 59 direct expression of inheritance, so other techniques - such as structure 60 embedding - must be used. 61 62 - So, for example, the UIO code has a structure that defines the memory 63 - region associated with a uio device: 64 65 - struct uio_mem { 66 struct kobject kobj; 67 - unsigned long addr; 68 - unsigned long size; 69 - int memtype; 70 - void __iomem *internal_addr; 71 - }; 72 73 - If you have a struct uio_mem structure, finding its embedded kobject is 74 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, 76 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) 78 and, instead, use the container_of() macro, found in <linux/kernel.h>: 79 80 - container_of(pointer, type, member) 81 82 - where pointer is the pointer to the embedded kobject, type is the type of 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 89 - struct uio_mem *u_mem = container_of(kp, struct uio_mem, kobj); 90 91 - Programmers often define a simple macro for "back-casting" kobject pointers 92 - to the containing type. 93 94 95 Initialization of kobjects ··· 406 Example code to copy from 407 408 For a more complete example of using ksets and kobjects properly, see the 409 - sample/kobject/kset-example.c code.
··· 59 direct expression of inheritance, so other techniques - such as structure 60 embedding - must be used. 61 62 + (As an aside, for those familiar with the kernel linked list implementation, 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.) 66 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 { 71 struct kobject kobj; 72 + struct uio_mem *mem; 73 + }; 74 75 + If you have a struct uio_map structure, finding its embedded kobject is 76 just a matter of using the kobj member. Code that works with kobjects will 77 often have the opposite problem, however: given a struct kobject pointer, 78 what is the pointer to the containing structure? You must avoid tricks 79 (such as assuming that the kobject is at the beginning of the structure) 80 and, instead, use the container_of() macro, found in <linux/kernel.h>: 81 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 + }; 105 + 106 + #define to_map(map) container_of(map, struct uio_map, kobj) 107 + 108 + where the macro argument "map" is a pointer to the struct kobject in 109 + question. That macro is subsequently invoked with: 110 + 111 + struct uio_map *map = to_map(kobj); 112 113 114 Initialization of kobjects ··· 387 Example code to copy from 388 389 For a more complete example of using ksets and kobjects properly, see the 390 + example programs samples/kobject/{kobject-example.c,kset-example.c}, 391 + which will be built as loadable modules if you select CONFIG_SAMPLE_KOBJECT.
+2
drivers/base/class.c
··· 219 * This is used to create a struct class pointer that can then be used 220 * in calls to device_create(). 221 * 222 * Note, the pointer created here is to be destroyed when finished by 223 * making a call to class_destroy(). 224 */
··· 219 * This is used to create a struct class pointer that can then be used 220 * in calls to device_create(). 221 * 222 + * Returns &struct class pointer on success, or ERR_PTR() on error. 223 + * 224 * Note, the pointer created here is to be destroyed when finished by 225 * making a call to class_destroy(). 226 */
+6
drivers/base/core.c
··· 1345 * 'module' symlink which points to the @owner directory 1346 * in sysfs. 1347 * 1348 * Note: You probably want to use root_device_register(). 1349 */ 1350 struct device *__root_device_register(const char *name, struct module *owner) ··· 1434 * Any further sysfs files that might be required can be created using this 1435 * pointer. 1436 * 1437 * Note: the struct class passed to this function must have previously 1438 * been created with a call to class_create(). 1439 */ ··· 1495 * The pointer to the struct device will be returned from the call. 1496 * Any further sysfs files that might be required can be created using this 1497 * pointer. 1498 * 1499 * Note: the struct class passed to this function must have previously 1500 * been created with a call to class_create().
··· 1345 * 'module' symlink which points to the @owner directory 1346 * in sysfs. 1347 * 1348 + * Returns &struct device pointer on success, or ERR_PTR() on error. 1349 + * 1350 * Note: You probably want to use root_device_register(). 1351 */ 1352 struct device *__root_device_register(const char *name, struct module *owner) ··· 1432 * Any further sysfs files that might be required can be created using this 1433 * pointer. 1434 * 1435 + * Returns &struct device pointer on success, or ERR_PTR() on error. 1436 + * 1437 * Note: the struct class passed to this function must have previously 1438 * been created with a call to class_create(). 1439 */ ··· 1491 * The pointer to the struct device will be returned from the call. 1492 * Any further sysfs files that might be required can be created using this 1493 * pointer. 1494 + * 1495 + * Returns &struct device pointer on success, or ERR_PTR() on error. 1496 * 1497 * Note: the struct class passed to this function must have previously 1498 * been created with a call to class_create().
+8 -8
drivers/base/cpu.c
··· 79 } 80 81 #ifdef CONFIG_ARCH_CPU_PROBE_RELEASE 82 - static ssize_t cpu_probe_store(struct sys_device *dev, 83 - struct sysdev_attribute *attr, 84 - const char *buf, 85 size_t count) 86 { 87 return arch_cpu_probe(buf, count); 88 } 89 90 - static ssize_t cpu_release_store(struct sys_device *dev, 91 - struct sysdev_attribute *attr, 92 - const char *buf, 93 size_t count) 94 { 95 return arch_cpu_release(buf, count); 96 } 97 98 - static SYSDEV_ATTR(probe, S_IWUSR, NULL, cpu_probe_store); 99 - static SYSDEV_ATTR(release, S_IWUSR, NULL, cpu_release_store); 100 #endif /* CONFIG_ARCH_CPU_PROBE_RELEASE */ 101 102 #else /* ... !CONFIG_HOTPLUG_CPU */
··· 79 } 80 81 #ifdef CONFIG_ARCH_CPU_PROBE_RELEASE 82 + static ssize_t cpu_probe_store(struct sysdev_class *class, 83 + struct sysdev_class_attribute *attr, 84 + const char *buf, 85 size_t count) 86 { 87 return arch_cpu_probe(buf, count); 88 } 89 90 + static ssize_t cpu_release_store(struct sysdev_class *class, 91 + struct sysdev_class_attribute *attr, 92 + const char *buf, 93 size_t count) 94 { 95 return arch_cpu_release(buf, count); 96 } 97 98 + static SYSDEV_CLASS_ATTR(probe, S_IWUSR, NULL, cpu_probe_store); 99 + static SYSDEV_CLASS_ATTR(release, S_IWUSR, NULL, cpu_release_store); 100 #endif /* CONFIG_ARCH_CPU_PROBE_RELEASE */ 101 102 #else /* ... !CONFIG_HOTPLUG_CPU */
+2
drivers/base/firmware_class.c
··· 78 /** 79 * firmware_timeout_store - set number of seconds to wait for firmware 80 * @class: device class pointer 81 * @buf: buffer to scan for timeout value 82 * @count: number of bytes in @buf 83 * ··· 443 fw_priv = dev_get_drvdata(f_dev); 444 445 fw_priv->fw = fw; 446 retval = sysfs_create_bin_file(&f_dev->kobj, &fw_priv->attr_data); 447 if (retval) { 448 dev_err(device, "%s: sysfs_create_bin_file failed\n", __func__);
··· 78 /** 79 * firmware_timeout_store - set number of seconds to wait for firmware 80 * @class: device class pointer 81 + * @attr: device attribute pointer 82 * @buf: buffer to scan for timeout value 83 * @count: number of bytes in @buf 84 * ··· 442 fw_priv = dev_get_drvdata(f_dev); 443 444 fw_priv->fw = fw; 445 + sysfs_bin_attr_init(&fw_priv->attr_data); 446 retval = sysfs_create_bin_file(&f_dev->kobj, &fw_priv->attr_data); 447 if (retval) { 448 dev_err(device, "%s: sysfs_create_bin_file failed\n", __func__);
+5 -2
drivers/base/node.c
··· 165 int len = 0; 166 int i; 167 168 - /* buf currently PAGE_SIZE, need ~4 chars per node */ 169 - BUILD_BUG_ON(MAX_NUMNODES*4 > PAGE_SIZE/2); 170 171 for_each_online_node(i) 172 len += sprintf(buf + len, "%s%d", i ? " " : "", node_distance(nid, i));
··· 165 int len = 0; 166 int i; 167 168 + /* 169 + * buf is currently PAGE_SIZE in length and each node needs 4 chars 170 + * at the most (distance + space or newline). 171 + */ 172 + BUILD_BUG_ON(MAX_NUMNODES * 4 > PAGE_SIZE); 173 174 for_each_online_node(i) 175 len += sprintf(buf + len, "%s%d", i ? " " : "", node_distance(nid, i));
+26 -7
drivers/base/platform.c
··· 362 * enumeration tasks, they don't fully conform to the Linux driver model. 363 * In particular, when such drivers are built as modules, they can't be 364 * "hotplugged". 365 */ 366 struct platform_device *platform_device_register_simple(const char *name, 367 int id, ··· 410 * allocated for the device allows drivers using such devices to be 411 * unloaded without waiting for the last reference to the device to be 412 * dropped. 413 */ 414 struct platform_device *platform_device_register_data( 415 struct device *parent, ··· 563 * 564 * Use this in legacy-style modules that probe hardware directly and 565 * register a single platform device and corresponding platform driver. 566 */ 567 struct platform_device * __init_or_module platform_create_bundle( 568 struct platform_driver *driver, ··· 1058 static __initdata LIST_HEAD(early_platform_device_list); 1059 1060 /** 1061 - * early_platform_driver_register 1062 * @epdrv: early_platform driver structure 1063 * @buf: string passed from early_param() 1064 */ 1065 int __init early_platform_driver_register(struct early_platform_driver *epdrv, 1066 char *buf) ··· 1114 } 1115 1116 /** 1117 - * early_platform_add_devices - add a numbers of early platform devices 1118 * @devs: array of early platform devices to add 1119 * @num: number of early platform devices in array 1120 */ 1121 void __init early_platform_add_devices(struct platform_device **devs, int num) 1122 { ··· 1139 } 1140 1141 /** 1142 - * early_platform_driver_register_all 1143 * @class_str: string to identify early platform driver class 1144 */ 1145 void __init early_platform_driver_register_all(char *class_str) 1146 { ··· 1166 } 1167 1168 /** 1169 - * early_platform_match 1170 * @epdrv: early platform driver structure 1171 * @id: id to match against 1172 */ ··· 1184 } 1185 1186 /** 1187 - * early_platform_left 1188 * @epdrv: early platform driver structure 1189 * @id: return true if id or above exists 1190 */ ··· 1202 } 1203 1204 /** 1205 - * early_platform_driver_probe_id 1206 * @class_str: string to identify early platform driver class 1207 * @id: id to match against 1208 * @nr_probe: number of platform devices to successfully probe before exiting ··· 1272 } 1273 1274 /** 1275 - * early_platform_driver_probe 1276 * @class_str: string to identify early platform driver class 1277 * @nr_probe: number of platform devices to successfully probe before exiting 1278 * @user_only: only probe user specified early platform devices 1279 */ 1280 int __init early_platform_driver_probe(char *class_str, 1281 int nr_probe,
··· 362 * enumeration tasks, they don't fully conform to the Linux driver model. 363 * In particular, when such drivers are built as modules, they can't be 364 * "hotplugged". 365 + * 366 + * Returns &struct platform_device pointer on success, or ERR_PTR() on error. 367 */ 368 struct platform_device *platform_device_register_simple(const char *name, 369 int id, ··· 408 * allocated for the device allows drivers using such devices to be 409 * unloaded without waiting for the last reference to the device to be 410 * dropped. 411 + * 412 + * Returns &struct platform_device pointer on success, or ERR_PTR() on error. 413 */ 414 struct platform_device *platform_device_register_data( 415 struct device *parent, ··· 559 * 560 * Use this in legacy-style modules that probe hardware directly and 561 * register a single platform device and corresponding platform driver. 562 + * 563 + * Returns &struct platform_device pointer on success, or ERR_PTR() on error. 564 */ 565 struct platform_device * __init_or_module platform_create_bundle( 566 struct platform_driver *driver, ··· 1052 static __initdata LIST_HEAD(early_platform_device_list); 1053 1054 /** 1055 + * early_platform_driver_register - register early platform driver 1056 * @epdrv: early_platform driver structure 1057 * @buf: string passed from early_param() 1058 + * 1059 + * Helper function for early_platform_init() / early_platform_init_buffer() 1060 */ 1061 int __init early_platform_driver_register(struct early_platform_driver *epdrv, 1062 char *buf) ··· 1106 } 1107 1108 /** 1109 + * early_platform_add_devices - adds a number of early platform devices 1110 * @devs: array of early platform devices to add 1111 * @num: number of early platform devices in array 1112 + * 1113 + * Used by early architecture code to register early platform devices and 1114 + * their platform data. 1115 */ 1116 void __init early_platform_add_devices(struct platform_device **devs, int num) 1117 { ··· 1128 } 1129 1130 /** 1131 + * early_platform_driver_register_all - register early platform drivers 1132 * @class_str: string to identify early platform driver class 1133 + * 1134 + * Used by architecture code to register all early platform drivers 1135 + * for a certain class. If omitted then only early platform drivers 1136 + * with matching kernel command line class parameters will be registered. 1137 */ 1138 void __init early_platform_driver_register_all(char *class_str) 1139 { ··· 1151 } 1152 1153 /** 1154 + * early_platform_match - find early platform device matching driver 1155 * @epdrv: early platform driver structure 1156 * @id: id to match against 1157 */ ··· 1169 } 1170 1171 /** 1172 + * early_platform_left - check if early platform driver has matching devices 1173 * @epdrv: early platform driver structure 1174 * @id: return true if id or above exists 1175 */ ··· 1187 } 1188 1189 /** 1190 + * early_platform_driver_probe_id - probe drivers matching class_str and id 1191 * @class_str: string to identify early platform driver class 1192 * @id: id to match against 1193 * @nr_probe: number of platform devices to successfully probe before exiting ··· 1257 } 1258 1259 /** 1260 + * early_platform_driver_probe - probe a class of registered drivers 1261 * @class_str: string to identify early platform driver class 1262 * @nr_probe: number of platform devices to successfully probe before exiting 1263 * @user_only: only probe user specified early platform devices 1264 + * 1265 + * Used by architecture code to probe registered early platform drivers 1266 + * within a certain class. For probe to happen a registered early platform 1267 + * device matching a registered early platform driver is needed. 1268 */ 1269 int __init early_platform_driver_probe(char *class_str, 1270 int nr_probe,
+10
drivers/char/ipmi/ipmi_msghandler.c
··· 2272 bmc->device_id_attr.attr.name = "device_id"; 2273 bmc->device_id_attr.attr.mode = S_IRUGO; 2274 bmc->device_id_attr.show = device_id_show; 2275 2276 bmc->provides_dev_sdrs_attr.attr.name = "provides_device_sdrs"; 2277 bmc->provides_dev_sdrs_attr.attr.mode = S_IRUGO; 2278 bmc->provides_dev_sdrs_attr.show = provides_dev_sdrs_show; 2279 2280 bmc->revision_attr.attr.name = "revision"; 2281 bmc->revision_attr.attr.mode = S_IRUGO; 2282 bmc->revision_attr.show = revision_show; 2283 2284 bmc->firmware_rev_attr.attr.name = "firmware_revision"; 2285 bmc->firmware_rev_attr.attr.mode = S_IRUGO; 2286 bmc->firmware_rev_attr.show = firmware_rev_show; 2287 2288 bmc->version_attr.attr.name = "ipmi_version"; 2289 bmc->version_attr.attr.mode = S_IRUGO; 2290 bmc->version_attr.show = ipmi_version_show; 2291 2292 bmc->add_dev_support_attr.attr.name = "additional_device_support"; 2293 bmc->add_dev_support_attr.attr.mode = S_IRUGO; 2294 bmc->add_dev_support_attr.show = add_dev_support_show; 2295 2296 bmc->manufacturer_id_attr.attr.name = "manufacturer_id"; 2297 bmc->manufacturer_id_attr.attr.mode = S_IRUGO; 2298 bmc->manufacturer_id_attr.show = manufacturer_id_show; 2299 2300 bmc->product_id_attr.attr.name = "product_id"; 2301 bmc->product_id_attr.attr.mode = S_IRUGO; 2302 bmc->product_id_attr.show = product_id_show; 2303 2304 bmc->guid_attr.attr.name = "guid"; 2305 bmc->guid_attr.attr.mode = S_IRUGO; 2306 bmc->guid_attr.show = guid_show; 2307 2308 bmc->aux_firmware_rev_attr.attr.name = "aux_firmware_revision"; 2309 bmc->aux_firmware_rev_attr.attr.mode = S_IRUGO; 2310 bmc->aux_firmware_rev_attr.show = aux_firmware_rev_show; 2311 2312 err = device_create_file(&bmc->dev->dev, 2313 &bmc->device_id_attr);
··· 2272 bmc->device_id_attr.attr.name = "device_id"; 2273 bmc->device_id_attr.attr.mode = S_IRUGO; 2274 bmc->device_id_attr.show = device_id_show; 2275 + sysfs_attr_init(&bmc->device_id_attr.attr); 2276 2277 bmc->provides_dev_sdrs_attr.attr.name = "provides_device_sdrs"; 2278 bmc->provides_dev_sdrs_attr.attr.mode = S_IRUGO; 2279 bmc->provides_dev_sdrs_attr.show = provides_dev_sdrs_show; 2280 + sysfs_attr_init(&bmc->provides_dev_sdrs_attr.attr); 2281 2282 bmc->revision_attr.attr.name = "revision"; 2283 bmc->revision_attr.attr.mode = S_IRUGO; 2284 bmc->revision_attr.show = revision_show; 2285 + sysfs_attr_init(&bmc->revision_attr.attr); 2286 2287 bmc->firmware_rev_attr.attr.name = "firmware_revision"; 2288 bmc->firmware_rev_attr.attr.mode = S_IRUGO; 2289 bmc->firmware_rev_attr.show = firmware_rev_show; 2290 + sysfs_attr_init(&bmc->firmware_rev_attr.attr); 2291 2292 bmc->version_attr.attr.name = "ipmi_version"; 2293 bmc->version_attr.attr.mode = S_IRUGO; 2294 bmc->version_attr.show = ipmi_version_show; 2295 + sysfs_attr_init(&bmc->version_attr.attr); 2296 2297 bmc->add_dev_support_attr.attr.name = "additional_device_support"; 2298 bmc->add_dev_support_attr.attr.mode = S_IRUGO; 2299 bmc->add_dev_support_attr.show = add_dev_support_show; 2300 + sysfs_attr_init(&bmc->add_dev_support_attr.attr); 2301 2302 bmc->manufacturer_id_attr.attr.name = "manufacturer_id"; 2303 bmc->manufacturer_id_attr.attr.mode = S_IRUGO; 2304 bmc->manufacturer_id_attr.show = manufacturer_id_show; 2305 + sysfs_attr_init(&bmc->manufacturer_id_attr.attr); 2306 2307 bmc->product_id_attr.attr.name = "product_id"; 2308 bmc->product_id_attr.attr.mode = S_IRUGO; 2309 bmc->product_id_attr.show = product_id_show; 2310 + sysfs_attr_init(&bmc->product_id_attr.attr); 2311 2312 bmc->guid_attr.attr.name = "guid"; 2313 bmc->guid_attr.attr.mode = S_IRUGO; 2314 bmc->guid_attr.show = guid_show; 2315 + sysfs_attr_init(&bmc->guid_attr.attr); 2316 2317 bmc->aux_firmware_rev_attr.attr.name = "aux_firmware_revision"; 2318 bmc->aux_firmware_rev_attr.attr.mode = S_IRUGO; 2319 bmc->aux_firmware_rev_attr.show = aux_firmware_rev_show; 2320 + sysfs_attr_init(&bmc->aux_firmware_rev_attr.attr); 2321 2322 err = device_create_file(&bmc->dev->dev, 2323 &bmc->device_id_attr);
+1
drivers/infiniband/core/sysfs.c
··· 461 element->attr.attr.mode = S_IRUGO; 462 element->attr.show = show; 463 element->index = i; 464 465 tab_attr[i] = &element->attr.attr; 466 }
··· 461 element->attr.attr.mode = S_IRUGO; 462 element->attr.show = show; 463 element->index = i; 464 + sysfs_attr_init(&element->attr.attr); 465 466 tab_attr[i] = &element->attr.attr; 467 }
+1
drivers/net/mlx4/main.c
··· 1023 info->port_attr.attr.mode = S_IRUGO | S_IWUSR; 1024 info->port_attr.show = show_port_type; 1025 info->port_attr.store = set_port_type; 1026 1027 err = device_create_file(&dev->pdev->dev, &info->port_attr); 1028 if (err) {
··· 1023 info->port_attr.attr.mode = S_IRUGO | S_IWUSR; 1024 info->port_attr.show = show_port_type; 1025 info->port_attr.store = set_port_type; 1026 + sysfs_attr_init(&info->port_attr.attr); 1027 1028 err = device_create_file(&dev->pdev->dev, &info->port_attr); 1029 if (err) {
+1 -1
drivers/pci/pci-sysfs.c
··· 655 goto legacy_io_err; 656 657 /* Allocated above after the legacy_io struct */ 658 - sysfs_bin_attr_init(b->legacy_mem); 659 b->legacy_mem = b->legacy_io + 1; 660 b->legacy_mem->attr.name = "legacy_mem"; 661 b->legacy_mem->size = 1024*1024; 662 b->legacy_mem->attr.mode = S_IRUSR | S_IWUSR;
··· 655 goto legacy_io_err; 656 657 /* Allocated above after the legacy_io struct */ 658 b->legacy_mem = b->legacy_io + 1; 659 + sysfs_bin_attr_init(b->legacy_mem); 660 b->legacy_mem->attr.name = "legacy_mem"; 661 b->legacy_mem->size = 1024*1024; 662 b->legacy_mem->attr.mode = S_IRUSR | S_IWUSR;