]> git.proxmox.com Git - mirror_ubuntu-artful-kernel.git/commitdiff
of: Add function for generating a DT modalias with a newline
authorRob Herring <robh@kernel.org>
Wed, 22 Mar 2017 14:16:27 +0000 (09:16 -0500)
committerRob Herring <robh@kernel.org>
Wed, 22 Mar 2017 19:56:13 +0000 (14:56 -0500)
The modalias sysfs attr is lacking a newline for DT aliases on platform
devices. The macio and ibmebus correctly add the newline, but open code it.
Introduce a new function, of_device_modalias(), that fills the buffer with
the modalias including the newline and update users of the old
of_device_get_modalias function.

Signed-off-by: Rob Herring <robh@kernel.org>
Cc: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Michael Ellerman <mpe@ellerman.id.au>
Cc: Frank Rowand <frowand.list@gmail.com>
Cc: linuxppc-dev@lists.ozlabs.org
Acked-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
arch/powerpc/platforms/pseries/ibmebus.c
drivers/base/platform.c
drivers/macintosh/macio_sysfs.c
drivers/of/device.c
drivers/tty/serdev/core.c
drivers/usb/common/ulpi.c
include/linux/of_device.h

index 99a6bf7f3bcf3508f6a452f9512757bd6649aeb8..b363e439ddb906badd35d2e343106b9d74e89dd7 100644 (file)
@@ -410,10 +410,7 @@ static ssize_t name_show(struct device *dev,
 static ssize_t modalias_show(struct device *dev,
                                struct device_attribute *attr, char *buf)
 {
-       ssize_t len = of_device_get_modalias(dev, buf, PAGE_SIZE - 2);
-       buf[len] = '\n';
-       buf[len+1] = 0;
-       return len+1;
+       return of_device_modalias(dev, buf, PAGE_SIZE);
 }
 
 static struct device_attribute ibmebus_bus_device_attrs[] = {
index c2456839214aee8065beaed9752d29d04371fbac..a102152301c8327b347e32d11230d635d3655cc2 100644 (file)
@@ -847,7 +847,7 @@ static ssize_t modalias_show(struct device *dev, struct device_attribute *a,
        struct platform_device  *pdev = to_platform_device(dev);
        int len;
 
-       len = of_device_get_modalias(dev, buf, PAGE_SIZE -1);
+       len = of_device_modalias(dev, buf, PAGE_SIZE);
        if (len != -ENODEV)
                return len;
 
index 8eb40afbd0f511fd5a7b09c8fc48b1b295eb9ea5..0b1f9c76c68d9c5287f286aef95ad882fb3b35df 100644 (file)
@@ -41,12 +41,7 @@ compatible_show (struct device *dev, struct device_attribute *attr, char *buf)
 static ssize_t modalias_show (struct device *dev, struct device_attribute *attr,
                              char *buf)
 {
-       int len = of_device_get_modalias(dev, buf, PAGE_SIZE - 2);
-
-       buf[len] = '\n';
-       buf[len+1] = 0;
-
-       return len+1;
+       return of_device_modalias(dev, buf, PAGE_SIZE);
 }
 
 static ssize_t devspec_show(struct device *dev,
index 210432a3c4ecc739fb0cf0fdf443c9f77e683082..6e2f9113b1b7ab18706b1b763699669e883533c2 100644 (file)
@@ -176,7 +176,7 @@ const void *of_device_get_match_data(const struct device *dev)
 }
 EXPORT_SYMBOL(of_device_get_match_data);
 
-ssize_t of_device_get_modalias(struct device *dev, char *str, ssize_t len)
+static ssize_t of_device_get_modalias(struct device *dev, char *str, ssize_t len)
 {
        const char *compat;
        int cplen, i;
@@ -225,7 +225,6 @@ ssize_t of_device_get_modalias(struct device *dev, char *str, ssize_t len)
 
        return repend;
 }
-EXPORT_SYMBOL_GPL(of_device_get_modalias);
 
 int of_device_request_module(struct device *dev)
 {
@@ -250,6 +249,21 @@ int of_device_request_module(struct device *dev)
 }
 EXPORT_SYMBOL_GPL(of_device_request_module);
 
+/**
+ * of_device_modalias - Fill buffer with newline terminated modalias string
+ */
+ssize_t of_device_modalias(struct device *dev, char *str, ssize_t len)
+{
+       ssize_t sl = of_device_get_modalias(dev, str, len - 2);
+       if (sl < 0)
+               return sl;
+
+       str[sl++] = '\n';
+       str[sl] = 0;
+       return sl;
+}
+EXPORT_SYMBOL_GPL(of_device_modalias);
+
 /**
  * of_device_uevent - Display OF related uevent information
  */
index f4c6c90add7882e92e43cea88dd2cc0d436fb21b..531aa89ff243d2abd5e66b3b28cc4c505c40bdb6 100644 (file)
@@ -191,10 +191,7 @@ static int serdev_drv_remove(struct device *dev)
 static ssize_t modalias_show(struct device *dev,
                             struct device_attribute *attr, char *buf)
 {
-       ssize_t len = of_device_get_modalias(dev, buf, PAGE_SIZE - 2);
-       buf[len] = '\n';
-       buf[len+1] = 0;
-       return len+1;
+       return of_device_modalias(dev, buf, PAGE_SIZE);
 }
 
 static struct device_attribute serdev_device_attrs[] = {
index c9480d77810c9ff93db21c18ac262a3a046c62b2..930e8f35f8df39255be60e2e8267f3acff72b2f9 100644 (file)
@@ -107,7 +107,7 @@ static ssize_t modalias_show(struct device *dev, struct device_attribute *attr,
        int len;
        struct ulpi *ulpi = to_ulpi_dev(dev);
 
-       len = of_device_get_modalias(dev, buf, PAGE_SIZE - 1);
+       len = of_device_modalias(dev, buf, PAGE_SIZE);
        if (len != -ENODEV)
                return len;
 
index c12dace043f3c840a8bb4d4540e06f897eeca8cb..169ea0bd8eb4e72549331f4a181dec50ae3c1946 100644 (file)
@@ -34,8 +34,7 @@ extern void of_device_unregister(struct platform_device *ofdev);
 
 extern const void *of_device_get_match_data(const struct device *dev);
 
-extern ssize_t of_device_get_modalias(struct device *dev,
-                                       char *str, ssize_t len);
+extern ssize_t of_device_modalias(struct device *dev, char *str, ssize_t len);
 extern int of_device_request_module(struct device *dev);
 
 extern void of_device_uevent(struct device *dev, struct kobj_uevent_env *env);
@@ -72,8 +71,8 @@ static inline const void *of_device_get_match_data(const struct device *dev)
        return NULL;
 }
 
-static inline int of_device_get_modalias(struct device *dev,
-                                  char *str, ssize_t len)
+static inline int of_device_modalias(struct device *dev,
+                                    char *str, ssize_t len)
 {
        return -ENODEV;
 }