All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] pinctrl: shut up a couple of pinctrl warnings
@ 2013-07-27 10:38 Russell King - ARM Linux
  2013-07-28 12:13 ` [PATCH v2] " Russell King - ARM Linux
  0 siblings, 1 reply; 5+ messages in thread
From: Russell King - ARM Linux @ 2013-07-27 10:38 UTC (permalink / raw)
  To: linux-arm-kernel

So, I notice that we get a couple of warnings from the pinctrl code:

drivers/pinctrl/pinconf.c: In function 'pinconf_dbg_config_print':
drivers/pinctrl/pinconf.c:433:36: warning: 'configs' may be used uninitialized in this function
drivers/pinctrl/pinconf.c: In function 'pinconf_dbg_config_write':
drivers/pinctrl/pinconf.c:511:36: warning: 'configs' may be used uninitialized in this function

While the compiler might not be able to work out that "configs" is
safe, the code doesn't lend itself very well to identifying that
fact when reading it either.  This can be trivially solved by a slight
restructuring of the code - which also reduces the LOC.

Signed-off-by: Russell King <rmk+kernel@arm.linux.org.uk>
---
This patch is not yet build tested; it'll go through the build system
tonight though.

 drivers/pinctrl/pinconf.c |   29 +++++++++++------------------
 1 files changed, 11 insertions(+), 18 deletions(-)

diff --git a/drivers/pinctrl/pinconf.c b/drivers/pinctrl/pinconf.c
index e875f21..0674df3 100644
--- a/drivers/pinctrl/pinconf.c
+++ b/drivers/pinctrl/pinconf.c
@@ -428,12 +428,11 @@ static int pinconf_dbg_config_print(struct seq_file *s, void *d)
 {
 	struct pinctrl_maps *maps_node;
 	const struct pinctrl_map *map;
-	struct pinctrl_dev *pctldev = NULL;
+	const struct pinctrl_map *found = NULL;
+	struct pinctrl_dev *pctldev;
 	const struct pinconf_ops *confops = NULL;
-	const struct pinctrl_map_configs *configs;
 	struct dbg_cfg *dbg = &pinconf_dbg_conf;
 	int i, j;
-	bool found = false;
 	unsigned long config;
 
 	mutex_lock(&pinctrl_maps_mutex);
@@ -450,14 +449,8 @@ static int pinconf_dbg_config_print(struct seq_file *s, void *d)
 		for (j = 0; j < map->data.configs.num_configs; j++) {
 			if (!strcmp(map->data.configs.group_or_pin,
 					dbg->pin_name)) {
-				/*
-				 * We found the right pin / state, read the
-				 * config and he pctldev for later use
-				 */
-				configs = &map->data.configs;
-				pctldev = get_pinctrl_dev_from_devname
-					(map->ctrl_dev_name);
-				found = true;
+				/* We found the right pin / state */
+				found = map;
 				break;
 			}
 		}
@@ -473,7 +466,8 @@ static int pinconf_dbg_config_print(struct seq_file *s, void *d)
 		goto exit;
 	}
 
-	config = *(configs->configs);
+	pctldev = get_pinctrl_dev_from_devname(found->ctrl_dev_name);
+	config = *found->data.configs.configs;
 	seq_printf(s, "Dev %s has config of %s in state %s: 0x%08lX\n",
 			dbg->dev_name, dbg->pin_name,
 			dbg->state_name, config);
@@ -505,12 +499,12 @@ static int pinconf_dbg_config_write(struct file *file,
 {
 	struct pinctrl_maps *maps_node;
 	const struct pinctrl_map *map;
-	struct pinctrl_dev *pctldev = NULL;
+	const struct pinctrl_map *found = NULL;
+	struct pinctrl_dev *pctldev;
 	const struct pinconf_ops *confops = NULL;
 	struct dbg_cfg *dbg = &pinconf_dbg_conf;
 	const struct pinctrl_map_configs *configs;
 	char config[MAX_NAME_LEN+1];
-	bool found = false;
 	char buf[128];
 	char *b = &buf[0];
 	int buf_size;
@@ -588,10 +582,7 @@ static int pinconf_dbg_config_write(struct file *file,
 
 		/*  we found the right pin / state, so overwrite config */
 		if (!strcmp(map->data.configs.group_or_pin, dbg->pin_name)) {
-			found = true;
-			pctldev = get_pinctrl_dev_from_devname(
-					map->ctrl_dev_name);
-			configs = &map->data.configs;
+			found = map;
 			break;
 		}
 	}
@@ -601,10 +592,12 @@ static int pinconf_dbg_config_write(struct file *file,
 		goto exit;
 	}
 
+	pctldev = get_pinctrl_dev_from_devname(map->ctrl_dev_name);
 	if (pctldev)
 		confops = pctldev->desc->confops;
 
 	if (confops && confops->pin_config_dbg_parse_modify) {
+		configs = &map->data.configs;
 		for (i = 0; i < configs->num_configs; i++) {
 			confops->pin_config_dbg_parse_modify(pctldev,
 						     config,

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH v2] pinctrl: shut up a couple of pinctrl warnings
  2013-07-27 10:38 [PATCH] pinctrl: shut up a couple of pinctrl warnings Russell King - ARM Linux
@ 2013-07-28 12:13 ` Russell King - ARM Linux
  2013-08-07 18:19   ` Linus Walleij
  2013-08-07 19:16   ` Uwe Kleine-König
  0 siblings, 2 replies; 5+ messages in thread
From: Russell King - ARM Linux @ 2013-07-28 12:13 UTC (permalink / raw)
  To: linux-arm-kernel

So, I notice that we get a couple of warnings from the pinctrl code:

drivers/pinctrl/pinconf.c: In function 'pinconf_dbg_config_print':
drivers/pinctrl/pinconf.c:433:36: warning: 'configs' may be used uninitialized in this function
drivers/pinctrl/pinconf.c: In function 'pinconf_dbg_config_write':
drivers/pinctrl/pinconf.c:511:36: warning: 'configs' may be used uninitialized in this function

While the compiler might not be able to work out that "configs" is
safe, the code doesn't lend itself very well to identifying that
fact when reading it either.  This can be trivially solved by a slight
restructuring of the code - which also reduces the LOC.

Signed-off-by: Russell King <rmk+kernel@arm.linux.org.uk>
---
So last nights build test found a silly in the last patch, so that's fixed
in this version.

 drivers/pinctrl/pinconf.c |   29 +++++++++++------------------
 1 files changed, 11 insertions(+), 18 deletions(-)

diff --git a/drivers/pinctrl/pinconf.c b/drivers/pinctrl/pinconf.c
index e875f21..d16ef87 100644
--- a/drivers/pinctrl/pinconf.c
+++ b/drivers/pinctrl/pinconf.c
@@ -428,12 +428,11 @@ static int pinconf_dbg_config_print(struct seq_file *s, void *d)
 {
 	struct pinctrl_maps *maps_node;
 	const struct pinctrl_map *map;
-	struct pinctrl_dev *pctldev = NULL;
+	const struct pinctrl_map *found = NULL;
+	struct pinctrl_dev *pctldev;
 	const struct pinconf_ops *confops = NULL;
-	const struct pinctrl_map_configs *configs;
 	struct dbg_cfg *dbg = &pinconf_dbg_conf;
 	int i, j;
-	bool found = false;
 	unsigned long config;
 
 	mutex_lock(&pinctrl_maps_mutex);
@@ -450,14 +449,8 @@ static int pinconf_dbg_config_print(struct seq_file *s, void *d)
 		for (j = 0; j < map->data.configs.num_configs; j++) {
 			if (!strcmp(map->data.configs.group_or_pin,
 					dbg->pin_name)) {
-				/*
-				 * We found the right pin / state, read the
-				 * config and he pctldev for later use
-				 */
-				configs = &map->data.configs;
-				pctldev = get_pinctrl_dev_from_devname
-					(map->ctrl_dev_name);
-				found = true;
+				/* We found the right pin / state */
+				found = map;
 				break;
 			}
 		}
@@ -473,7 +466,8 @@ static int pinconf_dbg_config_print(struct seq_file *s, void *d)
 		goto exit;
 	}
 
-	config = *(configs->configs);
+	pctldev = get_pinctrl_dev_from_devname(found->ctrl_dev_name);
+	config = *found->data.configs.configs;
 	seq_printf(s, "Dev %s has config of %s in state %s: 0x%08lX\n",
 			dbg->dev_name, dbg->pin_name,
 			dbg->state_name, config);
