* [PATCH] pinctrl: Cleanup string initializations (char[] instead of char *)
@ 2014-05-17 14:37 Manuel Schölling
2014-05-17 21:24 ` Thierry Reding
2014-05-22 21:57 ` Linus Walleij
0 siblings, 2 replies; 3+ messages in thread
From: Manuel Schölling @ 2014-05-17 14:37 UTC (permalink / raw)
To: linus.walleij
Cc: swarren, thierry.reding, linux-kernel, linux-tegra,
Manuel Schölling
Initializations like 'char *foo = "bar"' will create two variables: a static
string and a pointer (foo) to that static string. Instead 'char foo[] = "bar"'
will declare a single variable and will end up in shorter
assembly (according to Jeff Garzik on the KernelJanitor's TODO list).
Signed-off-by: Manuel Schölling <manuel.schoelling@gmx.de>
---
drivers/pinctrl/pinctrl-mxs.c | 6 +++---
drivers/pinctrl/pinctrl-single.c | 4 ++--
drivers/pinctrl/pinctrl-tegra.c | 2 +-
3 files changed, 6 insertions(+), 6 deletions(-)
diff --git a/drivers/pinctrl/pinctrl-mxs.c b/drivers/pinctrl/pinctrl-mxs.c
index 40c76f2..cd4215e 100644
--- a/drivers/pinctrl/pinctrl-mxs.c
+++ b/drivers/pinctrl/pinctrl-mxs.c
@@ -351,7 +351,7 @@ static int mxs_pinctrl_parse_group(struct platform_device *pdev,
struct mxs_pinctrl_data *d = platform_get_drvdata(pdev);
struct mxs_group *g = &d->soc->groups[idx];
struct property *prop;
- const char *propname = "fsl,pinmux-ids";
+ const char propname[] = "fsl,pinmux-ids";
char *group;
int length = strlen(np->name) + SUFFIX_LEN;
u32 val, i;
@@ -399,8 +399,8 @@ static int mxs_pinctrl_probe_dt(struct platform_device *pdev,
struct device_node *np = pdev->dev.of_node;
struct device_node *child;
struct mxs_function *f;
- const char *gpio_compat = "fsl,mxs-gpio";
- const char *fn, *fnull = "";
+ const char gpio_compat[] = "fsl,mxs-gpio";
+ const char *fn, fnull[] = "";
int i = 0, idxf = 0, idxg = 0;
int ret;
u32 val;
diff --git a/drivers/pinctrl/pinctrl-single.c b/drivers/pinctrl/pinctrl-single.c
index 2960557..a3ed99f 100644
--- a/drivers/pinctrl/pinctrl-single.c
+++ b/drivers/pinctrl/pinctrl-single.c
@@ -1561,8 +1561,8 @@ static struct of_device_id pcs_of_match[];
static int pcs_add_gpio_func(struct device_node *node, struct pcs_device *pcs)
{
- const char *propname = "pinctrl-single,gpio-range";
- const char *cellname = "#pinctrl-single,gpio-range-cells";
+ const char propname[] = "pinctrl-single,gpio-range";
+ const char cellname[] = "#pinctrl-single,gpio-range-cells";
struct of_phandle_args gpiospec;
struct pcs_gpiofunc_range *range;
int ret, i;
diff --git a/drivers/pinctrl/pinctrl-tegra.c b/drivers/pinctrl/pinctrl-tegra.c
index 6545809..43eeb1b 100644
--- a/drivers/pinctrl/pinctrl-tegra.c
+++ b/drivers/pinctrl/pinctrl-tegra.c
@@ -576,7 +576,7 @@ static void tegra_pinconf_config_dbg_show(struct pinctrl_dev *pctldev,
{
enum tegra_pinconf_param param = TEGRA_PINCONF_UNPACK_PARAM(config);
u16 arg = TEGRA_PINCONF_UNPACK_ARG(config);
- const char *pname = "unknown";
+ const char pname[] = "unknown";
int i;
for (i = 0; i < ARRAY_SIZE(cfg_params); i++) {
--
1.7.10.4
^ permalink raw reply related [flat|nested] 3+ messages in thread* Re: [PATCH] pinctrl: Cleanup string initializations (char[] instead of char *)
2014-05-17 14:37 [PATCH] pinctrl: Cleanup string initializations (char[] instead of char *) Manuel Schölling
@ 2014-05-17 21:24 ` Thierry Reding
2014-05-22 21:57 ` Linus Walleij
1 sibling, 0 replies; 3+ messages in thread
From: Thierry Reding @ 2014-05-17 21:24 UTC (permalink / raw)
To: Manuel Schölling; +Cc: linus.walleij, swarren, linux-kernel, linux-tegra
[-- Attachment #1: Type: text/plain, Size: 1455 bytes --]
On Sat, May 17, 2014 at 04:37:25PM +0200, Manuel Schölling wrote:
[...]
> diff --git a/drivers/pinctrl/pinctrl-tegra.c b/drivers/pinctrl/pinctrl-tegra.c
> index 6545809..43eeb1b 100644
> --- a/drivers/pinctrl/pinctrl-tegra.c
> +++ b/drivers/pinctrl/pinctrl-tegra.c
> @@ -576,7 +576,7 @@ static void tegra_pinconf_config_dbg_show(struct pinctrl_dev *pctldev,
> {
> enum tegra_pinconf_param param = TEGRA_PINCONF_UNPACK_PARAM(config);
> u16 arg = TEGRA_PINCONF_UNPACK_ARG(config);
> - const char *pname = "unknown";
> + const char pname[] = "unknown";
> int i;
>
> for (i = 0; i < ARRAY_SIZE(cfg_params); i++) {
When this hunk is applied, the build fails as follows:
CC drivers/pinctrl/pinctrl-tegra.o
drivers/pinctrl/pinctrl-tegra.c: In function 'tegra_pinconf_config_dbg_show':
drivers/pinctrl/pinctrl-tegra.c:589:4: warning: assignment of read-only location 'pname' [enabled by default]
pname = cfg_params[i].property;
^
drivers/pinctrl/pinctrl-tegra.c:589:10: error: incompatible types when assigning to type 'const char[8]' from type 'const char * const'
pname = cfg_params[i].property;
^
As you can see, pname is used to store a property name and the default
value is set to the static string "unknown" for cases where no matching
parameter is found in cfg_params. However, if a match is found the
default value will be overwritten, so you can't use const char [].
Thierry
[-- Attachment #2: Type: application/pgp-signature, Size: 836 bytes --]
^ permalink raw reply [flat|nested] 3+ messages in thread* Re: [PATCH] pinctrl: Cleanup string initializations (char[] instead of char *)
2014-05-17 14:37 [PATCH] pinctrl: Cleanup string initializations (char[] instead of char *) Manuel Schölling
2014-05-17 21:24 ` Thierry Reding
@ 2014-05-22 21:57 ` Linus Walleij
1 sibling, 0 replies; 3+ messages in thread
From: Linus Walleij @ 2014-05-22 21:57 UTC (permalink / raw)
To: Manuel Schölling
Cc: Stephen Warren, Thierry Reding, linux-kernel@vger.kernel.org,
linux-tegra@vger.kernel.org
On Sat, May 17, 2014 at 4:37 PM, Manuel Schölling
<manuel.schoelling@gmx.de> wrote:
> Initializations like 'char *foo = "bar"' will create two variables: a static
> string and a pointer (foo) to that static string. Instead 'char foo[] = "bar"'
> will declare a single variable and will end up in shorter
> assembly (according to Jeff Garzik on the KernelJanitor's TODO list).
>
> Signed-off-by: Manuel Schölling <manuel.schoelling@gmx.de>
At this point of the release cycle I do not dare to apply this.
Please work in Thierry's errors and resend after the merge window.
Yours,
Linus Walleij
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2014-05-22 21:57 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-05-17 14:37 [PATCH] pinctrl: Cleanup string initializations (char[] instead of char *) Manuel Schölling
2014-05-17 21:24 ` Thierry Reding
2014-05-22 21:57 ` Linus Walleij
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox