netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH net-next v3 1/3] string_helpers: Move string_is_valid() to the header
@ 2023-02-08 13:31 Andy Shevchenko
  2023-02-08 13:31 ` [PATCH net-next v3 2/3] genetlink: Use string_is_terminated() helper Andy Shevchenko
                   ` (3 more replies)
  0 siblings, 4 replies; 8+ messages in thread
From: Andy Shevchenko @ 2023-02-08 13:31 UTC (permalink / raw)
  To: Andy Shevchenko, Jakub Kicinski, Xin Long, linux-kernel, netdev,
	dev, tipc-discussion
  Cc: David S. Miller, Eric Dumazet, Paolo Abeni, Pravin B Shelar,
	Jon Maloy, Ying Xue, Simon Horman

Move string_is_valid() to the header for wider use.

While at it, rename to string_is_terminated() to be
precise about its semantics.

Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Reviewed-by: Simon Horman <simon.horman@corigine.com>
---
v3: renamed to string_is_terminated (Jakub)
v2: added tag and updated subject (Simon)
 include/linux/string_helpers.h |  5 +++++
 net/tipc/netlink_compat.c      | 16 ++++++----------
 2 files changed, 11 insertions(+), 10 deletions(-)

diff --git a/include/linux/string_helpers.h b/include/linux/string_helpers.h
index 8530c7328269..fae6beaaa217 100644
--- a/include/linux/string_helpers.h
+++ b/include/linux/string_helpers.h
@@ -11,6 +11,11 @@ struct device;
 struct file;
 struct task_struct;
 
