linux-arm-kernel.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 12/33] clk: bcm2835: use match_string() helper
       [not found] <1526903890-35761-1-git-send-email-xieyisheng1@huawei.com>
@ 2018-05-21 11:57 ` Yisheng Xie
  2018-05-21 17:48   ` Eric Anholt
  2018-05-21 21:50   ` Andy Shevchenko
  2018-05-21 11:57 ` [PATCH 13/33] clk: rockchip: " Yisheng Xie
  2018-05-21 11:57 ` [PATCH 17/33] pinctrl: armada-37xx: " Yisheng Xie
  2 siblings, 2 replies; 8+ messages in thread
From: Yisheng Xie @ 2018-05-21 11:57 UTC (permalink / raw)
  To: linux-arm-kernel

match_string() returns the index of an array for a matching string,
which can be used intead of open coded variant.

Cc: Michael Turquette <mturquette@baylibre.com>
Cc: Stephen Boyd <sboyd@kernel.org>
Cc: Eric Anholt <eric@anholt.net>
Cc: Stefan Wahren <stefan.wahren@i2se.com>
Cc: linux-clk at vger.kernel.org
Cc: linux-rpi-kernel at lists.infradead.org
Cc: linux-arm-kernel at lists.infradead.org
Signed-off-by: Yisheng Xie <xieyisheng1@huawei.com>
---
 drivers/clk/bcm/clk-bcm2835.c | 14 ++++++--------
 1 file changed, 6 insertions(+), 8 deletions(-)

diff --git a/drivers/clk/bcm/clk-bcm2835.c b/drivers/clk/bcm/clk-bcm2835.c
index fa0d5c8..a27c0d2 100644
--- a/drivers/clk/bcm/clk-bcm2835.c
+++ b/drivers/clk/bcm/clk-bcm2835.c
@@ -1395,8 +1395,7 @@ static struct clk_hw *bcm2835_register_clock(struct bcm2835_cprman *cprman,
 	struct bcm2835_clock *clock;
 	struct clk_init_data init;
 	const char *parents[1 << CM_SRC_BITS];
-	size_t i, j;
-	int ret;
+	int i, ret;
 
 	/*
 	 * Replace our strings referencing parent clocks with the
@@ -1405,12 +1404,11 @@ static struct clk_hw *bcm2835_register_clock(struct bcm2835_cprman *cprman,
 	for (i = 0; i < data->num_mux_parents; i++) {
 		parents[i] = data->parents[i];
 
-		for (j = 0; j < ARRAY_SIZE(cprman_parent_names); j++) {
-			if (strcmp(parents[i], cprman_parent_names[j]) == 0) {
-				parents[i] = cprman->real_parent_names[j];
-				break;
-			}
-		}
+		ret = match_string(cprman_parent_names,
+				   ARRAY_SIZE(cprman_parent_names),
+				   parents[i]);
+		if (ret >= 0)
+			parents[i] = cprman->real_parent_names[ret];
 	}
 
 	memset(&init, 0, sizeof(init));
-- 
1.7.12.4

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

* [PATCH 13/33] clk: rockchip: use match_string() helper
       [not found] <1526903890-35761-1-git-send-email-xieyisheng1@huawei.com>
  2018-05-21 11:57 ` [PATCH 12/33] clk: bcm2835: use match_string() helper Yisheng Xie
