All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Rafał Miłecki" <zajec5@gmail.com>
To: Linus Walleij <linus.walleij@linaro.org>
Cc: "Dong Aisheng" <aisheng.dong@nxp.com>,
	"Fabio Estevam" <festevam@gmail.com>,
	"Shawn Guo" <shawnguo@kernel.org>,
	"Stefan Agner" <stefan@agner.ch>,
	"Pengutronix Kernel Team" <kernel@pengutronix.de>,
	"Sascha Hauer" <s.hauer@pengutronix.de>,
	"NXP Linux Team" <linux-imx@nxp.com>,
	"Lakshmi Sowjanya D" <lakshmi.sowjanya.d@intel.com>,
	linux-gpio@vger.kernel.org, linux-arm-kernel@lists.infradead.org,
	"Rafał Miłecki" <rafal@milecki.pl>
Subject: [PATCH V2 3/4] pinctrl: keembay: rework loops looking for groups names
Date: Thu, 16 Dec 2021 17:22:05 +0100	[thread overview]
Message-ID: <20211216162206.8027-3-zajec5@gmail.com> (raw)
In-Reply-To: <20211216162206.8027-1-zajec5@gmail.com>

From: Rafał Miłecki <rafal@milecki.pl>

Make the outer loop iterate over functions as that's the real subject.
This simplifies code (and reduces amount of lines of code) as allocating
memory for names doesn't require extra checks anymore.

While at it use local "group_names" variable. The plan for
"struct function_desc" is to make its "group_names" /double/ const. That
will allow drivers to use it with static const data.

This keembay "group_names" change is required to avoid:
drivers/pinctrl/pinctrl-keembay.c: In function 'keembay_add_functions':
drivers/pinctrl/pinctrl-keembay.c:1594:8: warning: assignment discards 'const' qualifier from pointer target type [-Wdiscarded-qualifiers]
 1594 |    grp = func->group_names;
      |        ^

Signed-off-by: Rafał Miłecki <rafal@milecki.pl>
---
This has been runtime tested. I verified that output of
/sys/kernel/debug/pinctrl/*/pinmux-functions is the same without and
with my patches.
---
 drivers/pinctrl/pinctrl-keembay.c | 66 ++++++++++++-------------------
 1 file changed, 25 insertions(+), 41 deletions(-)

diff --git a/drivers/pinctrl/pinctrl-keembay.c b/drivers/pinctrl/pinctrl-keembay.c
index 9a602abad8df..152c35bce8ec 100644
--- a/drivers/pinctrl/pinctrl-keembay.c
+++ b/drivers/pinctrl/pinctrl-keembay.c
@@ -1555,58 +1555,42 @@ static int keembay_pinctrl_reg(struct keembay_pinctrl *kpc,  struct device *dev)
 }
 
 static int keembay_add_functions(struct keembay_pinctrl *kpc,
-				 struct function_desc *function)
+				 struct function_desc *functions)
 {
 	unsigned int i;
 
 	/* Assign the groups for each function */