+static inline bool string_is_terminated(const char *s, int len)
+{
+	return memchr(s, '\0', len) ? true : false;
+}
+
 /* Descriptions of the types of units to
  * print in */
 enum string_size_units {
diff --git a/net/tipc/netlink_compat.c b/net/tipc/netlink_compat.c
index dfea27a906f2..9b47c8409231 100644
--- a/net/tipc/netlink_compat.c
+++ b/net/tipc/netlink_compat.c
@@ -39,6 +39,7 @@
 #include "node.h"
 #include "net.h"
 #include <net/genetlink.h>
+#include <linux/string_helpers.h>
 #include <linux/tipc_config.h>
 
 /* The legacy API had an artificial message length limit called
@@ -173,11 +174,6 @@ static struct sk_buff *tipc_get_err_tlv(char *str)
 	return buf;
 }
 
-static inline bool string_is_valid(char *s, int len)
-{
-	return memchr(s, '\0', len) ? true : false;
-}
-
 static int __tipc_nl_compat_dumpit(struct tipc_nl_compat_cmd_dump *cmd,
 				   struct tipc_nl_compat_msg *msg,
 				   struct sk_buff *arg)
@@ -445,7 +441,7 @@ static int tipc_nl_compat_bearer_enable(struct tipc_nl_compat_cmd_doit *cmd,
 		return -EINVAL;
 
 	len = min_t(int, len, TIPC_MAX_BEARER_NAME);
-	if (!string_is_valid(b->name, len))
+	if (!string_is_terminated(b->name, len))
 		return -EINVAL;
 
 	if (nla_put_string(skb, TIPC_NLA_BEARER_NAME, b->name))
@@ -486,7 +482,7 @@ static int tipc_nl_compat_bearer_disable(struct tipc_nl_compat_cmd_doit *cmd,
 		return -EINVAL;
 
 	len = min_t(int, len, TIPC_MAX_BEARER_NAME);
-	if (!string_is_valid(name, len))
+	if (!string_is_terminated(name, len))
 		return -EINVAL;
 
 	if (nla_put_string(skb, TIPC_NLA_BEARER_NAME, name))
@@ -584,7 +580,7 @@ static int tipc_nl_compat_link_stat_dump(struct tipc_nl_compat_msg *msg,
 		return -EINVAL;
 
 	len = min_t(int, len, TIPC_MAX_LINK_NAME);
-	if (!string_is_valid(name, len))
+	if (!string_is_terminated(name, len))
 		return -EINVAL;
 
 	if (strcmp(name, nla_data(link[TIPC_NLA_LINK_NAME])) != 0)
@@ -819,7 +815,7 @@ static int tipc_nl_compat_link_set(struct tipc_nl_compat_cmd_doit *cmd,
 		return -EINVAL;
 
 	len = min_t(int, len, TIPC_MAX_LINK_NAME);
-	if (!string_is_valid(lc->name, len))
+	if (!string_is_terminated(lc->name, len))
 		return -EINVAL;
 
 	media = tipc_media_find(lc->name);
@@ -856,7 +852,7 @@ static int tipc_nl_compat_link_reset_stats(struct tipc_nl_compat_cmd_doit *cmd,
 		return -EINVAL;
 
 	len = min_t(int, len, TIPC_MAX_LINK_NAME);
-	if (!string_is_valid(name, len))
+	if (!string_is_terminated(name, len))
 		return -EINVAL;
 
 	if (nla_put_string(skb, TIPC_NLA_LINK_NAME, name))
-- 
2.39.1


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

* [PATCH net-next v3 2/3] genetlink: Use string_is_terminated() helper
  2023-02-08 13:31 [PATCH net-next v3 1/3] string_helpers: Move string_is_valid() to the header Andy Shevchenko
@ 2023-02-08 13:31 ` Andy Shevchenko
  2023-02-08 14:44   ` Jiri Pirko
  2023-02-08 13:31 ` [PATCH net-next v3 3/3] openvswitch: " Andy Shevchenko
                   ` (2 subsequent siblings)
  3 siblings, 1 reply; 8+ messages in thread
From: Andy Shevchenko @ 2023-02-08 13:31 UTC (permalink / raw)
  To: Andy Shevchenko, Jakub Kicinski, Xin Long, linux-kernel, netdev,
	dev, tipc-discussion
  Cc: David S. Miller, Eric Dumazet, Paolo Abeni, Pravin B Shelar,
	Jon Maloy, Ying Xue, Simon Horman

Use string_is_terminated() helper instead of cpecific memchr() call.
This shows better the intention of the call.

Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Reviewed-by: Simon Horman <simon.horman@corigine.com>
---
v3: renamed to string_is_terminated (Jakub)
v2: added tag and updated subject (Simon)
 net/netlink/genetlink.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/net/netlink/genetlink.c b/net/netlink/genetlink.c
index 600993c80050..04c4036bf406 100644
--- a/net/netlink/genetlink.c
+++ b/net/netlink/genetlink.c
@@ -13,7 +13,7 @@
 #include <linux/errno.h>
 #include <linux/types.h>
 #include <linux/socket.h>
-#include <linux/string.h>
+#include <linux/string_helpers.h>
 #include <linux/skbuff.h>
 #include <linux/mutex.h>
 #include <linux/bitmap.h>
@@ -457,7 +457,7 @@ static int genl_validate_assign_mc_groups(struct genl_family *family)
 
 		if (WARN_ON(grp->name[0] == '\0'))
 			return -EINVAL;
-		if (WARN_ON(memchr(grp->name, '\0', GENL_NAMSIZ) == NULL))
+		if (WARN_ON(!string_is_terminated(grp->name, GENL_NAMSIZ)))
 			return -EINVAL;
 	}
 
-- 
2.39.1


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

* [PATCH net-next v3 3/3] openvswitch: Use string_is_terminated() helper
  2023-02-08 13:31 [PATCH net-next v3 1/3] string_helpers: Move string_is_valid() to the header Andy Shevchenko
  2023-02-08 13:31 ` [PATCH net-next v3 2/3] genetlink: Use string_is_terminated() helper Andy Shevchenko
@ 2023-02-08 13:31 ` Andy Shevchenko
  2023-02-08 14:44   ` Jiri Pirko
  2023-02-08 14:43 ` [PATCH net-next v3 1/3] string_helpers: Move string_is_valid() to the header Jiri Pirko
  2023-02-10  6:50 ` patchwork-bot+netdevbpf
  3 siblings, 1 reply; 8+ messages in thread
From: Andy Shevchenko @ 2023-02-08 13:31 UTC (permalink / raw)
  To: Andy Shevchenko, Jakub Kicinski, Xin Long, linux-kernel, netdev,
	dev, tipc-discussion
  Cc: David S. Miller, Eric Dumazet, Paolo Abeni, Pravin B Shelar,
	Jon Maloy, Ying Xue, Simon Horman

Use string_is_terminated() helper instead of cpecific memchr() call.
This shows better the intention of the call.

Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Reviewed-by: Simon Horman <simon.horman@corigine.com>
---
v3: renamed to string_is_terminated (Jakub)
v2: added tag and updated subject (Simon)
 net/openvswitch/conntrack.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/net/openvswitch/conntrack.c b/net/openvswitch/conntrack.c
index 2172930b1f17..f95272ebfa08 100644
--- a/net/openvswitch/conntrack.c
+++ b/net/openvswitch/conntrack.c
@@ -9,6 +9,7 @@
 #include <linux/udp.h>
 #include <linux/sctp.h>
 #include <linux/static_key.h>
+#include <linux/string_helpers.h>
 #include <net/ip.h>
 #include <net/genetlink.h>
 #include <net/netfilter/nf_conntrack_core.h>
@@ -1383,7 +1384,7 @@ static int parse_ct(const struct nlattr *attr, struct ovs_conntrack_info *info,
 #endif
 		case OVS_CT_ATTR_HELPER:
 			*helper = nla_data(a);
-			if (!memchr(*helper, '\0', nla_len(a))) {
+			if (!string_is_terminated(*helper, nla_len(a))) {
 				OVS_NLERR(log, "Invalid conntrack helper");
 				return -EINVAL;
 			}
@@ -1404,7 +1405,7 @@ static int parse_ct(const struct nlattr *attr, struct ovs_conntrack_info *info,
 #ifdef CONFIG_NF_CONNTRACK_TIMEOUT
 		case OVS_CT_ATTR_TIMEOUT:
 			memcpy(info->timeout, nla_data(a), nla_len(a));
-			if (!memchr(info->timeout, '\0', nla_len(a))) {
+			if (!string_is_terminated(info->timeout, nla_len(a))) {
 				OVS_NLERR(log, "Invalid conntrack timeout");
 				return -EINVAL;
 			}
-- 
2.39.1


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

* Re: [PATCH net-next v3 1/3] string_helpers: Move string_is_valid() to the header
  2023-02-08 13:31 [PATCH net-next v3 1/3] string_helpers: Move string_is_valid() to the header Andy Shevchenko
  2023-02-08 13:31 ` [PATCH net-next v3 2/3] genetlink: Use string_is_terminated() helper Andy Shevchenko
  2023-02-08 13:31 ` [PATCH net-next v3 3/3] openvswitch: " Andy Shevchenko
@ 2023-02-08 14:43 ` Jiri Pirko
  2023-02-08 14:47   ` Andy Shevchenko
  2023-02-10  6:50 ` patchwork-bot+netdevbpf
  3 siblings, 1 reply; 8+ messages in thread
From: Jiri Pirko @ 2023-02-08 14:43 UTC (permalink / raw)
  To: Andy Shevchenko
  Cc: Jakub Kicinski, Xin Long, linux-kernel, netdev, dev,
	tipc-discussion, David S. Miller, Eric Dumazet, Paolo Abeni,
	Pravin B Shelar, Jon Maloy, Ying Xue, Simon Horman

Wed, Feb 08, 2023 at 02:31:51PM CET, andriy.shevchenko@linux.intel.com wrote:
>Move string_is_valid() to the header for wider use.
>
>While at it, rename to string_is_terminated() to be
>precise about its semantics.

While at it, you could drop the ternary operator and return memchr()
directly.

With or without it:
Reviewed-by: Jiri Pirko <jiri@nvidia.com>

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

* Re: [PATCH net-next v3 2/3] genetlink: Use string_is_terminated() helper
  2023-02-08 13:31 ` [PATCH net-next v3 2/3] genetlink: Use string_is_terminated() helper Andy Shevchenko
@ 2023-02-08 14:44   ` Jiri Pirko
  0 siblings, 0 replies; 8+ messages in thread
From: Jiri Pirko @ 2023-02-08 14:44 UTC (permalink / raw)
  To: Andy Shevchenko
  Cc: Jakub Kicinski, Xin Long, linux-kernel, netdev, dev,
	tipc-discussion, David S. Miller, Eric Dumazet, Paolo Abeni,
	Pravin B Shelar, Jon Maloy, Ying Xue, Simon Horman

Wed, Feb 08, 2023 at 02:31:52PM CET, andriy.shevchenko@linux.intel.com wrote:
>Use string_is_terminated() helper instead of cpecific memchr() call.
>This shows better the intention of the call.
>
>Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
>Reviewed-by: Simon Horman <simon.horman@corigine.com>

Reviewed-by: Jiri Pirko <jiri@nvidia.com>

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

* Re: [PATCH net-next v3 3/3] openvswitch: Use string_is_terminated() helper
  2023-02-08 13:31 ` [PATCH net-next v3 3/3] openvswitch: " Andy Shevchenko
@ 2023-02-08 14:44   ` Jiri Pirko
  0 siblings, 0 replies; 8+ messages in thread
From: Jiri Pirko @ 2023-02-08 14:44 UTC (permalink / raw)
  To: Andy Shevchenko
  Cc: Jakub Kicinski, Xin Long, linux-kernel, netdev, dev,
	tipc-discussion, David S. Miller, Eric Dumazet, Paolo Abeni,
	Pravin B Shelar, Jon Maloy, Ying Xue, Simon Horman

Wed, Feb 08, 2023 at 02:31:53PM CET, andriy.shevchenko@linux.intel.com wrote:
>Use string_is_terminated() helper instead of cpecific memchr() call.
>This shows better the intention of the call.
>
>Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
>Reviewed-by: Simon Horman <simon.horman@corigine.com>

Reviewed-by: Jiri Pirko <jiri@nvidia.com>

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

* Re: [PATCH net-next v3 1/3] string_helpers: Move string_is_valid() to the header
  2023-02-08 14:43 ` [PATCH net-next v3 1/3] string_helpers: Move string_is_valid() to the header Jiri Pirko
@ 2023-02-08 14:47   ` Andy Shevchenko
  0 siblings, 0 replies; 8+ messages in thread
From: Andy Shevchenko @ 2023-02-08 14:47 UTC (permalink / raw)
  To: Jiri Pirko
  Cc: Jakub Kicinski, Xin Long, linux-kernel, netdev, dev,
	tipc-discussion, David S. Miller, Eric Dumazet, Paolo Abeni,
	Pravin B Shelar, Jon Maloy, Ying Xue, Simon Horman

On Wed, Feb 08, 2023 at 03:43:06PM +0100, Jiri Pirko wrote:
> Wed, Feb 08, 2023 at 02:31:51PM CET, andriy.shevchenko@linux.intel.com wrote:
> >Move string_is_valid() to the header for wider use.
> >
> >While at it, rename to string_is_terminated() to be
> >precise about its semantics.
> 
> While at it, you could drop the ternary operator and return memchr()
> directly.

Code generation will be the same, I won't modify too much the original,
the point of the change is just to have this helper to be available to
others.

> With or without it:
> Reviewed-by: Jiri Pirko <jiri@nvidia.com>

Thank you!

-- 
With Best Regards,
Andy Shevchenko



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

* Re: [PATCH net-next v3 1/3] string_helpers: Move string_is_valid() to the header
  2023-02-08 13:31 [PATCH net-next v3 1/3] string_helpers: Move string_is_valid() to the header Andy Shevchenko
                   ` (2 preceding siblings ...)
  2023-02-08 14:43 ` [PATCH net-next v3 1/3] string_helpers: Move string_is_valid() to the header Jiri Pirko
@ 2023-02-10  6:50 ` patchwork-bot+netdevbpf
  3 siblings, 0 replies; 8+ messages in thread
From: patchwork-bot+netdevbpf @ 2023-02-10  6:50 UTC (permalink / raw)
  To: Andy Shevchenko
  Cc: kuba, lucien.xin, linux-kernel, netdev, dev, tipc-discussion,
	davem, edumazet, pabeni, pshelar, jmaloy, ying.xue, simon.horman

Hello:

This series was applied to netdev/net-next.git (master)
by Jakub Kicinski <kuba@kernel.org>:

On Wed,  8 Feb 2023 15:31:51 +0200 you wrote:
> Move string_is_valid() to the header for wider use.
> 
> While at it, rename to string_is_terminated() to be
> precise about its semantics.
> 
> Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
> Reviewed-by: Simon Horman <simon.horman@corigine.com>
> 
> [...]

Here is the summary with links:
  - [net-next,v3,1/3] string_helpers: Move string_is_valid() to the header
    https://git.kernel.org/netdev/net-next/c/f1db99c07b4f
  - [net-next,v3,2/3] genetlink: Use string_is_terminated() helper
    https://git.kernel.org/netdev/net-next/c/d4545bf9c33b
  - [net-next,v3,3/3] openvswitch: Use string_is_terminated() helper
    https://git.kernel.org/netdev/net-next/c/5c72b4c644eb

You are awesome, thank you!
-- 
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html



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

end of thread, other threads:[~2023-02-10  6:50 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-02-08 13:31 [PATCH net-next v3 1/3] string_helpers: Move string_is_valid() to the header Andy Shevchenko
2023-02-08 13:31 ` [PATCH net-next v3 2/3] genetlink: Use string_is_terminated() helper Andy Shevchenko
2023-02-08 14:44   ` Jiri Pirko
2023-02-08 13:31 ` [PATCH net-next v3 3/3] openvswitch: " Andy Shevchenko
2023-02-08 14:44   ` Jiri Pirko
2023-02-08 14:43 ` [PATCH net-next v3 1/3] string_helpers: Move string_is_valid() to the header Jiri Pirko
2023-02-08 14:47   ` Andy Shevchenko
2023-02-10  6:50 ` patchwork-bot+netdevbpf

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