2 * drivers/base/core.c - core driver model code (device registration, etc)
4 * Copyright (c) 2002-3 Patrick Mochel
5 * Copyright (c) 2002-3 Open Source Development Labs
6 * Copyright (c) 2006 Greg Kroah-Hartman <gregkh@suse.de>
7 * Copyright (c) 2006 Novell, Inc.
9 * This file is released under the GPLv2
13 #include <linux/device.h>
14 #include <linux/err.h>
15 #include <linux/init.h>
16 #include <linux/module.h>
17 #include <linux/slab.h>
18 #include <linux/string.h>
19 #include <linux/kdev_t.h>
20 #include <linux/notifier.h>
22 #include <asm/semaphore.h>
25 #include "power/power.h"
27 int (*platform_notify)(struct device * dev) = NULL;
28 int (*platform_notify_remove)(struct device * dev) = NULL;
31 * sysfs bindings for devices.
35 * dev_driver_string - Return a device's driver name, if at all possible
36 * @dev: struct device to get the name of
38 * Will return the device's driver's name if it is bound to a device. If
39 * the device is not bound to a device, it will return the name of the bus
40 * it is attached to. If it is not attached to a bus either, an empty
41 * string will be returned.
43 const char *dev_driver_string(struct device *dev)
45 return dev->driver ? dev->driver->name :
46 (dev->bus ? dev->bus->name : "");
48 EXPORT_SYMBOL(dev_driver_string);
50 #define to_dev(obj) container_of(obj, struct device, kobj)
51 #define to_dev_attr(_attr) container_of(_attr, struct device_attribute, attr)
54 dev_attr_show(struct kobject * kobj, struct attribute * attr, char * buf)
56 struct device_attribute * dev_attr = to_dev_attr(attr);
57 struct device * dev = to_dev(kobj);
61 ret = dev_attr->show(dev, dev_attr, buf);
66 dev_attr_store(struct kobject * kobj, struct attribute * attr,
67 const char * buf, size_t count)
69 struct device_attribute * dev_attr = to_dev_attr(attr);
70 struct device * dev = to_dev(kobj);
74 ret = dev_attr->store(dev, dev_attr, buf, count);
78 static struct sysfs_ops dev_sysfs_ops = {
79 .show = dev_attr_show,
80 .store = dev_attr_store,
85 * device_release - free device structure.
86 * @kobj: device's kobject.
88 * This is called once the reference count for the object
89 * reaches 0. We forward the call to the device's release
90 * method, which should handle actually freeing the structure.
92 static void device_release(struct kobject * kobj)
94 struct device * dev = to_dev(kobj);
98 else if (dev->class && dev->class->dev_release)
99 dev->class->dev_release(dev);
101 printk(KERN_ERR "Device '%s' does not have a release() function, "
102 "it is broken and must be fixed.\n",
108 static struct kobj_type ktype_device = {
109 .release = device_release,
110 .sysfs_ops = &dev_sysfs_ops,
114 static int dev_uevent_filter(struct kset *kset, struct kobject *kobj)
116 struct kobj_type *ktype = get_ktype(kobj);
118 if (ktype == &ktype_device) {
119 struct device *dev = to_dev(kobj);
128 static const char *dev_uevent_name(struct kset *kset, struct kobject *kobj)
130 struct device *dev = to_dev(kobj);
133 return dev->bus->name;
135 return dev->class->name;
139 static int dev_uevent(struct kset *kset, struct kobject *kobj, char **envp,
140 int num_envp, char *buffer, int buffer_size)
142 struct device *dev = to_dev(kobj);
147 /* add the major/minor if present */
148 if (MAJOR(dev->devt)) {
149 add_uevent_var(envp, num_envp, &i,
150 buffer, buffer_size, &length,
151 "MAJOR=%u", MAJOR(dev->devt));
152 add_uevent_var(envp, num_envp, &i,
153 buffer, buffer_size, &length,
154 "MINOR=%u", MINOR(dev->devt));
157 #ifdef CONFIG_SYSFS_DEPRECATED
158 /* add bus name (same as SUBSYSTEM, deprecated) */
160 add_uevent_var(envp, num_envp, &i,
161 buffer, buffer_size, &length,
162 "PHYSDEVBUS=%s", dev->bus->name);
165 /* add driver name (PHYSDEV* values are deprecated)*/
167 add_uevent_var(envp, num_envp, &i,
168 buffer, buffer_size, &length,
169 "DRIVER=%s", dev->driver->name);
170 #ifdef CONFIG_SYSFS_DEPRECATED
171 add_uevent_var(envp, num_envp, &i,
172 buffer, buffer_size, &length,
173 "PHYSDEVDRIVER=%s", dev->driver->name);
177 /* terminate, set to next free slot, shrink available space */
181 buffer = &buffer[length];
182 buffer_size -= length;
184 if (dev->bus && dev->bus->uevent) {
185 /* have the bus specific function add its stuff */
186 retval = dev->bus->uevent(dev, envp, num_envp, buffer, buffer_size);
188 pr_debug ("%s - uevent() returned %d\n",
189 __FUNCTION__, retval);
193 if (dev->class && dev->class->dev_uevent) {
194 /* have the class specific function add its stuff */
195 retval = dev->class->dev_uevent(dev, envp, num_envp, buffer, buffer_size);
197 pr_debug("%s - dev_uevent() returned %d\n",
198 __FUNCTION__, retval);
205 static struct kset_uevent_ops device_uevent_ops = {
206 .filter = dev_uevent_filter,
207 .name = dev_uevent_name,
208 .uevent = dev_uevent,
211 static ssize_t store_uevent(struct device *dev, struct device_attribute *attr,
212 const char *buf, size_t count)
214 kobject_uevent(&dev->kobj, KOBJ_ADD);
218 static int device_add_groups(struct device *dev)
224 for (i = 0; dev->groups[i]; i++) {
225 error = sysfs_create_group(&dev->kobj, dev->groups[i]);
228 sysfs_remove_group(&dev->kobj, dev->groups[i]);
237 static void device_remove_groups(struct device *dev)
241 for (i = 0; dev->groups[i]; i++) {
242 sysfs_remove_group(&dev->kobj, dev->groups[i]);
247 static int device_add_attrs(struct device *dev)
249 struct class *class = dev->class;
256 if (class->dev_attrs) {
257 for (i = 0; attr_name(class->dev_attrs[i]); i++) {
258 error = device_create_file(dev, &class->dev_attrs[i]);
265 device_remove_file(dev, &class->dev_attrs[i]);
269 static void device_remove_attrs(struct device *dev)
271 struct class *class = dev->class;
277 if (class->dev_attrs) {
278 for (i = 0; attr_name(class->dev_attrs[i]); i++)
279 device_remove_file(dev, &class->dev_attrs[i]);
284 static ssize_t show_dev(struct device *dev, struct device_attribute *attr,
287 return print_dev_t(buf, dev->devt);
291 * devices_subsys - structure to be registered with kobject core.
294 decl_subsys(devices, &ktype_device, &device_uevent_ops);
298 * device_create_file - create sysfs attribute file for device.
300 * @attr: device attribute descriptor.
303 int device_create_file(struct device * dev, struct device_attribute * attr)
306 if (get_device(dev)) {
307 error = sysfs_create_file(&dev->kobj, &attr->attr);
314 * device_remove_file - remove sysfs attribute file.
316 * @attr: device attribute descriptor.
319 void device_remove_file(struct device * dev, struct device_attribute * attr)
321 if (get_device(dev)) {
322 sysfs_remove_file(&dev->kobj, &attr->attr);
328 * device_create_bin_file - create sysfs binary attribute file for device.
330 * @attr: device binary attribute descriptor.
332 int device_create_bin_file(struct device *dev, struct bin_attribute *attr)
336 error = sysfs_create_bin_file(&dev->kobj, attr);
339 EXPORT_SYMBOL_GPL(device_create_bin_file);
342 * device_remove_bin_file - remove sysfs binary attribute file
344 * @attr: device binary attribute descriptor.
346 void device_remove_bin_file(struct device *dev, struct bin_attribute *attr)
349 sysfs_remove_bin_file(&dev->kobj, attr);
351 EXPORT_SYMBOL_GPL(device_remove_bin_file);
353 static void klist_children_get(struct klist_node *n)
355 struct device *dev = container_of(n, struct device, knode_parent);
360 static void klist_children_put(struct klist_node *n)
362 struct device *dev = container_of(n, struct device, knode_parent);
369 * device_initialize - init device structure.
372 * This prepares the device for use by other layers,
373 * including adding it to the device hierarchy.
374 * It is the first half of device_register(), if called by
375 * that, though it can also be called separately, so one
376 * may use @dev's fields (e.g. the refcount).
379 void device_initialize(struct device *dev)
381 kobj_set_kset_s(dev, devices_subsys);
382 kobject_init(&dev->kobj);
383 klist_init(&dev->klist_children, klist_children_get,
385 INIT_LIST_HEAD(&dev->dma_pools);
386 INIT_LIST_HEAD(&dev->node);
387 init_MUTEX(&dev->sem);
388 device_init_wakeup(dev, 0);
389 set_dev_node(dev, -1);
392 #ifdef CONFIG_SYSFS_DEPRECATED
393 static struct kobject * get_device_parent(struct device *dev,
394 struct device *parent)
396 /* Set the parent to the class, not the parent device */
397 /* this keeps sysfs from having a symlink to make old udevs happy */
399 return &dev->class->subsys.kset.kobj;
401 return &parent->kobj;
406 static struct kobject * virtual_device_parent(struct device *dev)
409 return ERR_PTR(-ENODEV);
411 if (!dev->class->virtual_dir) {
412 static struct kobject *virtual_dir = NULL;
415 virtual_dir = kobject_add_dir(&devices_subsys.kset.kobj, "virtual");
416 dev->class->virtual_dir = kobject_add_dir(virtual_dir, dev->class->name);
419 return dev->class->virtual_dir;
422 static struct kobject * get_device_parent(struct device *dev,
423 struct device *parent)
425 /* if this is a class device, and has no parent, create one */
426 if ((dev->class) && (parent == NULL)) {
427 return virtual_device_parent(dev);
429 return &parent->kobj;
434 static int setup_parent(struct device *dev, struct device *parent)
436 struct kobject *kobj;
437 kobj = get_device_parent(dev, parent);
439 return PTR_ERR(kobj);
441 dev->kobj.parent = kobj;
446 * device_add - add device to device hierarchy.
449 * This is part 2 of device_register(), though may be called
450 * separately _iff_ device_initialize() has been called separately.
452 * This adds it to the kobject hierarchy via kobject_add(), adds it
453 * to the global and sibling lists for the device, then
454 * adds it to the other relevant subsystems of the driver model.
456 int device_add(struct device *dev)
458 struct device *parent = NULL;
459 char *class_name = NULL;
460 struct class_interface *class_intf;
463 dev = get_device(dev);
464 if (!dev || !strlen(dev->bus_id))
467 pr_debug("DEV: registering device: ID = '%s'\n", dev->bus_id);
469 parent = get_device(dev->parent);
471 error = setup_parent(dev, parent);
475 /* first, register with generic layer. */
476 kobject_set_name(&dev->kobj, "%s", dev->bus_id);
477 error = kobject_add(&dev->kobj);
481 /* notify platform of device entry */
483 platform_notify(dev);
485 /* notify clients of device entry (new way) */
487 blocking_notifier_call_chain(&dev->bus->bus_notifier,
488 BUS_NOTIFY_ADD_DEVICE, dev);
490 dev->uevent_attr.attr.name = "uevent";
491 dev->uevent_attr.attr.mode = S_IWUSR;
493 dev->uevent_attr.attr.owner = dev->driver->owner;
494 dev->uevent_attr.store = store_uevent;
495 error = device_create_file(dev, &dev->uevent_attr);
499 if (MAJOR(dev->devt)) {
500 struct device_attribute *attr;
501 attr = kzalloc(sizeof(*attr), GFP_KERNEL);
504 goto ueventattrError;
506 attr->attr.name = "dev";
507 attr->attr.mode = S_IRUGO;
509 attr->attr.owner = dev->driver->owner;
510 attr->show = show_dev;
511 error = device_create_file(dev, attr);
514 goto ueventattrError;
517 dev->devt_attr = attr;
521 sysfs_create_link(&dev->kobj, &dev->class->subsys.kset.kobj,
523 /* If this is not a "fake" compatible device, then create the
524 * symlink from the class to the device. */
525 if (dev->kobj.parent != &dev->class->subsys.kset.kobj)
526 sysfs_create_link(&dev->class->subsys.kset.kobj,
527 &dev->kobj, dev->bus_id);
528 #ifdef CONFIG_SYSFS_DEPRECATED
530 sysfs_create_link(&dev->kobj, &dev->parent->kobj,
532 class_name = make_class_name(dev->class->name,
535 sysfs_create_link(&dev->parent->kobj,
536 &dev->kobj, class_name);
541 if ((error = device_add_attrs(dev)))
543 if ((error = device_add_groups(dev)))
545 if ((error = device_pm_add(dev)))
547 if ((error = bus_add_device(dev)))
549 kobject_uevent(&dev->kobj, KOBJ_ADD);
550 if ((error = bus_attach_device(dev)))
553 klist_add_tail(&dev->knode_parent, &parent->klist_children);
556 down(&dev->class->sem);
557 /* tie the class to the device */
558 list_add_tail(&dev->node, &dev->class->devices);
560 /* notify any interfaces that the device is here */
561 list_for_each_entry(class_intf, &dev->class->interfaces, node)
562 if (class_intf->add_dev)
563 class_intf->add_dev(dev, class_intf);
564 up(&dev->class->sem);
571 bus_remove_device(dev);
573 device_pm_remove(dev);
576 blocking_notifier_call_chain(&dev->bus->bus_notifier,
577 BUS_NOTIFY_DEL_DEVICE, dev);
578 device_remove_groups(dev);
580 device_remove_attrs(dev);
582 if (dev->devt_attr) {
583 device_remove_file(dev, dev->devt_attr);
584 kfree(dev->devt_attr);
587 device_remove_file(dev, &dev->uevent_attr);
589 kobject_uevent(&dev->kobj, KOBJ_REMOVE);
590 kobject_del(&dev->kobj);
599 * device_register - register a device with the system.
600 * @dev: pointer to the device structure
602 * This happens in two clean steps - initialize the device
603 * and add it to the system. The two steps can be called
604 * separately, but this is the easiest and most common.
605 * I.e. you should only call the two helpers separately if
606 * have a clearly defined need to use and refcount the device
607 * before it is added to the hierarchy.
610 int device_register(struct device *dev)
612 device_initialize(dev);
613 return device_add(dev);
618 * get_device - increment reference count for device.
621 * This simply forwards the call to kobject_get(), though
622 * we do take care to provide for the case that we get a NULL
626 struct device * get_device(struct device * dev)
628 return dev ? to_dev(kobject_get(&dev->kobj)) : NULL;
633 * put_device - decrement reference count.
634 * @dev: device in question.
636 void put_device(struct device * dev)
639 kobject_put(&dev->kobj);
644 * device_del - delete device from system.
647 * This is the first part of the device unregistration
648 * sequence. This removes the device from the lists we control
649 * from here, has it removed from the other driver model
650 * subsystems it was added to in device_add(), and removes it
651 * from the kobject hierarchy.
653 * NOTE: this should be called manually _iff_ device_add() was
654 * also called manually.
657 void device_del(struct device * dev)
659 struct device * parent = dev->parent;
660 struct class_interface *class_intf;
663 klist_del(&dev->knode_parent);
664 if (dev->devt_attr) {
665 device_remove_file(dev, dev->devt_attr);
666 kfree(dev->devt_attr);
669 sysfs_remove_link(&dev->kobj, "subsystem");
670 /* If this is not a "fake" compatible device, remove the
671 * symlink from the class to the device. */
672 if (dev->kobj.parent != &dev->class->subsys.kset.kobj)
673 sysfs_remove_link(&dev->class->subsys.kset.kobj,
675 #ifdef CONFIG_SYSFS_DEPRECATED
677 char *class_name = make_class_name(dev->class->name,
680 sysfs_remove_link(&dev->parent->kobj,
683 sysfs_remove_link(&dev->kobj, "device");
687 down(&dev->class->sem);
688 /* notify any interfaces that the device is now gone */
689 list_for_each_entry(class_intf, &dev->class->interfaces, node)
690 if (class_intf->remove_dev)
691 class_intf->remove_dev(dev, class_intf);
692 /* remove the device from the class list */
693 list_del_init(&dev->node);
694 up(&dev->class->sem);
696 device_remove_file(dev, &dev->uevent_attr);
697 device_remove_groups(dev);
698 device_remove_attrs(dev);
699 bus_remove_device(dev);
701 /* Notify the platform of the removal, in case they
702 * need to do anything...
704 if (platform_notify_remove)
705 platform_notify_remove(dev);
707 blocking_notifier_call_chain(&dev->bus->bus_notifier,
708 BUS_NOTIFY_DEL_DEVICE, dev);
709 device_pm_remove(dev);
710 kobject_uevent(&dev->kobj, KOBJ_REMOVE);
711 kobject_del(&dev->kobj);
717 * device_unregister - unregister device from system.
718 * @dev: device going away.
720 * We do this in two parts, like we do device_register(). First,
721 * we remove it from all the subsystems with device_del(), then
722 * we decrement the reference count via put_device(). If that
723 * is the final reference count, the device will be cleaned up
724 * via device_release() above. Otherwise, the structure will
725 * stick around until the final reference to the device is dropped.
727 void device_unregister(struct device * dev)
729 pr_debug("DEV: Unregistering device. ID = '%s'\n", dev->bus_id);
735 static struct device * next_device(struct klist_iter * i)
737 struct klist_node * n = klist_next(i);
738 return n ? container_of(n, struct device, knode_parent) : NULL;
742 * device_for_each_child - device child iterator.
743 * @parent: parent struct device.
744 * @data: data for the callback.
745 * @fn: function to be called for each device.
747 * Iterate over @parent's child devices, and call @fn for each,
750 * We check the return of @fn each time. If it returns anything
751 * other than 0, we break out and return that value.
753 int device_for_each_child(struct device * parent, void * data,
754 int (*fn)(struct device *, void *))
757 struct device * child;
760 klist_iter_init(&parent->klist_children, &i);
761 while ((child = next_device(&i)) && !error)
762 error = fn(child, data);
768 * device_find_child - device iterator for locating a particular device.
769 * @parent: parent struct device
770 * @data: Data to pass to match function
771 * @match: Callback function to check device
773 * This is similar to the device_for_each_child() function above, but it
774 * returns a reference to a device that is 'found' for later use, as
775 * determined by the @match callback.
777 * The callback should return 0 if the device doesn't match and non-zero
778 * if it does. If the callback returns non-zero and a reference to the
779 * current device can be obtained, this function will return to the caller
780 * and not iterate over any more devices.
782 struct device * device_find_child(struct device *parent, void *data,
783 int (*match)(struct device *, void *))
786 struct device *child;
791 klist_iter_init(&parent->klist_children, &i);
792 while ((child = next_device(&i)))
793 if (match(child, data) && get_device(child))
799 int __init devices_init(void)
801 return subsystem_register(&devices_subsys);
804 EXPORT_SYMBOL_GPL(device_for_each_child);
805 EXPORT_SYMBOL_GPL(device_find_child);
807 EXPORT_SYMBOL_GPL(device_initialize);
808 EXPORT_SYMBOL_GPL(device_add);
809 EXPORT_SYMBOL_GPL(device_register);
811 EXPORT_SYMBOL_GPL(device_del);
812 EXPORT_SYMBOL_GPL(device_unregister);
813 EXPORT_SYMBOL_GPL(get_device);
814 EXPORT_SYMBOL_GPL(put_device);
816 EXPORT_SYMBOL_GPL(device_create_file);
817 EXPORT_SYMBOL_GPL(device_remove_file);
820 static void device_create_release(struct device *dev)
822 pr_debug("%s called for %s\n", __FUNCTION__, dev->bus_id);
827 * device_create - creates a device and registers it with sysfs
828 * @class: pointer to the struct class that this device should be registered to
829 * @parent: pointer to the parent struct device of this new device, if any
830 * @devt: the dev_t for the char device to be added
831 * @fmt: string for the device's name
833 * This function can be used by char device classes. A struct device
834 * will be created in sysfs, registered to the specified class.
836 * A "dev" file will be created, showing the dev_t for the device, if
837 * the dev_t is not 0,0.
838 * If a pointer to a parent struct device is passed in, the newly created
839 * struct device will be a child of that device in sysfs.
840 * The pointer to the struct device will be returned from the call.
841 * Any further sysfs files that might be required can be created using this
844 * Note: the struct class passed to this function must have previously
845 * been created with a call to class_create().
847 struct device *device_create(struct class *class, struct device *parent,
848 dev_t devt, const char *fmt, ...)
851 struct device *dev = NULL;
852 int retval = -ENODEV;
854 if (class == NULL || IS_ERR(class))
857 dev = kzalloc(sizeof(*dev), GFP_KERNEL);
865 dev->parent = parent;
866 dev->release = device_create_release;
869 vsnprintf(dev->bus_id, BUS_ID_SIZE, fmt, args);
871 retval = device_register(dev);
879 return ERR_PTR(retval);
881 EXPORT_SYMBOL_GPL(device_create);
884 * device_destroy - removes a device that was created with device_create()
885 * @class: pointer to the struct class that this device was registered with
886 * @devt: the dev_t of the device that was previously registered
888 * This call unregisters and cleans up a device that was created with a
889 * call to device_create().
891 void device_destroy(struct class *class, dev_t devt)
893 struct device *dev = NULL;
894 struct device *dev_tmp;
897 list_for_each_entry(dev_tmp, &class->devices, node) {
898 if (dev_tmp->devt == devt) {
906 device_unregister(dev);
908 EXPORT_SYMBOL_GPL(device_destroy);
911 * device_rename - renames a device
912 * @dev: the pointer to the struct device to be renamed
913 * @new_name: the new name of the device
915 int device_rename(struct device *dev, char *new_name)
917 char *old_class_name = NULL;
918 char *new_class_name = NULL;
919 char *old_symlink_name = NULL;
922 dev = get_device(dev);
926 pr_debug("DEVICE: renaming '%s' to '%s'\n", dev->bus_id, new_name);
928 #ifdef CONFIG_SYSFS_DEPRECATED
929 if ((dev->class) && (dev->parent))
930 old_class_name = make_class_name(dev->class->name, &dev->kobj);
934 old_symlink_name = kmalloc(BUS_ID_SIZE, GFP_KERNEL);
935 if (!old_symlink_name) {
937 goto out_free_old_class;
939 strlcpy(old_symlink_name, dev->bus_id, BUS_ID_SIZE);
942 strlcpy(dev->bus_id, new_name, BUS_ID_SIZE);
944 error = kobject_rename(&dev->kobj, new_name);
946 #ifdef CONFIG_SYSFS_DEPRECATED
947 if (old_class_name) {
948 new_class_name = make_class_name(dev->class->name, &dev->kobj);
949 if (new_class_name) {
950 sysfs_create_link(&dev->parent->kobj, &dev->kobj,
952 sysfs_remove_link(&dev->parent->kobj, old_class_name);
958 sysfs_remove_link(&dev->class->subsys.kset.kobj,
960 sysfs_create_link(&dev->class->subsys.kset.kobj, &dev->kobj,
965 kfree(new_class_name);
966 kfree(old_symlink_name);
968 kfree(old_class_name);
974 static int device_move_class_links(struct device *dev,
975 struct device *old_parent,
976 struct device *new_parent)
978 #ifdef CONFIG_SYSFS_DEPRECATED
982 class_name = make_class_name(dev->class->name, &dev->kobj);
988 sysfs_remove_link(&dev->kobj, "device");
989 sysfs_remove_link(&old_parent->kobj, class_name);
992 error = sysfs_create_link(&dev->kobj, &new_parent->kobj,
996 error = sysfs_create_link(&new_parent->kobj, &dev->kobj,
999 sysfs_remove_link(&dev->kobj, "device");
1012 * device_move - moves a device to a new parent
1013 * @dev: the pointer to the struct device to be moved
1014 * @new_parent: the new parent of the device (can by NULL)
1016 int device_move(struct device *dev, struct device *new_parent)
1019 struct device *old_parent;
1020 struct kobject *new_parent_kobj;
1022 dev = get_device(dev);
1026 new_parent = get_device(new_parent);
1027 new_parent_kobj = get_device_parent (dev, new_parent);
1028 if (IS_ERR(new_parent_kobj)) {
1029 error = PTR_ERR(new_parent_kobj);
1030 put_device(new_parent);
1033 pr_debug("DEVICE: moving '%s' to '%s'\n", dev->bus_id,
1034 new_parent ? new_parent->bus_id : "<NULL>");
1035 error = kobject_move(&dev->kobj, new_parent_kobj);
1037 put_device(new_parent);
1040 old_parent = dev->parent;
1041 dev->parent = new_parent;
1043 klist_remove(&dev->knode_parent);
1045 klist_add_tail(&dev->knode_parent, &new_parent->klist_children);
1048 error = device_move_class_links(dev, old_parent, new_parent);
1050 /* We ignore errors on cleanup since we're hosed anyway... */
1051 device_move_class_links(dev, new_parent, old_parent);
1052 if (!kobject_move(&dev->kobj, &old_parent->kobj)) {
1054 klist_remove(&dev->knode_parent);
1056 klist_add_tail(&dev->knode_parent,
1057 &old_parent->klist_children);
1059 put_device(new_parent);
1063 put_device(old_parent);
1069 EXPORT_SYMBOL_GPL(device_move);