mtd: physmap_of: use OF helpers for reading strings
PATCH 1/1 mtd: physmap_of: use OF helpers for reading strings
From: Rafał Miłecki <[email protected]>
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.
--- drivers/mtd/maps/physmap_of.c | 30 ++++++++++-------------------- 1 file changed, 10 insertions(+), 20 deletions(-)
drivers/mtd/maps/physmap_of.c +10 -20
@@ -116,32 +116,22 @@ static const char * const part_probe_types_def[] = {static const char *const *of_get_probes (struct device_node *dp) { -const char *cp; -int cplen; -unsigned int l; -unsigned int count;const char **res; +int count; - cp =of_get_property (dp,"linux,part-probe" , &cplen); -if (cp ==NULL ) + count =of_property_count_strings (dp,"linux,part-probe" ); +if (count <0 )return part_probe_types_def; - count =0 ; -for (l =0 ; l != cplen; l++) -if (cp[l] ==0 ) - count++; - - res =kzalloc ((count +1 )*sizeof (*res),GFP_KERNEL ); + res =kzalloc ((count +1 ) *sizeof (*res),GFP_KERNEL );if (!res)return NULL ; - count =0 ; -while (cplen >0 ) { - res[count] = cp; - l =strlen (cp) +1 ; - cp += l; - cplen -= l; - count++; - } + + count =of_property_read_string_array (dp,"linux,part-probe" , res, + count); +if (count <0 ) +return NULL ; +return res; }
Signature · 6 lines
2.11.0 -- 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
A message that is not in the archive (sent off-list or not yet received): 20170330155853.30349-1-zajec5-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
Boris Brezillon
Reviewed-byQuoted 6 lines · On Thu, 30 Mar 2017 17:58:53 +0200 Rafał Miłecki…
From: Rafał Miłecki <[email protected]>
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 <[email protected]>
Quoted 41 lines
--- drivers/mtd/maps/physmap_of.c | 30 ++++++++++-------------------- 1 file changed, 10 insertions(+), 20 deletions(-)drivers/mtd/maps/physmap_of.c +4
-19@@ -116,32 +116,22 @@ static const char * const part_probe_types_def[] = {static const char *const *of_get_probes (struct device_node *dp) { -const char *cp; -int cplen; -unsigned int l; -unsigned int count;const char **res; +int count; - cp =of_get_property (dp,"linux,part-probe" , &cplen); -if (cp ==NULL ) + count =of_property_count_strings (dp,"linux,part-probe" ); +if (count <0 )return part_probe_types_def; - count =0 ; -for (l =0 ; l != cplen; l++) -if (cp[l] ==0 ) - count++; - - res =kzalloc ((count +1 )*sizeof (*res),GFP_KERNEL ); + res =kzalloc ((count +1 ) *sizeof (*res),GFP_KERNEL );if (!res)return NULL ; - count =0 ; -while (cplen >0 ) { - res[count] = cp; - l =strlen (cp) +1 ; - cp += l; - cplen -= l; - count++;
drivers/mtd/maps/physmap_of.c static const char * const part_probe_types_def[] = { · line 137
Quoted 10 lines
drivers/mtd/maps/physmap_of.c +6
-1- } + + count =of_property_read_string_array (dp,"linux,part-probe" , res, + count); +if (count <0 ) +return NULL ; +return res; }
--
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
Quoted 11 lines · Boris Brezillon
Quoted 6 lines · On Thu, 30 Mar 2017 17:58:53 +0200 Rafał Miłecki…
From: Rafał Miłecki <[email protected]>
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 <[email protected]>
Applied as a cleanup, while we figure out the future of this binding. With luck we can deprecate it (but not remove it, of course) and use something better in the generic code.
--
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