From 8f5be0ec23bb9ef3f96659c8dff1340b876600bf Mon Sep 17 00:00:00 2001 From: Konstantin Khlebnikov Date: Mon, 13 Aug 2018 09:52:09 +0300 Subject: kernfs: update comment about kernfs_path() return value Now it returns the length of the full path or error code. Signed-off-by: Konstantin Khlebnikov Fixes: 3abb1d90f5d9 ("kernfs: make kernfs_path*() behave in the style of strlcpy()") Acked-by: Tejun Heo Signed-off-by: Greg Kroah-Hartman --- include/linux/kernfs.h | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'include') diff --git a/include/linux/kernfs.h b/include/linux/kernfs.h index 814643f7ee52..5b36b1287a5a 100644 --- a/include/linux/kernfs.h +++ b/include/linux/kernfs.h @@ -477,10 +477,11 @@ static inline void kernfs_init(void) { } * @buf: buffer to copy @kn's name into * @buflen: size of @buf * - * Builds and returns the full path of @kn in @buf of @buflen bytes. The - * path is built from the end of @buf so the returned pointer usually - * doesn't match @buf. If @buf isn't long enough, @buf is nul terminated - * and %NULL is returned. + * If @kn is NULL result will be "(null)". + * + * Returns the length of the full path. If the full length is equal to or + * greater than @buflen, @buf contains the truncated path with the trailing + * '\0'. On error, -errno is returned. */ static inline int kernfs_path(struct kernfs_node *kn, char *buf, size_t buflen) { -- cgit v1.2.3 From 8514c470dc18e58f27dee10a787175ef8f31162f Mon Sep 17 00:00:00 2001 From: Greg Kroah-Hartman Date: Wed, 11 Jul 2018 15:20:32 +0200 Subject: driver core: add BUS_ATTR_WO() macro Many bus attributes are write-only, so provide a simple macro for that to be able to match the other driver core attribute macros. Cc: "Rafael J. Wysocki" Cc: Ioana Ciornei Signed-off-by: Greg Kroah-Hartman --- include/linux/device.h | 2 ++ 1 file changed, 2 insertions(+) (limited to 'include') diff --git a/include/linux/device.h b/include/linux/device.h index 8f882549edee..767cf1938b14 100644 --- a/include/linux/device.h +++ b/include/linux/device.h @@ -55,6 +55,8 @@ struct bus_attribute { struct bus_attribute bus_attr_##_name = __ATTR_RW(_name) #define BUS_ATTR_RO(_name) \ struct bus_attribute bus_attr_##_name = __ATTR_RO(_name) +#define BUS_ATTR_WO(_name) \ + struct bus_attribute bus_attr_##_name = __ATTR_WO(_name) extern int __must_check bus_create_file(struct bus_type *, struct bus_attribute *); -- cgit v1.2.3 From 0571967dfb5d2573c2a06871517d748932a899d1 Mon Sep 17 00:00:00 2001 From: Bartosz Golaszewski Date: Sun, 14 Oct 2018 17:20:07 +0200 Subject: devres: constify p in devm_kfree() Make devm_kfree() signature uniform with that of kfree(). To avoid compiler warnings: cast p to (void *) when calling devres_destroy(). Signed-off-by: Bartosz Golaszewski Reviewed-by: Bjorn Andersson Reviewed-by: Geert Uytterhoeven Acked-by: Rasmus Villemoes Reviewed-by: Andy Shevchenko Signed-off-by: Greg Kroah-Hartman --- include/linux/device.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'include') diff --git a/include/linux/device.h b/include/linux/device.h index 767cf1938b14..c2022c1daef6 100644 --- a/include/linux/device.h +++ b/include/linux/device.h @@ -694,7 +694,7 @@ static inline void *devm_kcalloc(struct device *dev, { return devm_kmalloc_array(dev, n, size, flags | __GFP_ZERO); } -extern void devm_kfree(struct device *dev, void *p); +extern void devm_kfree(struct device *dev, const void *p); extern char *devm_kstrdup(struct device *dev, const char *s, gfp_t gfp) __malloc; extern void *devm_kmemdup(struct device *dev, const void *src, size_t len, gfp_t gfp); -- cgit v1.2.3 From 59c3f82ad1d6ed83fde9d7608afb9fb221a211ab Mon Sep 17 00:00:00 2001 From: Bartosz Golaszewski Date: Sun, 14 Oct 2018 17:20:08 +0200 Subject: mm: move is_kernel_rodata() to asm-generic/sections.h Export this routine so that we can use it later in devm_kstrdup_const() and devm_kfree(). Signed-off-by: Bartosz Golaszewski Reviewed-by: Bjorn Andersson Acked-by: Mike Rapoport Acked-by: Rasmus Villemoes Reviewed-by: Geert Uytterhoeven Reviewed-by: Andy Shevchenko Signed-off-by: Greg Kroah-Hartman --- include/asm-generic/sections.h | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'include') diff --git a/include/asm-generic/sections.h b/include/asm-generic/sections.h index 849cd8eb5ca0..d79abca81a52 100644 --- a/include/asm-generic/sections.h +++ b/include/asm-generic/sections.h @@ -141,4 +141,18 @@ static inline bool init_section_intersects(void *virt, size_t size) return memory_intersects(__init_begin, __init_end, virt, size); } +/** + * is_kernel_rodata - checks if the pointer address is located in the + * .rodata section + * + * @addr: address to check + * + * Returns: true if the address is located in .rodata, false otherwise. + */ +static inline bool is_kernel_rodata(unsigned long addr) +{ + return addr >= (unsigned long)__start_rodata && + addr < (unsigned long)__end_rodata; +} + #endif /* _ASM_GENERIC_SECTIONS_H_ */ -- cgit v1.2.3 From 09d1ea1c7309c8ca91151778bb3efe514f2e03ed Mon Sep 17 00:00:00 2001 From: Bartosz Golaszewski Date: Sun, 14 Oct 2018 17:20:09 +0200 Subject: devres: provide devm_kstrdup_const() Provide a resource managed version of kstrdup_const(). This variant internally calls devm_kstrdup() on pointers that are outside of .rodata section and returns the string as is otherwise. Make devm_kfree() check if the passed pointer doesn't point to .rodata and if so - don't actually destroy the resource. Signed-off-by: Bartosz Golaszewski Reviewed-by: Bjorn Andersson Acked-by: Mike Rapoport Acked-by: Rasmus Villemoes Reviewed-by: Geert Uytterhoeven Reviewed-by: Andy Shevchenko Signed-off-by: Greg Kroah-Hartman --- include/linux/device.h | 2 ++ 1 file changed, 2 insertions(+) (limited to 'include') diff --git a/include/linux/device.h b/include/linux/device.h index c2022c1daef6..fecd9722400e 100644 --- a/include/linux/device.h +++ b/include/linux/device.h @@ -696,6 +696,8 @@ static inline void *devm_kcalloc(struct device *dev, } extern void devm_kfree(struct device *dev, const void *p); extern char *devm_kstrdup(struct device *dev, const char *s, gfp_t gfp) __malloc; +extern const char *devm_kstrdup_const(struct device *dev, + const char *s, gfp_t gfp); extern void *devm_kmemdup(struct device *dev, const void *src, size_t len, gfp_t gfp); -- cgit v1.2.3