@@ -505,12 +499,12 @@ static int pinconf_dbg_config_write(struct file *file,
 {
 	struct pinctrl_maps *maps_node;
 	const struct pinctrl_map *map;
-	struct pinctrl_dev *pctldev = NULL;
+	const struct pinctrl_map *found = NULL;
+	struct pinctrl_dev *pctldev;
 	const struct pinconf_ops *confops = NULL;
 	struct dbg_cfg *dbg = &pinconf_dbg_conf;
 	const struct pinctrl_map_configs *configs;
 	char config[MAX_NAME_LEN+1];
-	bool found = false;
 	char buf[128];
 	char *b = &buf[0];
 	int buf_size;
@@ -588,10 +582,7 @@ static int pinconf_dbg_config_write(struct file *file,
 
 		/*  we found the right pin / state, so overwrite config */
 		if (!strcmp(map->data.configs.group_or_pin, dbg->pin_name)) {
-			found = true;
-			pctldev = get_pinctrl_dev_from_devname(
-					map->ctrl_dev_name);
-			configs = &map->data.configs;
+			found = map;
 			break;
 		}
 	}
@@ -601,10 +592,12 @@ static int pinconf_dbg_config_write(struct file *file,
 		goto exit;
 	}
 
+	pctldev = get_pinctrl_dev_from_devname(found->ctrl_dev_name);
 	if (pctldev)
 		confops = pctldev->desc->confops;
 
 	if (confops && confops->pin_config_dbg_parse_modify) {
+		configs = &found->data.configs;
 		for (i = 0; i < configs->num_configs; i++) {
 			confops->pin_config_dbg_parse_modify(pctldev,
 						     config,

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH v2] pinctrl: shut up a couple of pinctrl warnings
  2013-07-28 12:13 ` [PATCH v2] " Russell King - ARM Linux
@ 2013-08-07 18:19   ` Linus Walleij
  2013-08-07 19:16   ` Uwe Kleine-König
  1 sibling, 0 replies; 5+ messages in thread
From: Linus Walleij @ 2013-08-07 18:19 UTC (permalink / raw)
  To: linux-arm-kernel

On Sun, Jul 28, 2013 at 2:13 PM, Russell King - ARM Linux
<linux@arm.linux.org.uk> wrote:

> So, I notice that we get a couple of warnings from the pinctrl code:
>
> drivers/pinctrl/pinconf.c: In function 'pinconf_dbg_config_print':
> drivers/pinctrl/pinconf.c:433:36: warning: 'configs' may be used uninitialized in this function
> drivers/pinctrl/pinconf.c: In function 'pinconf_dbg_config_write':
> drivers/pinctrl/pinconf.c:511:36: warning: 'configs' may be used uninitialized in this function
>
> While the compiler might not be able to work out that "configs" is
> safe, the code doesn't lend itself very well to identifying that
> fact when reading it either.  This can be trivially solved by a slight
> restructuring of the code - which also reduces the LOC.
>
> Signed-off-by: Russell King <rmk+kernel@arm.linux.org.uk>
> ---
> So last nights build test found a silly in the last patch, so that's fixed
> in this version.

Thanks Russell, patch applied. Sorry for taking so long.

Yours,
Linus Walleij

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH v2] pinctrl: shut up a couple of pinctrl warnings
  2013-07-28 12:13 ` [PATCH v2] " Russell King - ARM Linux
  2013-08-07 18:19   ` Linus Walleij
@ 2013-08-07 19:16   ` Uwe Kleine-König
  2013-08-07 19:54     ` Linus Walleij
  1 sibling, 1 reply; 5+ messages in thread
From: Uwe Kleine-König @ 2013-08-07 19:16 UTC (permalink / raw)
  To: linux-arm-kernel

Hello,

On Sun, Jul 28, 2013 at 01:13:00PM +0100, Russell King - ARM Linux wrote:
> diff --git a/drivers/pinctrl/pinconf.c b/drivers/pinctrl/pinconf.c
> index e875f21..d16ef87 100644
> --- a/drivers/pinctrl/pinconf.c
> +++ b/drivers/pinctrl/pinconf.c
> [...]
> @@ -450,14 +449,8 @@ static int pinconf_dbg_config_print(struct seq_file *s, void *d)
>  		for (j = 0; j < map->data.configs.num_configs; j++) {
>  			if (!strcmp(map->data.configs.group_or_pin,
>  					dbg->pin_name)) {
> -				/*
> -				 * We found the right pin / state, read the
> -				 * config and he pctldev for later use
he?

> -				 */
> -				configs = &map->data.configs;
> -				pctldev = get_pinctrl_dev_from_devname
> -					(map->ctrl_dev_name);
> -				found = true;
> +				/* We found the right pin / state */
> +				found = map;
>  				break;
>  			}
>  		}

-- 
Pengutronix e.K.                           | Uwe Kleine-K?nig            |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH v2] pinctrl: shut up a couple of pinctrl warnings
  2013-08-07 19:16   ` Uwe Kleine-König
@ 2013-08-07 19:54     ` Linus Walleij
  0 siblings, 0 replies; 5+ messages in thread
From: Linus Walleij @ 2013-08-07 19:54 UTC (permalink / raw)
  To: linux-arm-kernel

On Wed, Aug 7, 2013 at 9:16 PM, Uwe Kleine-K?nig
<u.kleine-koenig@pengutronix.de> wrote:

> Hello,
(...)
>> -                             /*
>> -                              * We found the right pin / state, read the
>> -                              * config and he pctldev for later use
> he?

... but Russell is *deleteing* that comment...

Yours,
Linus Walleij

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2013-08-07 19:54 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-07-27 10:38 [PATCH] pinctrl: shut up a couple of pinctrl warnings Russell King - ARM Linux
2013-07-28 12:13 ` [PATCH v2] " Russell King - ARM Linux
2013-08-07 18:19   ` Linus Walleij
2013-08-07 19:16   ` Uwe Kleine-König
2013-08-07 19:54     ` Linus Walleij

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.