All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v1] rdmacg: Convert to use match_string() helper
@ 2018-05-03 17:49 Andy Shevchenko
  2018-05-03 22:56 ` kbuild test robot
  0 siblings, 1 reply; 2+ messages in thread
From: Andy Shevchenko @ 2018-05-03 17:49 UTC (permalink / raw)
  To: linux-kernel, Parav Pandit, Tejun Heo; +Cc: Andy Shevchenko

The new helper returns index of the matching string in an array.
We are going to use it here.

Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
 kernel/cgroup/rdma.c | 33 +++++++++++++++------------------
 1 file changed, 15 insertions(+), 18 deletions(-)

diff --git a/kernel/cgroup/rdma.c b/kernel/cgroup/rdma.c
index defad3c5e7dc..29697d2d0e85 100644
--- a/kernel/cgroup/rdma.c
+++ b/kernel/cgroup/rdma.c
@@ -362,10 +362,9 @@ EXPORT_SYMBOL(rdmacg_unregister_device);
 static int parse_resource(char *c, int *intval)
 {
 	substring_t argstr;
-	const char **table = &rdmacg_resource_names[0];
 	char *name, *value = c;
 	size_t len;
-	int ret, i = 0;
+	int ret, i;
 
 	name = strsep(&value, "=");
 	if (!name || !value)
@@ -373,24 +372,22 @@ static int parse_resource(char *c, int *intval)
 
 	len = strlen(value);
 
-	for (i = 0; i < RDMACG_RESOURCE_MAX; i++) {
-		if (strcmp(table[i], name))
-			continue;
+	i = match_string(rdmacg_resource_names, RDMACG_RESOURCE_MAX, name);
+	if (i < 0)
+		return i;
 
-		argstr.from = value;
-		argstr.to = value + len;
+	argstr.from = value;
+	argstr.to = value + len;
 
-		ret = match_int(&argstr, intval);
-		if (ret >= 0) {
-			if (*intval < 0)
-				break;
-			return i;
-		}
-		if (strncmp(value, RDMACG_MAX_STR, len) == 0) {
-			*intval = S32_MAX;
-			return i;
-		}
-		break;
+	ret = match_int(&argstr, intval);
+	if (ret >= 0) {
+		if (*intval < 0)
+			break;
+		return i;
+	}
+	if (strncmp(value, RDMACG_MAX_STR, len) == 0) {
+		*intval = S32_MAX;
+		return i;
 	}
 	return -EINVAL;
 }
-- 
2.17.0

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

* Re: [PATCH v1] rdmacg: Convert to use match_string() helper
  2018-05-03 17:49 [PATCH v1] rdmacg: Convert to use match_string() helper Andy Shevchenko
@ 2018-05-03 22:56 ` kbuild test robot
  0 siblings, 0 replies; 2+ messages in thread
From: kbuild test robot @ 2018-05-03 22:56 UTC (permalink / raw)
  To: Andy Shevchenko
  Cc: kbuild-all, linux-kernel, Parav Pandit, Tejun Heo, Andy Shevchenko

[-- Attachment #1: Type: text/plain, Size: 3261 bytes --]

Hi Andy,

I love your patch! Yet something to improve:

[auto build test ERROR on cgroup/for-next]
[also build test ERROR on v4.17-rc3 next-20180503]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system]

url:    https://github.com/0day-ci/linux/commits/Andy-Shevchenko/rdmacg-Convert-to-use-match_string-helper/20180504-060313
base:   https://git.kernel.org/pub/scm/linux/kernel/git/tj/cgroup.git for-next
config: x86_64-randconfig-x010-201817 (attached as .config)
compiler: gcc-7 (Debian 7.3.0-16) 7.3.0
reproduce:
        # save the attached .config to linux build tree
        make ARCH=x86_64 

All errors (new ones prefixed by >>):

   kernel/cgroup/rdma.c: In function 'parse_resource':
>> kernel/cgroup/rdma.c:385:4: error: break statement not within loop or switch
       break;
       ^~~~~

vim +385 kernel/cgroup/rdma.c

39d3e758 Parav Pandit    2017-01-10  361  
39d3e758 Parav Pandit    2017-01-10  362  static int parse_resource(char *c, int *intval)
39d3e758 Parav Pandit    2017-01-10  363  {
39d3e758 Parav Pandit    2017-01-10  364  	substring_t argstr;
39d3e758 Parav Pandit    2017-01-10  365  	char *name, *value = c;
39d3e758 Parav Pandit    2017-01-10  366  	size_t len;
9022ddfd Andy Shevchenko 2018-05-03  367  	int ret, i;
39d3e758 Parav Pandit    2017-01-10  368  
39d3e758 Parav Pandit    2017-01-10  369  	name = strsep(&value, "=");
39d3e758 Parav Pandit    2017-01-10  370  	if (!name || !value)
39d3e758 Parav Pandit    2017-01-10  371  		return -EINVAL;
39d3e758 Parav Pandit    2017-01-10  372  
39d3e758 Parav Pandit    2017-01-10  373  	len = strlen(value);
39d3e758 Parav Pandit    2017-01-10  374  
9022ddfd Andy Shevchenko 2018-05-03  375  	i = match_string(rdmacg_resource_names, RDMACG_RESOURCE_MAX, name);
9022ddfd Andy Shevchenko 2018-05-03  376  	if (i < 0)
9022ddfd Andy Shevchenko 2018-05-03  377  		return i;
39d3e758 Parav Pandit    2017-01-10  378  
39d3e758 Parav Pandit    2017-01-10  379  	argstr.from = value;
39d3e758 Parav Pandit    2017-01-10  380  	argstr.to = value + len;
39d3e758 Parav Pandit    2017-01-10  381  
39d3e758 Parav Pandit    2017-01-10  382  	ret = match_int(&argstr, intval);
39d3e758 Parav Pandit    2017-01-10  383  	if (ret >= 0) {
39d3e758 Parav Pandit    2017-01-10  384  		if (*intval < 0)
39d3e758 Parav Pandit    2017-01-10 @385  			break;
39d3e758 Parav Pandit    2017-01-10  386  		return i;
39d3e758 Parav Pandit    2017-01-10  387  	}
39d3e758 Parav Pandit    2017-01-10  388  	if (strncmp(value, RDMACG_MAX_STR, len) == 0) {
39d3e758 Parav Pandit    2017-01-10  389  		*intval = S32_MAX;
39d3e758 Parav Pandit    2017-01-10  390  		return i;
39d3e758 Parav Pandit    2017-01-10  391  	}
39d3e758 Parav Pandit    2017-01-10  392  	return -EINVAL;
39d3e758 Parav Pandit    2017-01-10  393  }
39d3e758 Parav Pandit    2017-01-10  394  

:::::: The code at line 385 was first introduced by commit
:::::: 39d3e7584a686541a3295ff1624d341e669e1afc rdmacg: Added rdma cgroup controller

:::::: TO: Parav Pandit <pandit.parav@gmail.com>
:::::: CC: Tejun Heo <tj@kernel.org>

---
0-DAY kernel test infrastructure                Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all                   Intel Corporation

[-- Attachment #2: .config.gz --]
[-- Type: application/gzip, Size: 26040 bytes --]

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

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

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-05-03 17:49 [PATCH v1] rdmacg: Convert to use match_string() helper Andy Shevchenko
2018-05-03 22:56 ` kbuild test robot

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.