diff options
Diffstat (limited to 'drivers/base/core.c')
-rw-r--r-- | drivers/base/core.c | 30 |
1 files changed, 24 insertions, 6 deletions
diff --git a/drivers/base/core.c b/drivers/base/core.c index b98cb1416a2d..8c2cc2648f5a 100644 --- a/drivers/base/core.c +++ b/drivers/base/core.c | |||
@@ -523,11 +523,16 @@ static void klist_children_put(struct klist_node *n) | |||
523 | * device_initialize - init device structure. | 523 | * device_initialize - init device structure. |
524 | * @dev: device. | 524 | * @dev: device. |
525 | * | 525 | * |
526 | * This prepares the device for use by other layers, | 526 | * This prepares the device for use by other layers by initializing |
527 | * including adding it to the device hierarchy. | 527 | * its fields. |
528 | * It is the first half of device_register(), if called by | 528 | * It is the first half of device_register(), if called by |
529 | * that, though it can also be called separately, so one | 529 | * that function, though it can also be called separately, so one |
530 | * may use @dev's fields (e.g. the refcount). | 530 | * may use @dev's fields. In particular, get_device()/put_device() |
531 | * may be used for reference counting of @dev after calling this | ||
532 | * function. | ||
533 | * | ||
534 | * NOTE: Use put_device() to give up your reference instead of freeing | ||
535 | * @dev directly once you have called this function. | ||
531 | */ | 536 | */ |
532 | void device_initialize(struct device *dev) | 537 | void device_initialize(struct device *dev) |
533 | { | 538 | { |
@@ -835,9 +840,13 @@ static void device_remove_sys_dev_entry(struct device *dev) | |||
835 | * This is part 2 of device_register(), though may be called | 840 | * This is part 2 of device_register(), though may be called |
836 | * separately _iff_ device_initialize() has been called separately. | 841 | * separately _iff_ device_initialize() has been called separately. |
837 | * | 842 | * |
838 | * This adds it to the kobject hierarchy via kobject_add(), adds it | 843 | * This adds @dev to the kobject hierarchy via kobject_add(), adds it |
839 | * to the global and sibling lists for the device, then | 844 | * to the global and sibling lists for the device, then |
840 | * adds it to the other relevant subsystems of the driver model. | 845 | * adds it to the other relevant subsystems of the driver model. |
846 | * | ||
847 | * NOTE: _Never_ directly free @dev after calling this function, even | ||
848 | * if it returned an error! Always use put_device() to give up your | ||
849 | * reference instead. | ||
841 | */ | 850 | */ |
842 | int device_add(struct device *dev) | 851 | int device_add(struct device *dev) |
843 | { | 852 | { |
@@ -965,6 +974,10 @@ done: | |||
965 | * I.e. you should only call the two helpers separately if | 974 | * I.e. you should only call the two helpers separately if |
966 | * have a clearly defined need to use and refcount the device | 975 | * have a clearly defined need to use and refcount the device |
967 | * before it is added to the hierarchy. | 976 | * before it is added to the hierarchy. |
977 | * | ||
978 | * NOTE: _Never_ directly free @dev after calling this function, even | ||
979 | * if it returned an error! Always use put_device() to give up the | ||
980 | * reference initialized in this function instead. | ||
968 | */ | 981 | */ |
969 | int device_register(struct device *dev) | 982 | int device_register(struct device *dev) |
970 | { | 983 | { |
@@ -1243,7 +1256,7 @@ struct device *device_create_vargs(struct class *class, struct device *parent, | |||
1243 | return dev; | 1256 | return dev; |
1244 | 1257 | ||
1245 | error: | 1258 | error: |
1246 | kfree(dev); | 1259 | put_device(dev); |
1247 | return ERR_PTR(retval); | 1260 | return ERR_PTR(retval); |
1248 | } | 1261 | } |
1249 | EXPORT_SYMBOL_GPL(device_create_vargs); | 1262 | EXPORT_SYMBOL_GPL(device_create_vargs); |
@@ -1314,6 +1327,11 @@ EXPORT_SYMBOL_GPL(device_destroy); | |||
1314 | * device_rename - renames a device | 1327 | * device_rename - renames a device |
1315 | * @dev: the pointer to the struct device to be renamed | 1328 | * @dev: the pointer to the struct device to be renamed |
1316 | * @new_name: the new name of the device | 1329 | * @new_name: the new name of the device |
1330 | * | ||
1331 | * It is the responsibility of the caller to provide mutual | ||
1332 | * exclusion between two different calls of device_rename | ||
1333 | * on the same device to ensure that new_name is valid and | ||
1334 | * won't conflict with other devices. | ||
1317 | */ | 1335 | */ |
1318 | int device_rename(struct device *dev, char *new_name) | 1336 | int device_rename(struct device *dev, char *new_name) |
1319 | { | 1337 | { |