public inbox for netdev@vger.kernel.org
 help / color / mirror / Atom feed
* [patch net-next v2] devlink: add format requirement for devlink param names
@ 2019-10-18 17:09 Jiri Pirko
  2019-10-18 18:39 ` Jakub Kicinski
  2019-10-21  7:58 ` Jiri Pirko
  0 siblings, 2 replies; 3+ messages in thread
From: Jiri Pirko @ 2019-10-18 17:09 UTC (permalink / raw)
  To: netdev; +Cc: davem, jakub.kicinski, andrew, mlxsw

From: Jiri Pirko <jiri@mellanox.com>

Currently, the name format is not required by the code, however it is
required during patch review. All params added until now are in-lined
with the following format:
1) lowercase characters, digits and underscored are allowed
2) underscore is neither at the beginning nor at the end and
   there is no more than one in a row.

Add checker to the code to require this format from drivers and warn if
they don't follow.

Signed-off-by: Jiri Pirko <jiri@mellanox.com>
---
v1->v2:
- removed empty line after comment
- added check for empty string
- converted i and len to size_t and put on a single line
- s/valid_name/name_valid/ to be aligned with the rest
---
 net/core/devlink.c | 29 +++++++++++++++++++++++++++++
 1 file changed, 29 insertions(+)

diff --git a/net/core/devlink.c b/net/core/devlink.c
index 97e9a2246929..a7f240f03e1c 100644
--- a/net/core/devlink.c
+++ b/net/core/devlink.c
@@ -20,6 +20,7 @@
 #include <linux/workqueue.h>
 #include <linux/u64_stats_sync.h>
 #include <linux/timekeeping.h>
+#include <linux/ctype.h>
 #include <rdma/ib_verbs.h>
 #include <net/netlink.h>
 #include <net/genetlink.h>
@@ -7040,10 +7041,38 @@ void devlink_resource_occ_get_unregister(struct devlink *devlink,
 }
 EXPORT_SYMBOL_GPL(devlink_resource_occ_get_unregister);
 
+static bool devlink_param_name_valid(const char *name)
+{
+	size_t i, len = strlen(name);
+
+	if (!len)
+		return false;
+
+	/* Name can contain lowercase characters or digits.
+	 * Underscores are also allowed, but not at the beginning
+	 * or end of the name and not more than one in a row.
+	 */
+	for (i = 0; i < len; i++) {
+		if (islower(name[i]) || isdigit(name[i]))
+			continue;
+		if (name[i] != '_')
+			return false;
+		if (i == 0 || i + 1 == len)
+			return false;
+		if (name[i - 1] == '_')
+			return false;
+	}
+	return true;
+}
+
 static int devlink_param_verify(const struct devlink_param *param)
 {
 	if (!param || !param->name || !param->supported_cmodes)
 		return -EINVAL;
+
+	if (WARN_ON(!devlink_param_name_valid(param->name)))
+		return -EINVAL;
+
 	if (param->generic)
 		return devlink_param_generic_verify(param);
 	else
-- 
2.21.0


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

* Re: [patch net-next v2] devlink: add format requirement for devlink param names
  2019-10-18 17:09 [patch net-next v2] devlink: add format requirement for devlink param names Jiri Pirko
@ 2019-10-18 18:39 ` Jakub Kicinski
  2019-10-21  7:58 ` Jiri Pirko
  1 sibling, 0 replies; 3+ messages in thread
From: Jakub Kicinski @ 2019-10-18 18:39 UTC (permalink / raw)
  To: Jiri Pirko; +Cc: netdev, davem, andrew, mlxsw

On Fri, 18 Oct 2019 19:09:51 +0200, Jiri Pirko wrote:
> From: Jiri Pirko <jiri@mellanox.com>
> 
> Currently, the name format is not required by the code, however it is
> required during patch review. All params added until now are in-lined
> with the following format:
> 1) lowercase characters, digits and underscored are allowed
> 2) underscore is neither at the beginning nor at the end and
>    there is no more than one in a row.
> 
> Add checker to the code to require this format from drivers and warn if
> they don't follow.
> 
> Signed-off-by: Jiri Pirko <jiri@mellanox.com>

Reviewed-by: Jakub Kicinski <jakub.kicinski@netronome.com>

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

* Re: [patch net-next v2] devlink: add format requirement for devlink param names
  2019-10-18 17:09 [patch net-next v2] devlink: add format requirement for devlink param names Jiri Pirko
  2019-10-18 18:39 ` Jakub Kicinski
@ 2019-10-21  7:58 ` Jiri Pirko
  1 sibling, 0 replies; 3+ messages in thread
From: Jiri Pirko @ 2019-10-21  7:58 UTC (permalink / raw)
  To: netdev; +Cc: davem, jakub.kicinski, andrew, mlxsw

Fri, Oct 18, 2019 at 07:09:51PM CEST, jiri@resnulli.us wrote:
>From: Jiri Pirko <jiri@mellanox.com>
>
>Currently, the name format is not required by the code, however it is
>required during patch review. All params added until now are in-lined
>with the following format:
>1) lowercase characters, digits and underscored are allowed
>2) underscore is neither at the beginning nor at the end and
>   there is no more than one in a row.
>
>Add checker to the code to require this format from drivers and warn if
>they don't follow.
>
>Signed-off-by: Jiri Pirko <jiri@mellanox.com>
>---
>v1->v2:
>- removed empty line after comment
>- added check for empty string
>- converted i and len to size_t and put on a single line
>- s/valid_name/name_valid/ to be aligned with the rest

Will send v3 which would allow uppercase and will make it part of
patchset that would check more devlink strings.

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

end of thread, other threads:[~2019-10-21  7:58 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2019-10-18 17:09 [patch net-next v2] devlink: add format requirement for devlink param names Jiri Pirko
2019-10-18 18:39 ` Jakub Kicinski
2019-10-21  7:58 ` Jiri Pirko

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox