of: fix of_device_get_modalias returned length when truncating buffers
Subsystems (4)
Rob Herring
maintainerPATCH 1/2 of: fix of_device_get_modalias returned length when truncating buffers
If the length of the modalias is greater than the buffer size, then the modalias is truncated. However the untruncated length is returned which will cause an error. Fix this to return the truncated length. If an error in the case was desired, then then we should just return -ENOMEM.
The reality is no device will ever have 4KB of compatible strings to hit this case.
--- drivers/of/device.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/of/device.c +1 -1
@@ -223,7 +223,7 @@ ssize_t of_device_get_modalias(struct device *dev, char *str, ssize_t len) str[i] ='_' ; } -return tsize; +return repend; }/**
Signature · 6 lines
2.10.1 -- To unsubscribe from this list: send the line "unsubscribe devicetree" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Rob Herring
maintainerPATCH 2/2 of: Add function for generating a DT modalias with a newline
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.
--- arch/powerpc/platforms/pseries/ibmebus.c | 5 +---- drivers/base/platform.c | 2 +- drivers/macintosh/macio_sysfs.c | 7 +------ drivers/of/device.c | 16 +++++++++++++++- include/linux/of_device.h | 7 +++---- 5 files changed, 21 insertions(+), 16 deletions(-)
arch/powerpc/platforms/pseries/ibmebus.c +1 -4
@@ -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[] = {
drivers/base/platform.c +1 -1
@@ -837,7 +837,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;
drivers/macintosh/macio_sysfs.c +1 -6
@@ -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,
drivers/of/device.c +15 -1
@@ -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;
@@ -227,6 +227,20 @@ ssize_t of_device_get_modalias(struct device *dev, char *str, ssize_t len) }/** +* 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; +} + +/** * of_device_uevent - Display OF related uevent information */ void of_device_uevent (struct device *dev,struct kobj_uevent_env *env)
include/linux/of_device.h +3 -4
@@ -35,8 +35,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 void of_device_uevent (struct device *dev,struct kobj_uevent_env *env);extern int of_device_uevent_modalias (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 ; }
Signature · 1 line
2.10.1
Re: [PATCH 2/2] of: Add function for generating a DT modalias with a newline
Quoted 6 lines · Rob Herring
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 oldof_device_get_modaliasfunction.
Quoted 7 lines
Signed-off-by Rob Herring <[email protected]>Cc Benjamin Herrenschmidt <[email protected]>Cc Paul Mackerras <[email protected]>Cc Michael Ellerman <[email protected]>Cc Greg Kroah-Hartman <[email protected]>Cc Frank Rowand <[email protected]>