@ 2018-05-21 11:57 ` Yisheng Xie
  2018-05-22 13:56   ` Heiko Stuebner
  2018-05-21 11:57 ` [PATCH 17/33] pinctrl: armada-37xx: " Yisheng Xie
  2 siblings, 1 reply; 8+ messages in thread
From: Yisheng Xie @ 2018-05-21 11:57 UTC (permalink / raw)
  To: linux-arm-kernel

match_string() returns the index of an array for a matching string,
which can be used intead of open coded variant.

Cc: Michael Turquette <mturquette@baylibre.com>
Cc: Stephen Boyd <sboyd@kernel.org>
Cc: Heiko Stuebner <heiko@sntech.de>
Cc: linux-clk at vger.kernel.org
Cc: linux-arm-kernel at lists.infradead.org
Cc: linux-rockchip at lists.infradead.org
Signed-off-by: Yisheng Xie <xieyisheng1@huawei.com>
---
 drivers/clk/rockchip/clk.c | 16 +++++-----------
 1 file changed, 5 insertions(+), 11 deletions(-)

diff --git a/drivers/clk/rockchip/clk.c b/drivers/clk/rockchip/clk.c
index 3cd8ad5..514032d 100644
--- a/drivers/clk/rockchip/clk.c
+++ b/drivers/clk/rockchip/clk.c
@@ -274,18 +274,10 @@ static struct clk *rockchip_clk_register_frac_branch(
 		struct clk_mux *frac_mux = &frac->mux;
 		struct clk_init_data init;
 		struct clk *mux_clk;
-		int i, ret;
-
-		frac->mux_frac_idx = -1;
-		for (i = 0; i < child->num_parents; i++) {
-			if (!strcmp(name, child->parent_names[i])) {
-				pr_debug("%s: found fractional parent in mux at pos %d\n",
-					 __func__, i);
-				frac->mux_frac_idx = i;
-				break;
-			}
-		}
+		int ret;
 
+		frac->mux_frac_idx = match_string(child->parent_names,
+						  child->num_parents, name);
 		frac->mux_ops = &clk_mux_ops;
 		frac->clk_nb.notifier_call = rockchip_clk_frac_notifier_cb;
 
@@ -312,6 +304,8 @@ static struct clk *rockchip_clk_register_frac_branch(
 
 		/* notifier on the fraction divider to catch rate changes */
 		if (frac->mux_frac_idx >= 0) {
+			pr_debug("%s: find fractional parent in mux at pos %d\n",
+				 __func__, frac->mux_frac_idx);
 			ret = clk_notifier_register(clk, &frac->clk_nb);
 			if (ret)
 				pr_err("%s: failed to register clock notifier for %s\n",
-- 
1.7.12.4

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

* [PATCH 17/33] pinctrl: armada-37xx: use match_string() helper
       [not found] <1526903890-35761-1-git-send-email-xieyisheng1@huawei.com>
  2018-05-21 11:57 ` [PATCH 12/33] clk: bcm2835: use match_string() helper Yisheng Xie
  2018-05-21 11:57 ` [PATCH 13/33] clk: rockchip: " Yisheng Xie
@ 2018-05-21 11:57 ` Yisheng Xie
  2018-05-21 21:55   ` Andy Shevchenko
  2 siblings, 1 reply; 8+ messages in thread
From: Yisheng Xie @ 2018-05-21 11:57 UTC (permalink / raw)
  To: linux-arm-kernel

match_string() returns the index of an array for a matching string,
which can be used intead of open coded variant.

Cc: Jason Cooper <jason@lakedaemon.net>
Cc: Andrew Lunn <andrew@lunn.ch>
Cc: Gregory Clement <gregory.clement@bootlin.com>
Cc: Sebastian Hesselbarth <sebastian.hesselbarth@gmail.com>
Cc: Linus Walleij <linus.walleij@linaro.org>
Cc: linux-arm-kernel at lists.infradead.org
Cc: linux-gpio at vger.kernel.org
Signed-off-by: Yisheng Xie <xieyisheng1@huawei.com>
---
 drivers/pinctrl/mvebu/pinctrl-armada-37xx.c | 16 ++--------------
 1 file changed, 2 insertions(+), 14 deletions(-)

diff --git a/drivers/pinctrl/mvebu/pinctrl-armada-37xx.c b/drivers/pinctrl/mvebu/pinctrl-armada-37xx.c
index 5b63248..e338327 100644
--- a/drivers/pinctrl/mvebu/pinctrl-armada-37xx.c
+++ b/drivers/pinctrl/mvebu/pinctrl-armada-37xx.c
@@ -214,18 +214,6 @@ static inline void armada_37xx_update_reg(unsigned int *reg,
 	}
 }
 
-static int armada_37xx_get_func_reg(struct armada_37xx_pin_group *grp,
-				    const char *func)
-{
-	int f;
-
-	for (f = 0; (f < NB_FUNCS) && grp->funcs[f]; f++)
-		if (!strcmp(grp->funcs[f], func))
-			return f;
-
-	return -ENOTSUPP;
-}
-
 static struct armada_37xx_pin_group *armada_37xx_find_next_grp_by_pin(
 	struct armada_37xx_pinctrl *info, int pin, int *grp)
 {
@@ -344,10 +332,10 @@ static int armada_37xx_pmx_set_by_name(struct pinctrl_dev *pctldev,
 	dev_dbg(info->dev, "enable function %s group %s\n",
 		name, grp->name);
 
-	func = armada_37xx_get_func_reg(grp, name);
+	func = match_string(grp->funcs, NB_FUNCS, name);
 
 	if (func < 0)
-		return func;
+		return -ENOTSUPP;
 
 	val = grp->val[func];
 
-- 
1.7.12.4

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

* [PATCH 12/33] clk: bcm2835: use match_string() helper
  2018-05-21 11:57 ` [PATCH 12/33] clk: bcm2835: use match_string() helper Yisheng Xie
@ 2018-05-21 17:48   ` Eric Anholt
  2018-05-21 21:50   ` Andy Shevchenko
  1 sibling, 0 replies; 8+ messages in thread
From: Eric Anholt @ 2018-05-21 17:48 UTC (permalink / raw)
  To: linux-arm-kernel

