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

mtd: physmap_of: use OF helpers for reading strings

OF core code provides helpers for counting strings and reading them so
use them instead of doing this manually. This simplifies the code a bit.

Signed-off-by: Rafał Miłecki <rafal@milecki.pl>
Reviewed-by: Boris Brezillon <boris.brezillon@free-electrons.com>
Signed-off-by: Brian Norris <computersforpeace@gmail.com>

authored by

Rafał Miłecki and committed by
Brian Norris
da4b1caa b3bb6d6a

+10 -20
+10 -20
drivers/mtd/maps/physmap_of_core.c
··· 116 116 117 117 static const char * const *of_get_probes(struct device_node *dp) 118 118 { 119 - const char *cp; 120 - int cplen; 121 - unsigned int l; 122 - unsigned int count; 123 119 const char **res; 120 + int count; 124 121 125 - cp = of_get_property(dp, "linux,part-probe", &cplen); 126 - if (cp == NULL) 122 + count = of_property_count_strings(dp, "linux,part-probe"); 123 + if (count < 0) 127 124 return part_probe_types_def; 128 125 129 - count = 0; 130 - for (l = 0; l != cplen; l++) 131 - if (cp[l] == 0) 132 - count++; 133 - 134 - res = kzalloc((count + 1)*sizeof(*res), GFP_KERNEL); 126 + res = kzalloc((count + 1) * sizeof(*res), GFP_KERNEL); 135 127 if (!res) 136 128 return NULL; 137 - count = 0; 138 - while (cplen > 0) { 139 - res[count] = cp; 140 - l = strlen(cp) + 1; 141 - cp += l; 142 - cplen -= l; 143 - count++; 144 - } 129 + 130 + count = of_property_read_string_array(dp, "linux,part-probe", res, 131 + count); 132 + if (count < 0) 133 + return NULL; 134 + 145 135 return res; 146 136 } 147 137