netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 05/33] cxgb4: 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 21:39   ` Andy Shevchenko
  2018-05-21 11:57 ` [PATCH 06/33] hp100: " Yisheng Xie
  2018-05-21 11:57 ` [PATCH 07/33] iwlwifi: mvm: " Yisheng Xie
  2 siblings, 1 reply; 9+ messages in thread
From: Yisheng Xie @ 2018-05-21 11:57 UTC (permalink / raw)
  To: linux-kernel; +Cc: Yisheng Xie, Ganesh Goudar, netdev

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

Cc: Ganesh Goudar <ganeshgr@chelsio.com>
Cc: netdev@vger.kernel.org
Signed-off-by: Yisheng Xie <xieyisheng1@huawei.com>
---
 drivers/net/ethernet/chelsio/cxgb4/cudbg_lib.c | 14 ++++----------
 1 file changed, 4 insertions(+), 10 deletions(-)

diff --git a/drivers/net/ethernet/chelsio/cxgb4/cudbg_lib.c b/drivers/net/ethernet/chelsio/cxgb4/cudbg_lib.c
index 9da6f57..bd61610 100644
--- a/drivers/net/ethernet/chelsio/cxgb4/cudbg_lib.c
+++ b/drivers/net/ethernet/chelsio/cxgb4/cudbg_lib.c
@@ -782,17 +782,11 @@ static int cudbg_get_mem_region(struct adapter *padap,
 	if (rc)
 		return rc;
 
-	for (i = 0; i < ARRAY_SIZE(cudbg_region); i++) {
-		if (!strcmp(cudbg_region[i], region_name)) {
-			found = 1;
-			idx = i;
-			break;
-		}
-	}
-	if (!found)
-		return -EINVAL;
+	rc = match_string(cudbg_region, ARRAY_SIZE(cudbg_region), region_name);
+	if (rc < 0)
+		return rc;
 
-	found = 0;
+	idx = rc;
 	for (i = 0; i < meminfo->mem_c; i++) {
 		if (meminfo->mem[i].idx >= ARRAY_SIZE(cudbg_region))
 			continue; /* Skip holes */
-- 
1.7.12.4

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

* [PATCH 06/33] hp100: use match_string() helper
       [not found] <1526903890-35761-1-git-send-email-xieyisheng1@huawei.com>
  2018-05-21 11:57 ` [PATCH 05/33] cxgb4: use match_string() helper Yisheng Xie
@ 2018-05-21 11:57 ` Yisheng Xie
  2018-05-21 11:57 ` [PATCH 07/33] iwlwifi: mvm: " Yisheng Xie
  2 siblings, 0 replies; 9+ messages in thread
From: Yisheng Xie @ 2018-05-21 11:57 UTC (permalink / raw)
  To: linux-kernel; +Cc: Yisheng Xie, Jaroslav Kysela, netdev

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

Cc: Jaroslav Kysela <perex@perex.cz>
Cc: netdev@vger.kernel.org
Signed-off-by: Yisheng Xie <xieyisheng1@huawei.com>
---
 drivers/net/ethernet/hp/hp100.c | 9 +--------
 1 file changed, 1 insertion(+), 8 deletions(-)

