All of lore.kernel.org
 help / color / mirror / Atom feed
From: aisheng.dong@freescale.com (Dong Aisheng)
To: linux-arm-kernel@lists.infradead.org
Subject: [PATCH] pinctrl: pinctrl-imx: fix map setting problem if NO_PAD_CTL
Date: Wed, 20 Jun 2012 17:17:35 +0800	[thread overview]
Message-ID: <20120620091735.GI10387@shlinux2.ap.freescale.net> (raw)
In-Reply-To: <1340178101-21605-1-git-send-email-jason77.wang@gmail.com>

On Wed, Jun 20, 2012 at 03:41:41PM +0800, Hui Wang wrote:
> new_map is allocated according to map_num instead of grp->npins,
> if a pin or some pins of a group has NO_PAD_CTL property, the map_num
> and the grp->npin are different definitely.
> 
> When we set mapping information to the new_map[], we should skip those
> pins with NO_PAD_CTL from index, otherwise it is possible the driver
> will aceesss to a unallocated region.
> 
Good catching.
Thanks.

> Cc: Dong Aisheng <dong.aisheng@linaro.org>
> Cc: Linus Walleij <linus.walleij@linaro.org>
> Cc: Shawn Guo <shawn.guo@linaro.org>
> Signed-off-by: Hui Wang <jason77.wang@gmail.com>
> ---
> This problem is easily reproduced if we set pinctrl in the
> ${board}.dts like following:
> fsl,pins = <pin_func_id1   config_with_NO_PAD_CTL
>             pin_func_id2   config_with_NO_PAD_CTL
>             pin_func_id3   config_normal>;
> 
>  drivers/pinctrl/pinctrl-imx.c | 9 +++++----
>  1 file changed, 5 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/pinctrl/pinctrl-imx.c b/drivers/pinctrl/pinctrl-imx.c
> index dd6d93a..0e21abb 100644
> --- a/drivers/pinctrl/pinctrl-imx.c
> +++ b/drivers/pinctrl/pinctrl-imx.c
> @@ -146,6 +146,7 @@ static int imx_dt_node_to_map(struct pinctrl_dev *pctldev,
>  	struct pinctrl_map *new_map;
>  	struct device_node *parent;
>  	int map_num = 1;
> +	int map_pos = 0;
>  	int i;
>  
>  	/*
> @@ -186,11 +187,11 @@ static int imx_dt_node_to_map(struct pinctrl_dev *pctldev,
>  	new_map++;
>  	for (i = 0; i < grp->npins; i++) {
>  		if (!(grp->configs[i] & IMX_NO_PAD_CTL)) {
> -			new_map[i].type = PIN_MAP_TYPE_CONFIGS_PIN;
> -			new_map[i].data.configs.group_or_pin =
> +			new_map[map_pos].type = PIN_MAP_TYPE_CONFIGS_PIN;
> +			new_map[map_pos].data.configs.group_or_pin =
>  					pin_get_name(pctldev, grp->pins[i]);
> -			new_map[i].data.configs.configs = &grp->configs[i];
> -			new_map[i].data.configs.num_configs = 1;
> +			new_map[map_pos].data.configs.configs = &grp->configs[i];
> +			new_map[map_pos++].data.configs.num_configs = 1;
I'm ok with the change, only a minor comment:
Does the change as follows look better?

-       for (i = 0; i < grp->npins; i++) {
+       for (i = j = 0; i < grp->npins; i++) {
                if (!(grp->configs[i] & IMX_NO_PAD_CTL)) {
-                       new_map[i].type = PIN_MAP_TYPE_CONFIGS_PIN;
-                       new_map[i].data.configs.group_or_pin =
+                       new_map[j].type = PIN_MAP_TYPE_CONFIGS_PIN;
+                       new_map[j].data.configs.group_or_pin =
                                        pin_get_name(pctldev, grp->pins[i]);
-                       new_map[i].data.configs.configs = &grp->configs[i];
-                       new_map[i].data.configs.num_configs = 1;
+                       new_map[j].data.configs.configs = &grp->configs[i];
+                       new_map[j].data.configs.num_configs = 1;
+                       j++;

Regards
Dong Aisheng

  parent reply	other threads:[~2012-06-20  9:17 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-06-20  7:41 [PATCH] pinctrl: pinctrl-imx: fix map setting problem if NO_PAD_CTL Hui Wang
2012-06-20  8:51 ` Linus Walleij
2012-06-20  9:17 ` Dong Aisheng [this message]
2012-06-20  9:52   ` Hui Wang
2012-06-20 10:14     ` Hui Wang

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=20120620091735.GI10387@shlinux2.ap.freescale.net \
    --to=aisheng.dong@freescale.com \
    --cc=linux-arm-kernel@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: link
Be 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.