Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

Merge tag 'driver-core-4.20-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/driver-core

Pull driver core updates from Greg KH:
"Here is a small number of driver core patches for 4.20-rc1.

Not much happened here this merge window, only a very tiny number of
patches that do:

- add BUS_ATTR_WO() for use by drivers

- component error path fixes

- kernfs range check fix

- other tiny error path fixes and const changes

All of these have been in linux-next with no reported issues for a
while"

* tag 'driver-core-4.20-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/driver-core:
devres: provide devm_kstrdup_const()
mm: move is_kernel_rodata() to asm-generic/sections.h
devres: constify p in devm_kfree()
driver core: add BUS_ATTR_WO() macro
kernfs: Fix range checks in kernfs_get_target_path
component: fix loop condition to call unbind() if bind() fails
drivers/base/devtmpfs.c: don't pretend path is const in delete_path
kernfs: update comment about kernfs_path() return value

+66 -19
+3 -3
drivers/base/component.c
··· 536 536 } 537 537 538 538 if (ret != 0) { 539 - for (; i--; ) 540 - if (!master->match->compare[i].duplicate) { 541 - c = master->match->compare[i].component; 539 + for (; i > 0; i--) 540 + if (!master->match->compare[i - 1].duplicate) { 541 + c = master->match->compare[i - 1].component; 542 542 component_unbind(c, master, data); 543 543 } 544 544 }
+34 -2
drivers/base/devres.c
··· 11 11 #include <linux/slab.h> 12 12 #include <linux/percpu.h> 13 13 14 + #include <asm/sections.h> 15 + 14 16 #include "base.h" 15 17 16 18 struct devres_node { ··· 825 823 EXPORT_SYMBOL_GPL(devm_kstrdup); 826 824 827 825 /** 826 + * devm_kstrdup_const - resource managed conditional string duplication 827 + * @dev: device for which to duplicate the string 828 + * @s: the string to duplicate 829 + * @gfp: the GFP mask used in the kmalloc() call when allocating memory 830 + * 831 + * Strings allocated by devm_kstrdup_const will be automatically freed when 832 + * the associated device is detached. 833 + * 834 + * RETURNS: 835 + * Source string if it is in .rodata section otherwise it falls back to 836 + * devm_kstrdup. 837 + */ 838 + const char *devm_kstrdup_const(struct device *dev, const char *s, gfp_t gfp) 839 + { 840 + if (is_kernel_rodata((unsigned long)s)) 841 + return s; 842 + 843 + return devm_kstrdup(dev, s, gfp); 844 + } 845 + EXPORT_SYMBOL_GPL(devm_kstrdup_const); 846 + 847 + /** 828 848 * devm_kvasprintf - Allocate resource managed space and format a string 829 849 * into that. 830 850 * @dev: Device to allocate memory for ··· 909 885 * 910 886 * Free memory allocated with devm_kmalloc(). 911 887 */ 912 - void devm_kfree(struct device *dev, void *p) 888 + void devm_kfree(struct device *dev, const void *p) 913 889 { 914 890 int rc; 915 891 916 - rc = devres_destroy(dev, devm_kmalloc_release, devm_kmalloc_match, p); 892 + /* 893 + * Special case: pointer to a string in .rodata returned by 894 + * devm_kstrdup_const(). 895 + */ 896 + if (unlikely(is_kernel_rodata((unsigned long)p))) 897 + return; 898 + 899 + rc = devres_destroy(dev, devm_kmalloc_release, 900 + devm_kmalloc_match, (void *)p); 917 901 WARN_ON(rc); 918 902 } 919 903 EXPORT_SYMBOL_GPL(devm_kfree);
+1 -1
drivers/base/devtmpfs.c
··· 252 252 253 253 static int delete_path(const char *nodepath) 254 254 { 255 - const char *path; 255 + char *path; 256 256 int err = 0; 257 257 258 258 path = kstrdup(nodepath, GFP_KERNEL);
+4 -1
fs/kernfs/symlink.c
··· 72 72 if (base == kn) 73 73 break; 74 74 75 + if ((s - path) + 3 >= PATH_MAX) 76 + return -ENAMETOOLONG; 77 + 75 78 strcpy(s, "../"); 76 79 s += 3; 77 80 base = base->parent; ··· 91 88 if (len < 2) 92 89 return -EINVAL; 93 90 len--; 94 - if ((s - path) + len > PATH_MAX) 91 + if ((s - path) + len >= PATH_MAX) 95 92 return -ENAMETOOLONG; 96 93 97 94 /* reverse fillup of target string from target to base */
+14
include/asm-generic/sections.h
··· 141 141 return memory_intersects(__init_begin, __init_end, virt, size); 142 142 } 143 143 144 + /** 145 + * is_kernel_rodata - checks if the pointer address is located in the 146 + * .rodata section 147 + * 148 + * @addr: address to check 149 + * 150 + * Returns: true if the address is located in .rodata, false otherwise. 151 + */ 152 + static inline bool is_kernel_rodata(unsigned long addr) 153 + { 154 + return addr >= (unsigned long)__start_rodata && 155 + addr < (unsigned long)__end_rodata; 156 + } 157 + 144 158 #endif /* _ASM_GENERIC_SECTIONS_H_ */
+5 -1
include/linux/device.h
··· 55 55 struct bus_attribute bus_attr_##_name = __ATTR_RW(_name) 56 56 #define BUS_ATTR_RO(_name) \ 57 57 struct bus_attribute bus_attr_##_name = __ATTR_RO(_name) 58 + #define BUS_ATTR_WO(_name) \ 59 + struct bus_attribute bus_attr_##_name = __ATTR_WO(_name) 58 60 59 61 extern int __must_check bus_create_file(struct bus_type *, 60 62 struct bus_attribute *); ··· 694 692 { 695 693 return devm_kmalloc_array(dev, n, size, flags | __GFP_ZERO); 696 694 } 697 - extern void devm_kfree(struct device *dev, void *p); 695 + extern void devm_kfree(struct device *dev, const void *p); 698 696 extern char *devm_kstrdup(struct device *dev, const char *s, gfp_t gfp) __malloc; 697 + extern const char *devm_kstrdup_const(struct device *dev, 698 + const char *s, gfp_t gfp); 699 699 extern void *devm_kmemdup(struct device *dev, const void *src, size_t len, 700 700 gfp_t gfp); 701 701
+5 -4
include/linux/kernfs.h
··· 477 477 * @buf: buffer to copy @kn's name into 478 478 * @buflen: size of @buf 479 479 * 480 - * Builds and returns the full path of @kn in @buf of @buflen bytes. The 481 - * path is built from the end of @buf so the returned pointer usually 482 - * doesn't match @buf. If @buf isn't long enough, @buf is nul terminated 483 - * and %NULL is returned. 480 + * If @kn is NULL result will be "(null)". 481 + * 482 + * Returns the length of the full path. If the full length is equal to or 483 + * greater than @buflen, @buf contains the truncated path with the trailing 484 + * '\0'. On error, -errno is returned. 484 485 */ 485 486 static inline int kernfs_path(struct kernfs_node *kn, char *buf, size_t buflen) 486 487 {
-7
mm/util.c
··· 15 15 #include <linux/vmalloc.h> 16 16 #include <linux/userfaultfd_k.h> 17 17 18 - #include <asm/sections.h> 19 18 #include <linux/uaccess.h> 20 19 21 20 #include "internal.h" 22 - 23 - static inline int is_kernel_rodata(unsigned long addr) 24 - { 25 - return addr >= (unsigned long)__start_rodata && 26 - addr < (unsigned long)__end_rodata; 27 - } 28 21 29 22 /** 30 23 * kfree_const - conditionally free memory