devicetree.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Heiko Stübner" <heiko@sntech.de>
To: Linus Walleij <linus.walleij@linaro.org>
Cc: "linux-arm-kernel@lists.infradead.org"
	<linux-arm-kernel@lists.infradead.org>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	Grant Likely <grant.likely@linaro.org>,
	rob.herring@calxeda.com, devicetree-discuss@lists.ozlabs.org,
	James Hogan <james.hogan@imgtec.com>,
	Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Subject: [PATCH 4/5] pinctrl: dynamically alloc temp array when parsing dt pinconf options
Date: Fri, 14 Jun 2013 17:43:55 +0200	[thread overview]
Message-ID: <201306141743.55811.heiko@sntech.de> (raw)
In-Reply-To: <201306141741.46077.heiko@sntech.de>

Allocating the temorary array in pinconf_generic_parse_dt_config on stack
might cause problems later on, when the number of options grows over time.
Therefore also allocate this array dynamically to be on the safe side.

Suggested-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Heiko Stuebner <heiko@sntech.de>
---
 drivers/pinctrl/pinconf-generic.c |   24 ++++++++++++++++++------
 1 file changed, 18 insertions(+), 6 deletions(-)

diff --git a/drivers/pinctrl/pinconf-generic.c b/drivers/pinctrl/pinconf-generic.c
index ea9da17..794dad7 100644
--- a/drivers/pinctrl/pinconf-generic.c
+++ b/drivers/pinctrl/pinconf-generic.c
@@ -182,7 +182,7 @@ int pinconf_generic_parse_dt_config(struct device_node *np,
 				    unsigned long **configs,
 				    unsigned int *nconfigs)
 {
-	unsigned long cfg[ARRAY_SIZE(dt_params)];
+	unsigned long *cfg;
 	unsigned int ncfg = 0;
 	int ret;
 	int i;
@@ -191,6 +191,11 @@ int pinconf_generic_parse_dt_config(struct device_node *np,
 	if (!np)
 		return -EINVAL;
 
+	/* allocate a temporary array big enough to hold one of each option */
+	cfg = kzalloc(sizeof(*cfg) * ARRAY_SIZE(dt_params), GFP_KERNEL);
+	if (!cfg)
+		return -ENOMEM;
+
 	for (i = 0; i < ARRAY_SIZE(dt_params); i++) {
 		struct pinconf_generic_dt_params *par = &dt_params[i];
 		ret = of_property_read_u32(np, par->property, &val);
@@ -208,11 +213,13 @@ int pinconf_generic_parse_dt_config(struct device_node *np,
 		ncfg++;
 	}
 
+	ret = 0;
+
 	/* no configs found at all */
 	if (ncfg == 0) {
 		*configs = NULL;
 		*nconfigs = 0;
-		return 0;
+		goto out;
 	}
 
 	/*
@@ -220,11 +227,16 @@ int pinconf_generic_parse_dt_config(struct device_node *np,
 	 * found properties.
 	 */
 	*configs = kzalloc(ncfg * sizeof(unsigned long), GFP_KERNEL);
-	if (!*configs)
-		return -ENOMEM;
+	if (!*configs) {
+		ret = -ENOMEM;
+		goto out;
+	}
 
-	memcpy(*configs, &cfg, ncfg * sizeof(unsigned long));
+	memcpy(*configs, cfg, ncfg * sizeof(unsigned long));
 	*nconfigs = ncfg;
-	return 0;
+
+out:
+	kfree(cfg);
+	return ret;
 }
 #endif
-- 
1.7.10.4

  parent reply	other threads:[~2013-06-14 15:43 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-06-14 15:41 [PATCH 0/5] pinctrl: fix some issues with new pinconfig dt parsing Heiko Stübner
2013-06-14 15:42 ` [PATCH 1/5] pinctrl: update the documentation for some pinconfig params Heiko Stübner
     [not found]   ` <201306141742.21808.heiko-4mtYJXux2i+zQB+pC5nmwQ@public.gmane.org>
2013-06-16 10:26     ` Linus Walleij
     [not found]       ` <CACRpkdaV78wXxGPFWVffEfnqrmhq1rsdVYdSKNx5mWaOcYOWrQ-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2013-06-16 10:45         ` Heiko Stübner
2013-06-16 12:26           ` Linus Walleij
2013-06-14 15:42 ` [PATCH 2/5] pinctrl: clarify some dt pinconfig options Heiko Stübner
2013-06-16 10:28   ` Linus Walleij
2013-06-19 22:10   ` Stephen Warren
2013-06-24  9:51     ` Linus Walleij
2013-06-14 15:43 ` [PATCH 3/5] pinctrl: handle zero found dt pinconfig properties better Heiko Stübner
2013-06-16 10:29   ` Linus Walleij
2013-06-14 15:43 ` Heiko Stübner [this message]
2013-06-16 10:31   ` [PATCH 4/5] pinctrl: dynamically alloc temp array when parsing dt pinconf options Linus Walleij
2013-06-14 15:44 ` [PATCH 5/5] pinctrl: rockchip: correctly handle arguments of " Heiko Stübner
2013-06-16 10:35   ` Linus Walleij
     [not found]     ` <CACRpkdY6pmS=5rphvYdt_8yKYJq8ADu0omy48ncZ3LFtEUf7yg-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2013-06-16 11:02       ` Heiko Stübner
     [not found]         ` <201306161302.32156.heiko-4mtYJXux2i+zQB+pC5nmwQ@public.gmane.org>
2013-06-16 12:35           ` Linus Walleij
2013-06-16 15:41             ` [PATCH v2] " Heiko Stübner
2013-06-17 15:48               ` Linus Walleij
2013-06-14 15:53 ` [PATCH 0/5] pinctrl: fix some issues with new pinconfig dt parsing James Hogan
2013-06-17  3:03   ` Laurent Pinchart

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=201306141743.55811.heiko@sntech.de \
    --to=heiko@sntech.de \
    --cc=devicetree-discuss@lists.ozlabs.org \
    --cc=grant.likely@linaro.org \
    --cc=james.hogan@imgtec.com \
    --cc=laurent.pinchart@ideasonboard.com \
    --cc=linus.walleij@linaro.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=rob.herring@calxeda.com \
    /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: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).