-	for (i = 0; i < kpc->npins; i++) {
-		const struct pinctrl_pin_desc *pdesc = keembay_pins + i;
-		struct keembay_mux_desc *mux = pdesc->drv_data;
-
-		while (mux->name) {
-			struct function_desc *func;
-			const char **grp;
-			size_t grp_size;
-			u32 j, grp_num;
-
-			for (j = 0; j < kpc->nfuncs; j++) {
-				if (!strcmp(mux->name, function[j].name))
-					break;
-			}
-
-			if (j == kpc->nfuncs)
-				return -EINVAL;
-
-			func = function + j;
-			grp_num = func->num_group_names;
-			grp_size = sizeof(*func->group_names);
-
-			if (!func->group_names) {
-				func->group_names = devm_kcalloc(kpc->dev,
-								 grp_num,
-								 grp_size,
-								 GFP_KERNEL);
-				if (!func->group_names)
-					return -ENOMEM;
+	for (i = 0; i < kpc->nfuncs; i++) {
+		struct function_desc *func = &functions[i];
+		const char **group_names;
+		unsigned int grp_idx = 0;
+		int j;
+
+		group_names = devm_kcalloc(kpc->dev, func->num_group_names,
+					   sizeof(*group_names), GFP_KERNEL);
+		if (!group_names)
+			return -ENOMEM;
+
+		for (j = 0; j < kpc->npins; j++) {
+			const struct pinctrl_pin_desc *pdesc = &keembay_pins[j];
+			struct keembay_mux_desc *mux;
+
+			for (mux = pdesc->drv_data; mux->name; mux++) {
+				if (!strcmp(mux->name, func->name))
+					group_names[grp_idx++] = pdesc->name;
 			}
-
-			grp = func->group_names;
-			while (*grp)
-				grp++;
-
-			*grp = pdesc->name;
-			mux++;
 		}
+
+		func->group_names = group_names;
 	}
 
 	/* Add all functions */
 	for (i = 0; i < kpc->nfuncs; i++) {
 		pinmux_generic_add_function(kpc->pctrl,
-					    function[i].name,
-					    function[i].group_names,
-					    function[i].num_group_names,
-					    function[i].data);
+					    functions[i].name,
+					    functions[i].group_names,
+					    functions[i].num_group_names,
+					    functions[i].data);
 	}
 
 	return 0;
-- 
2.31.1


WARNING: multiple messages have this Message-ID (diff)
From: "Rafał Miłecki" <zajec5@gmail.com>
To: Linus Walleij <linus.walleij@linaro.org>
Cc: "Dong Aisheng" <aisheng.dong@nxp.com>,
	"Fabio Estevam" <festevam@gmail.com>,
	"Shawn Guo" <shawnguo@kernel.org>,
	"Stefan Agner" <stefan@agner.ch>,
	"Pengutronix Kernel Team" <kernel@pengutronix.de>,
	"Sascha Hauer" <s.hauer@pengutronix.de>,
	"NXP Linux Team" <linux-imx@nxp.com>,
	"Lakshmi Sowjanya D" <lakshmi.sowjanya.d@intel.com>,
	linux-gpio@vger.kernel.org, linux-arm-kernel@lists.infradead.org,
	"Rafał Miłecki" <rafal@milecki.pl>
Subject: [PATCH V2 3/4] pinctrl: keembay: rework loops looking for groups names
Date: Thu, 16 Dec 2021 17:22:05 +0100	[thread overview]
Message-ID: <20211216162206.8027-3-zajec5@gmail.com> (raw)
In-Reply-To: <20211216162206.8027-1-zajec5@gmail.com>

From: Rafał Miłecki <rafal@milecki.pl>

Make the outer loop iterate over functions as that's the real subject.
This simplifies code (and reduces amount of lines of code) as allocating
memory for names doesn't require extra checks anymore.

While at it use local "group_names" variable. The plan for
"struct function_desc" is to make its "group_names" /double/ const. That
will allow drivers to use it with static const data.

This keembay "group_names" change is required to avoid:
drivers/pinctrl/pinctrl-keembay.c: In function 'keembay_add_functions':
drivers/pinctrl/pinctrl-keembay.c:1594:8: warning: assignment discards 'const' qualifier from pointer target type [-Wdiscarded-qualifiers]
 1594 |    grp = func->group_names;
      |        ^

Signed-off-by: Rafał Miłecki <rafal@milecki.pl>
---
This has been runtime tested. I verified that output of
/sys/kernel/debug/pinctrl/*/pinmux-functions is the same without and
with my patches.
---
 drivers/pinctrl/pinctrl-keembay.c | 66 ++++++++++++-------------------
 1 file changed, 25 insertions(+), 41 deletions(-)

diff --git a/drivers/pinctrl/pinctrl-keembay.c b/drivers/pinctrl/pinctrl-keembay.c
index 9a602abad8df..152c35bce8ec 100644
--- a/drivers/pinctrl/pinctrl-keembay.c
+++ b/drivers/pinctrl/pinctrl-keembay.c
@@ -1555,58 +1555,42 @@ static int keembay_pinctrl_reg(struct keembay_pinctrl *kpc,  struct device *dev)
 }
 
 static int keembay_add_functions(struct keembay_pinctrl *kpc,
-				 struct function_desc *function)
+				 struct function_desc *functions)
 {
 	unsigned int i;
 
 	/* Assign the groups for each function */
-	for (i = 0; i < kpc->npins; i++) {
-		const struct pinctrl_pin_desc *pdesc = keembay_pins + i;
-		struct keembay_mux_desc *mux = pdesc->drv_data;
-
-		while (mux->name) {
-			struct function_desc *func;
-			const char **grp;
-			size_t grp_size;
-			u32 j, grp_num;
-
-			for (j = 0; j < kpc->nfuncs; j++) {
-				if (!strcmp(mux->name, function[j].name))
-					break;
-			}
-
-			if (j == kpc->nfuncs)
-				return -EINVAL;
-
-			func = function + j;
-			grp_num = func->num_group_names;
-			grp_size = sizeof(*func->group_names);
-
-			if (!func->group_names) {
-				func->group_names = devm_kcalloc(kpc->dev,
-								 grp_num,
-								 grp_size,
-								 GFP_KERNEL);
-				if (!func->group_names)
-					return -ENOMEM;
+	for (i = 0; i < kpc->nfuncs; i++) {
+		struct function_desc *func = &functions[i];
+		const char **group_names;
+		unsigned int grp_idx = 0;
+		int j;
+
+		group_names = devm_kcalloc(kpc->dev, func->num_group_names,
+					   sizeof(*group_names), GFP_KERNEL);
+		if (!group_names)
+			return -ENOMEM;
+
+		for (j = 0; j < kpc->npins; j++) {
+			const struct pinctrl_pin_desc *pdesc = &keembay_pins[j];
+			struct keembay_mux_desc *mux;
+
+			for (mux = pdesc->drv_data; mux->name; mux++) {
+				if (!strcmp(mux->name, func->name))
+					group_names[grp_idx++] = pdesc->name;
 			}
-
-			grp = func->group_names;
-			while (*grp)
-				grp++;
-
-			*grp = pdesc->name;
-			mux++;
 		}
+
+		func->group_names = group_names;
 	}
 
 	/* Add all functions */
 	for (i = 0; i < kpc->nfuncs; i++) {
 		pinmux_generic_add_function(kpc->pctrl,
-					    function[i].name,
-					    function[i].group_names,
-					    function[i].num_group_names,
-					    function[i].data);
+					    functions[i].name,
+					    functions[i].group_names,
+					    functions[i].num_group_names,
+					    functions[i].data);
 	}
 
 	return 0;
-- 
2.31.1


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

  parent reply	other threads:[~2021-12-16 16:22 UTC|newest]

Thread overview: 32+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-12-16 16:22 [PATCH V2 1/4] pinctrl: imx: prepare for making "group_names" in "function_desc" const Rafał Miłecki
2021-12-16 16:22 ` Rafał Miłecki
2021-12-16 16:22 ` [PATCH V2 2/4] pinctrl: keembay: comment process of building functions a bit Rafał Miłecki
2021-12-16 16:22   ` Rafał Miłecki
2021-12-16 16:22 ` Rafał Miłecki [this message]
2021-12-16 16:22   ` [PATCH V2 3/4] pinctrl: keembay: rework loops looking for groups names Rafał Miłecki
2021-12-16 16:22 ` [PATCH V2 4/4] pinctrl: add one more "const" for generic function groups Rafał Miłecki
2021-12-16 16:22   ` Rafał Miłecki
2022-01-11 15:34   ` Nathan Chancellor
2022-01-11 15:34     ` Nathan Chancellor
2022-01-11 16:51     ` Rafał Miłecki
2022-01-11 16:51       ` Rafał Miłecki
2022-01-16  0:51       ` Linus Walleij
2022-01-16  0:51         ` Linus Walleij
2022-01-18  7:02       ` Uwe Kleine-König
2022-01-18  7:02         ` Uwe Kleine-König
2022-01-18  7:21         ` Rafał Miłecki
2022-01-18  7:21           ` Rafał Miłecki
2022-01-18  7:31           ` Uwe Kleine-König
2022-01-18  7:31             ` Uwe Kleine-König
2021-12-17  9:39 ` [PATCH V2 1/4] pinctrl: imx: prepare for making "group_names" in "function_desc" const Andy Shevchenko
2021-12-17  9:39   ` Andy Shevchenko
2021-12-22  1:58 ` Linus Walleij
2021-12-22  1:58   ` Linus Walleij
2021-12-22 20:24 ` Abel Vesa
2021-12-22 20:24   ` Abel Vesa
2022-01-01 23:55   ` Marcel Ziswiler
2022-01-01 23:55     ` Marcel Ziswiler
2022-01-01 23:58     ` Rafał Miłecki
2022-01-01 23:58       ` Rafał Miłecki
2022-01-01 23:59       ` Marcel Ziswiler
2022-01-01 23:59         ` Marcel Ziswiler

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=20211216162206.8027-3-zajec5@gmail.com \
    --to=zajec5@gmail.com \
    --cc=aisheng.dong@nxp.com \
    --cc=festevam@gmail.com \
    --cc=kernel@pengutronix.de \
    --cc=lakshmi.sowjanya.d@intel.com \
    --cc=linus.walleij@linaro.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-gpio@vger.kernel.org \
    --cc=linux-imx@nxp.com \
    --cc=rafal@milecki.pl \
    --cc=s.hauer@pengutronix.de \
    --cc=shawnguo@kernel.org \
    --cc=stefan@agner.ch \
    /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.