diff mbox series

[net-next,v3,1/3] string_helpers: Move string_is_valid() to the header

Message ID 20230208133153.22528-1-andriy.shevchenko@linux.intel.com (mailing list archive)
State Accepted
Commit f1db99c07b4f0a9edc45f3498d4d13d13a41836a
Delegated to: Netdev Maintainers
Headers show
Series [net-next,v3,1/3] string_helpers: Move string_is_valid() to the header | expand

Checks

Context Check Description
netdev/tree_selection success Clearly marked for net-next, async
netdev/fixes_present success Fixes tag not required for -next series
netdev/subject_prefix success Link
netdev/cover_letter warning Series does not have a cover letter
netdev/patch_count success Link
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 15358 this patch: 15358
netdev/cc_maintainers warning 4 maintainers not CCed: cezary.rojewski@intel.com ddrokosov@sberdevices.ru Jonathan.Cameron@huawei.com broonie@kernel.org
netdev/build_clang success Errors and warnings before: 3463 this patch: 3463
netdev/module_param success Was 0 now: 0
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/check_selftest success No net selftest shell script
netdev/verify_fixes success No Fixes tag
netdev/build_allmodconfig_warn success Errors and warnings before: 16212 this patch: 16212
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 69 lines checked
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 1 now: 0

Commit Message

Andy Shevchenko Feb. 8, 2023, 1:31 p.m. UTC
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(-)

Comments

Jiri Pirko Feb. 8, 2023, 2:43 p.m. UTC | #1
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>
Andy Shevchenko Feb. 8, 2023, 2:47 p.m. UTC | #2
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!
patchwork-bot+netdevbpf@kernel.org Feb. 10, 2023, 6:50 a.m. UTC | #3
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!
diff mbox series

Patch

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