Yisheng Xie <xieyisheng1@huawei.com> writes:

> match_string() returns the index of an array for a matching string,
> which can be used intead of open coded variant.
>
> Cc: Michael Turquette <mturquette@baylibre.com>
> Cc: Stephen Boyd <sboyd@kernel.org>
> Cc: Eric Anholt <eric@anholt.net>
> Cc: Stefan Wahren <stefan.wahren@i2se.com>
> Cc: linux-clk at vger.kernel.org
> Cc: linux-rpi-kernel at lists.infradead.org
> Cc: linux-arm-kernel at lists.infradead.org
> Signed-off-by: Yisheng Xie <xieyisheng1@huawei.com>
> ---
>  drivers/clk/bcm/clk-bcm2835.c | 14 ++++++--------
>  1 file changed, 6 insertions(+), 8 deletions(-)
>
> diff --git a/drivers/clk/bcm/clk-bcm2835.c b/drivers/clk/bcm/clk-bcm2835.c
> index fa0d5c8..a27c0d2 100644
> --- a/drivers/clk/bcm/clk-bcm2835.c
> +++ b/drivers/clk/bcm/clk-bcm2835.c
> @@ -1395,8 +1395,7 @@ static struct clk_hw *bcm2835_register_clock(struct bcm2835_cprman *cprman,
>  	struct bcm2835_clock *clock;
>  	struct clk_init_data init;
>  	const char *parents[1 << CM_SRC_BITS];
> -	size_t i, j;
> -	int ret;
> +	int i, ret;
>  
>  	/*
>  	 * Replace our strings referencing parent clocks with the
> @@ -1405,12 +1404,11 @@ static struct clk_hw *bcm2835_register_clock(struct bcm2835_cprman *cprman,
>  	for (i = 0; i < data->num_mux_parents; i++) {
>  		parents[i] = data->parents[i];
>  
> -		for (j = 0; j < ARRAY_SIZE(cprman_parent_names); j++) {
> -			if (strcmp(parents[i], cprman_parent_names[j]) == 0) {
> -				parents[i] = cprman->real_parent_names[j];
> -				break;
> -			}
> -		}
> +		ret = match_string(cprman_parent_names,
> +				   ARRAY_SIZE(cprman_parent_names),
> +				   parents[i]);
> +		if (ret >= 0)
> +			parents[i] = cprman->real_parent_names[ret];

Reviewed-by: Eric Anholt <eric@anholt.net>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 832 bytes
Desc: not available
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20180521/d011e272/attachment.sig>

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

* [PATCH 12/33] clk: bcm2835: use match_string() helper
  2018-05-21 11:57 ` [PATCH 12/33] clk: bcm2835: use match_string() helper Yisheng Xie
  2018-05-21 17:48   ` Eric Anholt
@ 2018-05-21 21:50   ` Andy Shevchenko
  2018-05-22  3:42     ` Yisheng Xie
  1 sibling, 1 reply; 8+ messages in thread
From: Andy Shevchenko @ 2018-05-21 21:50 UTC (permalink / raw)
  To: linux-arm-kernel

On Mon, May 21, 2018 at 2:57 PM, Yisheng Xie <xieyisheng1@huawei.com> wrote:
> match_string() returns the index of an array for a matching string,
> which can be used intead of open coded variant.
>
> Cc: Michael Turquette <mturquette@baylibre.com>
> Cc: Stephen Boyd <sboyd@kernel.org>
> Cc: Eric Anholt <eric@anholt.net>
> Cc: Stefan Wahren <stefan.wahren@i2se.com>
> Cc: linux-clk at vger.kernel.org
> Cc: linux-rpi-kernel at lists.infradead.org
> Cc: linux-arm-kernel at lists.infradead.org
> Signed-off-by: Yisheng Xie <xieyisheng1@huawei.com>

> -       size_t i, j;
> -       int ret;
> +       int i, ret;

I do not see any need to change type for i.

> +               ret = match_string(cprman_parent_names,
> +                                  ARRAY_SIZE(cprman_parent_names),
> +                                  parents[i]);
> +               if (ret >= 0)
> +                       parents[i] = cprman->real_parent_names[ret];


-- 
With Best Regards,
Andy Shevchenko

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

* [PATCH 17/33] pinctrl: armada-37xx: use match_string() helper
  2018-05-21 11:57 ` [PATCH 17/33] pinctrl: armada-37xx: " Yisheng Xie
@ 2018-05-21 21:55   ` Andy Shevchenko
  0 siblings, 0 replies; 8+ messages in thread
From: Andy Shevchenko @ 2018-05-21 21:55 UTC (permalink / raw)
  To: linux-arm-kernel

On Mon, May 21, 2018 at 2:57 PM, Yisheng Xie <xieyisheng1@huawei.com> wrote:
> match_string() returns the index of an array for a matching string,
> which can be used intead of open coded variant.

https://patchwork.kernel.org/patch/10378781/

> Cc: Jason Cooper <jason@lakedaemon.net>
> Cc: Andrew Lunn <andrew@lunn.ch>
> Cc: Gregory Clement <gregory.clement@bootlin.com>
> Cc: Sebastian Hesselbarth <sebastian.hesselbarth@gmail.com>
> Cc: Linus Walleij <linus.walleij@linaro.org>
> Cc: linux-arm-kernel at lists.infradead.org
> Cc: linux-gpio at vger.kernel.org

-- 
With Best Regards,
Andy Shevchenko

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

* [PATCH 12/33] clk: bcm2835: use match_string() helper
  2018-05-21 21:50   ` Andy Shevchenko
@ 2018-05-22  3:42     ` Yisheng Xie
  0 siblings, 0 replies; 8+ messages in thread
From: Yisheng Xie @ 2018-05-22  3:42 UTC (permalink / raw)
  To: linux-arm-kernel

Hi Andy,

On 2018/5/22 5:50, Andy Shevchenko wrote:
> On Mon, May 21, 2018 at 2:57 PM, Yisheng Xie <xieyisheng1@huawei.com> wrote:
>> match_string() returns the index of an array for a matching string,
>> which can be used intead of open coded variant.
>>
>> Cc: Michael Turquette <mturquette@baylibre.com>
>> Cc: Stephen Boyd <sboyd@kernel.org>
>> Cc: Eric Anholt <eric@anholt.net>
>> Cc: Stefan Wahren <stefan.wahren@i2se.com>
>> Cc: linux-clk at vger.kernel.org
>> Cc: linux-rpi-kernel at lists.infradead.org
>> Cc: linux-arm-kernel at lists.infradead.org
>> Signed-off-by: Yisheng Xie <xieyisheng1@huawei.com>
> 
>> -       size_t i, j;
>> -       int ret;
>> +       int i, ret;
> 
> I do not see any need to change type for i.

Right, I just want to smaller the line of code, for unsinged int is also OK for i.
Anyway, I can change it as your suggestion in next version.

Thanks
Yisheng

> 
>> +               ret = match_string(cprman_parent_names,
>> +                                  ARRAY_SIZE(cprman_parent_names),
>> +                                  parents[i]);
>> +               if (ret >= 0)
>> +                       parents[i] = cprman->real_parent_names[ret];
> 
> 

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

* [PATCH 13/33] clk: rockchip: use match_string() helper
  2018-05-21 11:57 ` [PATCH 13/33] clk: rockchip: " Yisheng Xie
@ 2018-05-22 13:56   ` Heiko Stuebner
  0 siblings, 0 replies; 8+ messages in thread
From: Heiko Stuebner @ 2018-05-22 13:56 UTC (permalink / raw)
  To: linux-arm-kernel

Am Montag, 21. Mai 2018, 13:57:50 CEST schrieb Yisheng Xie:
> match_string() returns the index of an array for a matching string,
> which can be used intead of open coded variant.
> 
> Cc: Michael Turquette <mturquette@baylibre.com>
> Cc: Stephen Boyd <sboyd@kernel.org>
> Cc: Heiko Stuebner <heiko@sntech.de>
> Cc: linux-clk at vger.kernel.org
> Cc: linux-arm-kernel at lists.infradead.org
> Cc: linux-rockchip at lists.infradead.org
> Signed-off-by: Yisheng Xie <xieyisheng1@huawei.com>

> @@ -312,6 +304,8 @@ static struct clk *rockchip_clk_register_frac_branch(
>  
>  		/* notifier on the fraction divider to catch rate changes */
>  		if (frac->mux_frac_idx >= 0) {
> +			pr_debug("%s: find fractional parent in mux at pos %d\n",
> +				 __func__, frac->mux_frac_idx);

applied to my Rockchip clk branch for 4.18 after changing the "find" above
to "found" again ;-) .


Thanks for the nice cleanup
Heiko

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

end of thread, other threads:[~2018-05-22 13:56 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <1526903890-35761-1-git-send-email-xieyisheng1@huawei.com>
2018-05-21 11:57 ` [PATCH 12/33] clk: bcm2835: use match_string() helper Yisheng Xie
2018-05-21 17:48   ` Eric Anholt
2018-05-21 21:50   ` Andy Shevchenko
2018-05-22  3:42     ` Yisheng Xie
2018-05-21 11:57 ` [PATCH 13/33] clk: rockchip: " Yisheng Xie
2018-05-22 13:56   ` Heiko Stuebner
2018-05-21 11:57 ` [PATCH 17/33] pinctrl: armada-37xx: " Yisheng Xie
2018-05-21 21:55   ` Andy Shevchenko

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).