diff --git a/drivers/net/ethernet/hp/hp100.c b/drivers/net/ethernet/hp/hp100.c
index c8c7ad2..84501b3 100644
--- a/drivers/net/ethernet/hp/hp100.c
+++ b/drivers/net/ethernet/hp/hp100.c
@@ -335,7 +335,6 @@ static const char *hp100_read_id(int ioaddr)
 static __init int hp100_isa_probe1(struct net_device *dev, int ioaddr)
 {
 	const char *sig;
-	int i;
 
 	if (!request_region(ioaddr, HP100_REGION_SIZE, "hp100"))
 		goto err;
@@ -351,13 +350,7 @@ static __init int hp100_isa_probe1(struct net_device *dev, int ioaddr)
 	if (sig == NULL)
 		goto err;
 
-	for (i = 0; i < ARRAY_SIZE(hp100_isa_tbl); i++) {
-		if (!strcmp(hp100_isa_tbl[i], sig))
-			break;
-
-	}
-
-	if (i < ARRAY_SIZE(hp100_isa_tbl))
+	if (match_string(hp100_isa_tbl, ARRAY_SIZE(hp100_isa_tbl), sig) >= 0)
 		return hp100_probe1(dev, ioaddr, HP100_BUS_ISA, NULL);
  err:
 	return -ENODEV;
-- 
1.7.12.4

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

* [PATCH 07/33] iwlwifi: mvm: use match_string() helper
       [not found] <1526903890-35761-1-git-send-email-xieyisheng1@huawei.com>
  2018-05-21 11:57 ` [PATCH 05/33] cxgb4: use match_string() helper Yisheng Xie
  2018-05-21 11:57 ` [PATCH 06/33] hp100: " Yisheng Xie
@ 2018-05-21 11:57 ` Yisheng Xie
  2018-05-21 20:12   ` Luca Coelho
  2018-05-21 21:43   ` Andy Shevchenko
  2 siblings, 2 replies; 9+ messages in thread
From: Yisheng Xie @ 2018-05-21 11:57 UTC (permalink / raw)
  To: linux-kernel
  Cc: Yisheng Xie, Kalle Valo, Intel Linux Wireless, Johannes Berg,
	Emmanuel Grumbach, linux-wireless, netdev

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

Cc: Kalle Valo <kvalo@codeaurora.org>
Cc: Intel Linux Wireless <linuxwifi@intel.com>
Cc: Johannes Berg <johannes.berg@intel.com>
Cc: Emmanuel Grumbach <emmanuel.grumbach@intel.com>
Cc: linux-wireless@vger.kernel.org
Cc: netdev@vger.kernel.org
Signed-off-by: Yisheng Xie <xieyisheng1@huawei.com>
---
 drivers/net/wireless/intel/iwlwifi/mvm/debugfs.c | 11 +++--------
 1 file changed, 3 insertions(+), 8 deletions(-)

diff --git a/drivers/net/wireless/intel/iwlwifi/mvm/debugfs.c b/drivers/net/wireless/intel/iwlwifi/mvm/debugfs.c
index 0e6401c..e8249a6 100644
--- a/drivers/net/wireless/intel/iwlwifi/mvm/debugfs.c
+++ b/drivers/net/wireless/intel/iwlwifi/mvm/debugfs.c
@@ -671,14 +671,9 @@ static ssize_t iwl_dbgfs_bt_cmd_read(struct file *file, char __user *user_buf,
 	};
 	int ret, bt_force_ant_mode;
 
-	for (bt_force_ant_mode = 0;
-	     bt_force_ant_mode < ARRAY_SIZE(modes_str);
-	     bt_force_ant_mode++) {
-		if (!strcmp(buf, modes_str[bt_force_ant_mode]))
-			break;
-	}
-
-	if (bt_force_ant_mode >= ARRAY_SIZE(modes_str))
+	bt_force_ant_mode = match_string(modes_str,
+					 ARRAY_SIZE(modes_str), buf);
+	if (bt_force_ant_mode < 0)
 		return -EINVAL;
 
 	ret = 0;
-- 
1.7.12.4

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

* Re: [PATCH 07/33] iwlwifi: mvm: use match_string() helper
  2018-05-21 11:57 ` [PATCH 07/33] iwlwifi: mvm: " Yisheng Xie
@ 2018-05-21 20:12   ` Luca Coelho
  2018-05-21 21:43   ` Andy Shevchenko
  1 sibling, 0 replies; 9+ messages in thread
From: Luca Coelho @ 2018-05-21 20:12 UTC (permalink / raw)
  To: Yisheng Xie, linux-kernel
  Cc: Kalle Valo, Intel Linux Wireless, Johannes Berg,
	Emmanuel Grumbach, linux-wireless, netdev

On Mon, 2018-05-21 at 19:57 +0800, Yisheng Xie wrote:
> match_string() returns the index of an array for a matching string,
> which can be used intead of open coded variant.
> 
> Cc: Kalle Valo <kvalo@codeaurora.org>
> Cc: Intel Linux Wireless <linuxwifi@intel.com>
> Cc: Johannes Berg <johannes.berg@intel.com>
> Cc: Emmanuel Grumbach <emmanuel.grumbach@intel.com>
> Cc: linux-wireless@vger.kernel.org
> Cc: netdev@vger.kernel.org
> Signed-off-by: Yisheng Xie <xieyisheng1@huawei.com>
> ---
>  drivers/net/wireless/intel/iwlwifi/mvm/debugfs.c | 11 +++--------
>  1 file changed, 3 insertions(+), 8 deletions(-)
> 
> diff --git a/drivers/net/wireless/intel/iwlwifi/mvm/debugfs.c
> b/drivers/net/wireless/intel/iwlwifi/mvm/debugfs.c
> index 0e6401c..e8249a6 100644
> --- a/drivers/net/wireless/intel/iwlwifi/mvm/debugfs.c
> +++ b/drivers/net/wireless/intel/iwlwifi/mvm/debugfs.c
> @@ -671,14 +671,9 @@ static ssize_t iwl_dbgfs_bt_cmd_read(struct file
> *file, char __user *user_buf,
>  	};
>  	int ret, bt_force_ant_mode;
>  
> -	for (bt_force_ant_mode = 0;
> -	     bt_force_ant_mode < ARRAY_SIZE(modes_str);
> -	     bt_force_ant_mode++) {
> -		if (!strcmp(buf, modes_str[bt_force_ant_mode]))
> -			break;
> -	}
> -
> -	if (bt_force_ant_mode >= ARRAY_SIZE(modes_str))
> +	bt_force_ant_mode = match_string(modes_str,
> +					 ARRAY_SIZE(modes_str),
> buf);
> +	if (bt_force_ant_mode < 0)
>  		return -EINVAL;
>  
>  	ret = 0;

Looks fine, I'll push this to our internal tree for review and take a
closer look at what the match_string() function does exactly.

Thanks for the patch.

--
Cheers,
Luca.

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

* Re: [PATCH 05/33] cxgb4: use match_string() helper
  2018-05-21 11:57 ` [PATCH 05/33] cxgb4: use match_string() helper Yisheng Xie
@ 2018-05-21 21:39   ` Andy Shevchenko
  2018-05-22  0:55     ` Yisheng Xie
  0 siblings, 1 reply; 9+ messages in thread
From: Andy Shevchenko @ 2018-05-21 21:39 UTC (permalink / raw)
  To: Yisheng Xie; +Cc: Linux Kernel Mailing List, Ganesh Goudar, netdev

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.

> -       for (i = 0; i < ARRAY_SIZE(cudbg_region); i++) {
> -               if (!strcmp(cudbg_region[i], region_name)) {
> -                       found = 1;
> -                       idx = i;
> -                       break;
> -               }
> -       }
> -       if (!found)
> -               return -EINVAL;
> +       rc = match_string(cudbg_region, ARRAY_SIZE(cudbg_region), region_name);
> +       if (rc < 0)
> +               return rc;
>
> -       found = 0;
> +       idx = rc;

Is found still in use after this?
If so, is it initialized properly now?

-- 
With Best Regards,
Andy Shevchenko

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

* Re: [PATCH 07/33] iwlwifi: mvm: use match_string() helper
  2018-05-21 11:57 ` [PATCH 07/33] iwlwifi: mvm: " Yisheng Xie
  2018-05-21 20:12   ` Luca Coelho
@ 2018-05-21 21:43   ` Andy Shevchenko
  2018-05-22  3:30     ` Yisheng Xie
  1 sibling, 1 reply; 9+ messages in thread
From: Andy Shevchenko @ 2018-05-21 21:43 UTC (permalink / raw)
  To: Yisheng Xie
  Cc: Linux Kernel Mailing List, Kalle Valo, Intel Linux Wireless,
	Johannes Berg, Emmanuel Grumbach, open list:TI WILINK WIRELES...,
	netdev

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.

>         int ret, bt_force_ant_mode;
>
> -       for (bt_force_ant_mode = 0;
> -            bt_force_ant_mode < ARRAY_SIZE(modes_str);
> -            bt_force_ant_mode++) {
> -               if (!strcmp(buf, modes_str[bt_force_ant_mode]))
> -                       break;
> -       }
> -
> -       if (bt_force_ant_mode >= ARRAY_SIZE(modes_str))

> +       bt_force_ant_mode = match_string(modes_str,
> +                                        ARRAY_SIZE(modes_str), buf);

One line?

> +       if (bt_force_ant_mode < 0)
>                 return -EINVAL;

I would rather use

ret = match_string();
if (ret < 0)
 return ret;

bt_force_... = ret;

But it's up tu Loca.

>
>         ret = 0;



-- 
With Best Regards,
Andy Shevchenko

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

* Re: [PATCH 05/33] cxgb4: use match_string() helper
  2018-05-21 21:39   ` Andy Shevchenko
@ 2018-05-22  0:55     ` Yisheng Xie
  0 siblings, 0 replies; 9+ messages in thread
From: Yisheng Xie @ 2018-05-22  0:55 UTC (permalink / raw)
  To: Andy Shevchenko; +Cc: Linux Kernel Mailing List, Ganesh Goudar, netdev

Hi Andy,

On 2018/5/22 5:39, 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.
> 
>> -       for (i = 0; i < ARRAY_SIZE(cudbg_region); i++) {
>> -               if (!strcmp(cudbg_region[i], region_name)) {
>> -                       found = 1;
>> -                       idx = i;
>> -                       break;
>> -               }
>> -       }
>> -       if (!found)
>> -               return -EINVAL;
>> +       rc = match_string(cudbg_region, ARRAY_SIZE(cudbg_region), region_name);
>> +       if (rc < 0)
>> +               return rc;
>>
>> -       found = 0;
>> +       idx = rc;
> 
> Is found still in use after this?
> If so, is it initialized properly now?
it is initialized  when define 'found', so no need to be initialized once more.

Thanks
Yisheng

> 

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

* Re: [PATCH 07/33] iwlwifi: mvm: use match_string() helper
  2018-05-21 21:43   ` Andy Shevchenko
@ 2018-05-22  3:30     ` Yisheng Xie
  2018-05-22 20:41       ` Andy Shevchenko
  0 siblings, 1 reply; 9+ messages in thread
From: Yisheng Xie @ 2018-05-22  3:30 UTC (permalink / raw)
  To: Andy Shevchenko
  Cc: Linux Kernel Mailing List, Kalle Valo, Intel Linux Wireless,
	Johannes Berg, Emmanuel Grumbach, open list:TI WILINK WIRELES...,
	netdev

Hi Andy,

On 2018/5/22 5:43, 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.
> 
>>         int ret, bt_force_ant_mode;
>>
>> -       for (bt_force_ant_mode = 0;
>> -            bt_force_ant_mode < ARRAY_SIZE(modes_str);
>> -            bt_force_ant_mode++) {
>> -               if (!strcmp(buf, modes_str[bt_force_ant_mode]))
>> -                       break;
>> -       }
>> -
>> -       if (bt_force_ant_mode >= ARRAY_SIZE(modes_str))
> 
>> +       bt_force_ant_mode = match_string(modes_str,
>> +                                        ARRAY_SIZE(modes_str), buf);
> 
> One line?

hmm, if use ret instead it will no over 80 chars.

> 
>> +       if (bt_force_ant_mode < 0)
>>                 return -EINVAL;
> 
> I would rather use
> 
> ret = match_string();
> if (ret < 0)
>  return ret;
> 
> bt_force_... = ret;
> 
> But it's up tu Loca.

OK, I will change it if Loca agree your opinion.

Thanks
Yisheng
> 
>>
>>         ret = 0;
> 
> 
> 

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

* Re: [PATCH 07/33] iwlwifi: mvm: use match_string() helper
  2018-05-22  3:30     ` Yisheng Xie
@ 2018-05-22 20:41       ` Andy Shevchenko
  0 siblings, 0 replies; 9+ messages in thread
From: Andy Shevchenko @ 2018-05-22 20:41 UTC (permalink / raw)
  To: Yisheng Xie, Luca Coelho
  Cc: Linux Kernel Mailing List, Kalle Valo, Intel Linux Wireless,
	Johannes Berg, Emmanuel Grumbach, open list:TI WILINK WIRELES...,
	netdev

On Tue, May 22, 2018 at 6:30 AM, Yisheng Xie <xieyisheng1@huawei.com> wrote:

>> But it's up tu Loca.

Shame on me. I meant Luca, of course!
Luca, sorry.

> OK, I will change it if Loca agree your opinion.


-- 
With Best Regards,
Andy Shevchenko

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

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

Thread overview: 9+ 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 05/33] cxgb4: use match_string() helper Yisheng Xie
2018-05-21 21:39   ` Andy Shevchenko
2018-05-22  0:55     ` Yisheng Xie
2018-05-21 11:57 ` [PATCH 06/33] hp100: " Yisheng Xie
2018-05-21 11:57 ` [PATCH 07/33] iwlwifi: mvm: " Yisheng Xie
2018-05-21 20:12   ` Luca Coelho
2018-05-21 21:43   ` Andy Shevchenko
2018-05-22  3:30     ` Yisheng Xie
2018-05-22 20:41       ` 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).