From: Linus Walleij <linus.walleij@linaro.org> To: David Woodhouse <dwmw2@infradead.org>, Brian Norris <computersforpeace@gmail.com>, linux-mtd@lists.infradead.org Cc: linux-arm-kernel@lists.infradead.org, Linus Walleij <linus.walleij@linaro.org> Subject: [PATCH 2/3] mtd: physmap_of: break out array clone code Date: Thu, 29 Oct 2015 13:52:31 +0100 [thread overview] Message-ID: <1446123152-22666-2-git-send-email-linus.walleij@linaro.org> (raw) In-Reply-To: <1446123152-22666-1-git-send-email-linus.walleij@linaro.org> There is a piece of code cloning a string array in the end of the of_get_probes() function. Break it out, so we can reuse it. Signed-off-by: Linus Walleij <linus.walleij@linaro.org> --- drivers/mtd/maps/physmap_of.c | 29 +++++++++++++++++++++-------- 1 file changed, 21 insertions(+), 8 deletions(-) diff --git a/drivers/mtd/maps/physmap_of.c b/drivers/mtd/maps/physmap_of.c index 3e614e9119d5..1b66ca66206b 100644 --- a/drivers/mtd/maps/physmap_of.c +++ b/drivers/mtd/maps/physmap_of.c @@ -112,17 +112,18 @@ static struct mtd_info *obsolete_probe(struct platform_device *dev, static const char * const part_probe_types_def[] = { "cmdlinepart", "RedBoot", "ofpart", "ofoldpart", NULL }; -static const char * const *of_get_probes(struct device_node *dp) +/** + * string_to_array() - split a string into an array + * + * This takes "a\0string\0array" and splits it into { "a", "string", "array" } + * with a newly allocated array of pointers returned. A NULL terminator + * is also added at the end of the array. + */ +static const char * const *string_to_array(const char *cp, int cplen) { - const char *cp; - int cplen; + const char **res; unsigned int l; unsigned int count; - const char **res; - - cp = of_get_property(dp, "linux,part-probe", &cplen); - if (cp == NULL) - return part_probe_types_def; count = 0; for (l = 0; l != cplen; l++) @@ -143,6 +144,18 @@ static const char * const *of_get_probes(struct device_node *dp) return res; } +static const char * const *of_get_probes(struct device_node *dp) +{ + const char *cp; + int cplen; + int ret; + + cp = of_get_property(dp, "linux,part-probe", &cplen); + if (cp == NULL) + return part_probe_types_def; + return string_to_array(cp, cplen); +} + static void of_free_probes(const char * const *probes) { if (probes != part_probe_types_def) -- 2.4.3
WARNING: multiple messages have this Message-ID (diff)
From: linus.walleij@linaro.org (Linus Walleij) To: linux-arm-kernel@lists.infradead.org Subject: [PATCH 2/3] mtd: physmap_of: break out array clone code Date: Thu, 29 Oct 2015 13:52:31 +0100 [thread overview] Message-ID: <1446123152-22666-2-git-send-email-linus.walleij@linaro.org> (raw) In-Reply-To: <1446123152-22666-1-git-send-email-linus.walleij@linaro.org> There is a piece of code cloning a string array in the end of the of_get_probes() function. Break it out, so we can reuse it. Signed-off-by: Linus Walleij <linus.walleij@linaro.org> --- drivers/mtd/maps/physmap_of.c | 29 +++++++++++++++++++++-------- 1 file changed, 21 insertions(+), 8 deletions(-) diff --git a/drivers/mtd/maps/physmap_of.c b/drivers/mtd/maps/physmap_of.c index 3e614e9119d5..1b66ca66206b 100644 --- a/drivers/mtd/maps/physmap_of.c +++ b/drivers/mtd/maps/physmap_of.c @@ -112,17 +112,18 @@ static struct mtd_info *obsolete_probe(struct platform_device *dev, static const char * const part_probe_types_def[] = { "cmdlinepart", "RedBoot", "ofpart", "ofoldpart", NULL }; -static const char * const *of_get_probes(struct device_node *dp) +/** + * string_to_array() - split a string into an array + * + * This takes "a\0string\0array" and splits it into { "a", "string", "array" } + * with a newly allocated array of pointers returned. A NULL terminator + * is also added at the end of the array. + */ +static const char * const *string_to_array(const char *cp, int cplen) { - const char *cp; - int cplen; + const char **res; unsigned int l; unsigned int count; - const char **res; - - cp = of_get_property(dp, "linux,part-probe", &cplen); - if (cp == NULL) - return part_probe_types_def; count = 0; for (l = 0; l != cplen; l++) @@ -143,6 +144,18 @@ static const char * const *of_get_probes(struct device_node *dp) return res; } +static const char * const *of_get_probes(struct device_node *dp) +{ + const char *cp; + int cplen; + int ret; + + cp = of_get_property(dp, "linux,part-probe", &cplen); + if (cp == NULL) + return part_probe_types_def; + return string_to_array(cp, cplen); +} + static void of_free_probes(const char * const *probes) { if (probes != part_probe_types_def) -- 2.4.3
next prev parent reply other threads:[~2015-10-29 12:53 UTC|newest] Thread overview: 37+ messages / expand[flat|nested] mbox.gz Atom feed top 2015-10-29 12:52 [PATCH 1/3] mtd: create a partition type device tree binding Linus Walleij 2015-10-29 12:52 ` Linus Walleij 2015-10-29 12:52 ` Linus Walleij 2015-10-29 12:52 ` Linus Walleij [this message] 2015-10-29 12:52 ` [PATCH 2/3] mtd: physmap_of: break out array clone code Linus Walleij 2015-10-29 12:52 ` [PATCH 3/3] mtd: physmap_of: handle the new "partition-type" Linus Walleij 2015-10-29 12:52 ` Linus Walleij [not found] ` <1446123152-22666-1-git-send-email-linus.walleij-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org> 2015-10-29 16:29 ` [PATCH 1/3] mtd: create a partition type device tree binding Brian Norris 2015-10-29 16:29 ` Brian Norris 2015-10-29 16:29 ` Brian Norris 2015-10-30 14:00 ` Linus Walleij 2015-10-30 14:00 ` Linus Walleij 2015-10-30 14:00 ` Linus Walleij [not found] ` <CACRpkdYS5Jf8UC2K0bNdEQZDjTeZZx44Uu-kkof+9E=4Ny0oDg-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org> 2015-10-30 17:51 ` Brian Norris 2015-10-30 17:51 ` Brian Norris 2015-10-30 17:51 ` Brian Norris [not found] ` <20151030175145.GF13239-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org> 2015-11-06 14:13 ` Rob Herring 2015-11-06 14:13 ` Rob Herring 2015-11-06 14:13 ` Rob Herring [not found] ` <CAL_JsqL2F3p7qBPbOiGytVyzF_aNLWbrCT0mAX1WZo6SxE3JoA-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org> 2015-11-10 3:26 ` Brian Norris 2015-11-10 3:26 ` Brian Norris 2015-11-10 3:26 ` Brian Norris [not found] ` <20151110032626.GN12143-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org> 2015-11-10 8:43 ` Linus Walleij 2015-11-10 8:43 ` Linus Walleij 2015-11-10 8:43 ` Linus Walleij 2015-11-13 22:00 ` Brian Norris 2015-11-13 22:00 ` Brian Norris 2015-11-13 22:00 ` Brian Norris [not found] ` <20151113220039.GA74382-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org> 2015-11-14 10:46 ` Linus Walleij 2015-11-14 10:46 ` Linus Walleij 2015-11-14 10:46 ` Linus Walleij [not found] ` <CACRpkdakyae95f_Lc-R7Uf7wndj5hyfCqqHziwmZjwm-uNkGAg-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org> 2015-11-16 4:12 ` Brian Norris 2015-11-16 4:12 ` Brian Norris 2015-11-16 4:12 ` Brian Norris 2015-11-15 9:06 ` Geert Uytterhoeven 2015-11-15 9:06 ` Geert Uytterhoeven 2015-11-15 9:06 ` Geert Uytterhoeven
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=1446123152-22666-2-git-send-email-linus.walleij@linaro.org \ --to=linus.walleij@linaro.org \ --cc=computersforpeace@gmail.com \ --cc=dwmw2@infradead.org \ --cc=linux-arm-kernel@lists.infradead.org \ --cc=linux-mtd@lists.infradead.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes, see mirroring instructions on how to clone and mirror all data and code used by this external index.