From patchwork Thu Oct 29 12:52:31 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 55764 Delivered-To: patch@linaro.org Received: by 10.112.61.134 with SMTP id p6csp544274lbr; Thu, 29 Oct 2015 05:53:42 -0700 (PDT) X-Received: by 10.50.65.101 with SMTP id w5mr9926802igs.3.1446123221864; Thu, 29 Oct 2015 05:53:41 -0700 (PDT) Return-Path: Received: from bombadil.infradead.org (bombadil.infradead.org. [2001:1868:205::9]) by mx.google.com with ESMTPS id av10si2947263igc.36.2015.10.29.05.53.41 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 29 Oct 2015 05:53:41 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-mtd-bounces+patch=linaro.org@lists.infradead.org designates 2001:1868:205::9 as permitted sender) client-ip=2001:1868:205::9; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-mtd-bounces+patch=linaro.org@lists.infradead.org designates 2001:1868:205::9 as permitted sender) smtp.mailfrom=linux-mtd-bounces+patch=linaro.org@lists.infradead.org; dkim=neutral (body hash did not verify) header.i=@linaro_org.20150623.gappssmtp.com Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1Zrmho-0000k5-38; Thu, 29 Oct 2015 12:53:24 +0000 Received: from mail-lf0-x236.google.com ([2a00:1450:4010:c07::236]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1Zrmha-0000ed-9s for linux-mtd@lists.infradead.org; Thu, 29 Oct 2015 12:53:11 +0000 Received: by lfaz124 with SMTP id z124so18245704lfa.1 for ; Thu, 29 Oct 2015 05:52:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro_org.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=cyzwuPF30hgpDBfbChwhtRuxcwTsbTKrWpWAe2OcEsA=; b=zuJpXu/EX2EVPO8s66Cx95pBIjd2jzojEmkx+APTLFJ0/A0QpUNeRjb25TvICk+OTm bBvcQCA+dmapDaw+g9Cr73gcDmsZniMMkT4MmAxzku2yxuSDokpGky+5qC9lRDzuS8Dv X4P8LiubYuCobzEzWRWuVlhJZrCLkHjKlSWxm5/+jNWo8YX9HghagxAWYmdKRwxr35Y9 17t7JNPmfSYr4wi6jWAPAwlJa8OJCVUwy20/jEhoERSLk9W9MEnkZuMwCyhho40vvCL5 bAjRnumoODTpXIGJyTG4NEHjfuiQp9eKYvHm+AUGSEeYgSlhB8RtIR0wJPAk6fdAB5Ju BbQw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=cyzwuPF30hgpDBfbChwhtRuxcwTsbTKrWpWAe2OcEsA=; b=KRQaJQxQ4jeaL2+9nnRDIWFe3fb3hbP7rIUvOpVb51UR0jQ4UOGva5bru8doLmibNs PudW1tzKJlGmL8LExukJELeqyMGmPNyE5natNbrTeugDD9Wldwkojxyjqbekn/qILJl4 DJW2bfBnzJVe5+fnb2D6d3FL/Wv64TSoBUGXxRx+UZk1XqvBWsf3VJBD5y0OlW0Yn5Qc NkHVdqR+APR42t0YWT6Z/kSOHUwFnxFjXrm6fEK/d/lSpihxyQQYEFZGyPzwkj0MF/VS 2Kj34xyN42+KmmeCBCVpzmykLt+zznwn3v4uLwN5Sp7AFfd5ndKdbnMkX1nTft+A1Im5 A4mw== X-Gm-Message-State: ALoCoQlYRV8yPOJ0mgayYoQt1uqAi/5xFMSHvwchCnelZOXj58WXQdluG1IEAcTaz6tuI3JANR+B X-Received: by 10.25.40.65 with SMTP id o62mr569167lfo.115.1446123168328; Thu, 29 Oct 2015 05:52:48 -0700 (PDT) Received: from localhost.localdomain ([85.235.10.227]) by smtp.gmail.com with ESMTPSA id o197sm300467lfb.7.2015.10.29.05.52.46 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 29 Oct 2015 05:52:47 -0700 (PDT) From: Linus Walleij To: David Woodhouse , Brian Norris , linux-mtd@lists.infradead.org Subject: [PATCH 2/3] mtd: physmap_of: break out array clone code Date: Thu, 29 Oct 2015 13:52:31 +0100 Message-Id: <1446123152-22666-2-git-send-email-linus.walleij@linaro.org> X-Mailer: git-send-email 2.4.3 In-Reply-To: <1446123152-22666-1-git-send-email-linus.walleij@linaro.org> References: <1446123152-22666-1-git-send-email-linus.walleij@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20151029_055310_648070_64B6CA52 X-CRM114-Status: GOOD ( 17.83 ) X-Spam-Score: -2.6 (--) X-Spam-Report: SpamAssassin version 3.4.0 on bombadil.infradead.org summary: Content analysis details: (-2.6 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.7 RCVD_IN_DNSWL_LOW RBL: Sender listed at http://www.dnswl.org/, low trust [2a00:1450:4010:c07:0:0:0:236 listed in] [list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature X-BeenThere: linux-mtd@lists.infradead.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: Linux MTD discussion mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Linus Walleij , linux-arm-kernel@lists.infradead.org MIME-Version: 1.0 Sender: "linux-mtd" Errors-To: linux-mtd-bounces+patch=linaro.org@lists.infradead.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 --- drivers/mtd/maps/physmap_of.c | 29 +++++++++++++++++++++-------- 1 file changed, 21 insertions(+), 8 deletions(-) -- 2.4.3 ______________________________________________________ Linux MTD discussion mailing list http://lists.infradead.org/mailman/listinfo/linux-mtd/ 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)