[PATCH] Driver core: kernel-doc in drivers/base/core.c corrections
[firefly-linux-kernel-4.4.55.git] / drivers / base / core.c
index a979bc3f49a99d297135d4e9143b53063a488d7e..be6b5bc0677d545c0f79efd659f98d268fffb200 100644 (file)
@@ -8,7 +8,6 @@
  *
  */
 
-#include <linux/config.h>
 #include <linux/device.h>
 #include <linux/err.h>
 #include <linux/init.h>
@@ -29,6 +28,22 @@ int (*platform_notify_remove)(struct device * dev) = NULL;
  * sysfs bindings for devices.
  */
 
+/**
+ * dev_driver_string - Return a device's driver name, if at all possible
+ * @dev: struct device to get the name of
+ *
+ * Will return the device's driver's name if it is bound to a device.  If
+ * the device is not bound to a device, it will return the name of the bus
+ * it is attached to.  If it is not attached to a bus either, an empty
+ * string will be returned.
+ */
+const char *dev_driver_string(struct device *dev)
+{
+       return dev->driver ? dev->driver->name :
+                       (dev->bus ? dev->bus->name : "");
+}
+EXPORT_SYMBOL_GPL(dev_driver_string);
+
 #define to_dev(obj) container_of(obj, struct device, kobj)
 #define to_dev_attr(_attr) container_of(_attr, struct device_attribute, attr)
 
@@ -340,6 +355,13 @@ int device_add(struct device *dev)
        if (parent)
                klist_add_tail(&dev->knode_parent, &parent->klist_children);
 
+       if (dev->class) {
+               /* tie the class to the device */
+               down(&dev->class->sem);
+               list_add_tail(&dev->node, &dev->class->devices);
+               up(&dev->class->sem);
+       }
+
        /* notify platform of device entry */
        if (platform_notify)
                platform_notify(dev);
@@ -439,6 +461,9 @@ void device_del(struct device * dev)
                sysfs_remove_link(&dev->kobj, "device");
                sysfs_remove_link(&dev->parent->kobj, class_name);
                kfree(class_name);
+               down(&dev->class->sem);
+               list_del_init(&dev->node);
+               up(&dev->class->sem);
        }
        device_remove_file(dev, &dev->uevent_attr);
 
@@ -534,20 +559,20 @@ static void device_create_release(struct device *dev)
 
 /**
  * device_create - creates a device and registers it with sysfs
- * @cs: pointer to the struct class that this device should be registered to.
- * @parent: pointer to the parent struct device of this new device, if any.
- * @dev: the dev_t for the char device to be added.
- * @fmt: string for the class device's name
+ * @class: pointer to the struct class that this device should be registered to
+ * @parent: pointer to the parent struct device of this new device, if any
+ * @devt: the dev_t for the char device to be added
+ * @fmt: string for the device's name
+ *
+ * This function can be used by char device classes.  A struct device
+ * will be created in sysfs, registered to the specified class.
  *
- * This function can be used by char device classes.  A struct
- * device will be created in sysfs, registered to the specified
- * class.
  * A "dev" file will be created, showing the dev_t for the device, if
  * the dev_t is not 0,0.
- * If a pointer to a parent struct device is passed in, the newly
- * created struct device will be a child of that device in sysfs.  The
- * pointer to the struct device will be returned from the call.  Any
- * further sysfs files that might be required can be created using this
+ * If a pointer to a parent struct device is passed in, the newly created
+ * struct device will be a child of that device in sysfs.
+ * The pointer to the struct device will be returned from the call.
+ * Any further sysfs files that might be required can be created using this
  * pointer.
  *
  * Note: the struct class passed to this function must have previously
@@ -585,11 +610,6 @@ struct device *device_create(struct class *class, struct device *parent,
        if (retval)
                goto error;
 
-       /* tie the class to the device */
-       down(&class->sem);
-       list_add_tail(&dev->node, &class->devices);
-       up(&class->sem);
-
        return dev;
 
 error:
@@ -600,11 +620,11 @@ EXPORT_SYMBOL_GPL(device_create);
 
 /**
  * device_destroy - removes a device that was created with device_create()
- * @class: the pointer to the struct class that this device was registered * with.
- * @dev: the dev_t of the device that was previously registered.
+ * @class: pointer to the struct class that this device was registered with
+ * @devt: the dev_t of the device that was previously registered
  *
- * This call unregisters and cleans up a class device that was created with a
- * call to class_device_create()
+ * This call unregisters and cleans up a device that was created with a
+ * call to device_create().
  */
 void device_destroy(struct class *class, dev_t devt)
 {
@@ -620,9 +640,7 @@ void device_destroy(struct class *class, dev_t devt)
        }
        up(&class->sem);
 
-       if (dev) {
-               list_del_init(&dev->node);
+       if (dev)
                device_unregister(dev);
-       }
 }
 EXPORT_SYMBOL_GPL(device_destroy);