From patchwork Wed Feb 8 13:31:51 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andy Shevchenko X-Patchwork-Id: 13133036 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 43194C636CC for ; Wed, 8 Feb 2023 13:31:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231144AbjBHNbg (ORCPT ); Wed, 8 Feb 2023 08:31:36 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35402 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230010AbjBHNba (ORCPT ); Wed, 8 Feb 2023 08:31:30 -0500 Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CB1F142DF9; Wed, 8 Feb 2023 05:31:23 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1675863083; x=1707399083; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=iRdp3KV5xmAJg0zcHWue1GbSneGTwjsPjdu/wNNtJlw=; b=QD16U+qI0sKd0YjgmPneiUn62GNFOBjJet5IgQndHdonwt4oWCla4NUL /oI9XeEF+UrXToeC/6kqg6+rG7lms/wB07bA5gQ307i5wFFVLrfG+bDYw keiXTBHgxZQyhttGYFlDxM0qSmtmYEqTB4dqk5x6rfzt7H9GZp5uagVSE t9tW05PfvpNTeeJSk29LBl+jiaODikCZ3gf0juMNmuXz73gi3uyfIZSrx P7pSahC4oTdNrIAAwyjdVHt7v9VsKcIMr2Gpew0BxVIo+WbeVDlbbNNk5 oq5J/mWmFVISOzJHaitvzuMzOMFWV8rTrz25DQJrcrUlP+1cWtN88il3z w==; X-IronPort-AV: E=McAfee;i="6500,9779,10615"; a="357188514" X-IronPort-AV: E=Sophos;i="5.97,280,1669104000"; d="scan'208";a="357188514" Received: from fmsmga007.fm.intel.com ([10.253.24.52]) by fmsmga101.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 08 Feb 2023 05:31:23 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6500,9779,10615"; a="669197631" X-IronPort-AV: E=Sophos;i="5.97,280,1669104000"; d="scan'208";a="669197631" Received: from black.fi.intel.com ([10.237.72.28]) by fmsmga007.fm.intel.com with ESMTP; 08 Feb 2023 05:31:20 -0800 Received: by black.fi.intel.com (Postfix, from userid 1003) id ADDFF1F8; Wed, 8 Feb 2023 15:31:58 +0200 (EET) From: Andy Shevchenko To: Andy Shevchenko , Jakub Kicinski , Xin Long , linux-kernel@vger.kernel.org, netdev@vger.kernel.org, dev@openvswitch.org, tipc-discussion@lists.sourceforge.net Cc: "David S. Miller" , Eric Dumazet , Paolo Abeni , Pravin B Shelar , Jon Maloy , Ying Xue , Simon Horman Subject: [PATCH net-next v3 1/3] string_helpers: Move string_is_valid() to the header Date: Wed, 8 Feb 2023 15:31:51 +0200 Message-Id: <20230208133153.22528-1-andriy.shevchenko@linux.intel.com> X-Mailer: git-send-email 2.39.1 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org 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 Reviewed-by: Simon Horman Reviewed-by: Jiri Pirko --- 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 +#include #include /* 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)) From patchwork Wed Feb 8 13:31:52 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andy Shevchenko X-Patchwork-Id: 13133037 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 90649C05027 for ; Wed, 8 Feb 2023 13:31:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230468AbjBHNbq (ORCPT ); Wed, 8 Feb 2023 08:31:46 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35534 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230010AbjBHNbj (ORCPT ); Wed, 8 Feb 2023 08:31:39 -0500 Received: from mga05.intel.com (mga05.intel.com [192.55.52.43]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A1E4247EFB; Wed, 8 Feb 2023 05:31:38 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1675863098; x=1707399098; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=EQiB8u8MT9RmdXrZcW6jRKDu65zFVwKhnZXefFKcEvo=; b=j8CS3nR3fOCXtseyIhe/YFbsZVbY4uitXi3WX29ZAMVyiEvY6Uz5IdI4 +g8eO97Ax/niSD/D0tluV4I6ncMbYvxoOFlx/ESXfqCBvsdgGPNXac2dE 8gO1lnFZX/RuDGrwt0XkQV0WI4lb0nG6NyBnFjo3J4ZYx04ODxXO7K49Z oU+Q0Vc1+BzsM1b0JhWu7zjhiWYPzaAGd47O9wVPKbbefAG6eTqtWm7Ml RQ8XmJbJQt/Cr9OpZrz5ZlQ4YIuoVYmfwjdLYR+Bh30aPKsheAm7u7kBG T+XYX1WtQm46/PlAAncIPlbBmj7VYAIXz7nCB43iFWO7i2E35AG/BlcCU w==; X-IronPort-AV: E=McAfee;i="6500,9779,10615"; a="416017505" X-IronPort-AV: E=Sophos;i="5.97,280,1669104000"; d="scan'208";a="416017505" Received: from orsmga003.jf.intel.com ([10.7.209.27]) by fmsmga105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 08 Feb 2023 05:31:25 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6500,9779,10615"; a="617215419" X-IronPort-AV: E=Sophos;i="5.97,280,1669104000"; d="scan'208";a="617215419" Received: from black.fi.intel.com ([10.237.72.28]) by orsmga003.jf.intel.com with ESMTP; 08 Feb 2023 05:31:21 -0800 Received: by black.fi.intel.com (Postfix, from userid 1003) id 40FEA210; Wed, 8 Feb 2023 15:32:00 +0200 (EET) From: Andy Shevchenko To: Andy Shevchenko , Jakub Kicinski , Xin Long , linux-kernel@vger.kernel.org, netdev@vger.kernel.org, dev@openvswitch.org, tipc-discussion@lists.sourceforge.net Cc: "David S. Miller" , Eric Dumazet , Paolo Abeni , Pravin B Shelar , Jon Maloy , Ying Xue , Simon Horman Subject: [PATCH net-next v3 2/3] genetlink: Use string_is_terminated() helper Date: Wed, 8 Feb 2023 15:31:52 +0200 Message-Id: <20230208133153.22528-2-andriy.shevchenko@linux.intel.com> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230208133153.22528-1-andriy.shevchenko@linux.intel.com> References: <20230208133153.22528-1-andriy.shevchenko@linux.intel.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org Use string_is_terminated() helper instead of cpecific memchr() call. This shows better the intention of the call. Signed-off-by: Andy Shevchenko Reviewed-by: Simon Horman Reviewed-by: Jiri Pirko --- 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 #include #include -#include +#include #include #include #include @@ -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; } From patchwork Wed Feb 8 13:31:53 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andy Shevchenko X-Patchwork-Id: 13133038 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6D3FFC636CC for ; Wed, 8 Feb 2023 13:31:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230504AbjBHNbr (ORCPT ); Wed, 8 Feb 2023 08:31:47 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35558 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230117AbjBHNbk (ORCPT ); Wed, 8 Feb 2023 08:31:40 -0500 Received: from mga05.intel.com (mga05.intel.com [192.55.52.43]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A6C68474C4; Wed, 8 Feb 2023 05:31:39 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1675863099; x=1707399099; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=Cb2fmUJNKf9jp0dPCHeaHoLfrF2oW+dEQC2UUuvVm/I=; b=GIcrIgOCwmSFC9RPuX5RNW4Sfw2lVgxXua0u7Qp23YN2H2YZDQNmNAXR iGO0RGZtxqC312N5r83KPEETIVMAUYM/zYCWOKFHupn+oQNwTVQjD15oM KymST6+We7Sck154Ga0ePjpZPEkroGnhPtIGTzksNRhs10vabg6E1AXud Gq1ovf36jN3kc4HOxzP+1QnQ9qsW5lE/oOxNH331iCpoCnCFezSAsl6fg cbZf3+Nab0E7n1E7Nv/w1uhOv9auDP9CUBvv6LUQ5gmdhPsbBxd5lF+Zr cWYWs9nnjIBPFa0p5Cm9FKystjLxuQ+sPCM/jNgaeLQ+OYO/9OhKKo+WW g==; X-IronPort-AV: E=McAfee;i="6500,9779,10615"; a="416017519" X-IronPort-AV: E=Sophos;i="5.97,280,1669104000"; d="scan'208";a="416017519" Received: from orsmga003.jf.intel.com ([10.7.209.27]) by fmsmga105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 08 Feb 2023 05:31:26 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6500,9779,10615"; a="617215420" X-IronPort-AV: E=Sophos;i="5.97,280,1669104000"; d="scan'208";a="617215420" Received: from black.fi.intel.com ([10.237.72.28]) by orsmga003.jf.intel.com with ESMTP; 08 Feb 2023 05:31:22 -0800 Received: by black.fi.intel.com (Postfix, from userid 1003) id E3581252; Wed, 8 Feb 2023 15:32:00 +0200 (EET) From: Andy Shevchenko To: Andy Shevchenko , Jakub Kicinski , Xin Long , linux-kernel@vger.kernel.org, netdev@vger.kernel.org, dev@openvswitch.org, tipc-discussion@lists.sourceforge.net Cc: "David S. Miller" , Eric Dumazet , Paolo Abeni , Pravin B Shelar , Jon Maloy , Ying Xue , Simon Horman Subject: [PATCH net-next v3 3/3] openvswitch: Use string_is_terminated() helper Date: Wed, 8 Feb 2023 15:31:53 +0200 Message-Id: <20230208133153.22528-3-andriy.shevchenko@linux.intel.com> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230208133153.22528-1-andriy.shevchenko@linux.intel.com> References: <20230208133153.22528-1-andriy.shevchenko@linux.intel.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org Use string_is_terminated() helper instead of cpecific memchr() call. This shows better the intention of the call. Signed-off-by: Andy Shevchenko Reviewed-by: Simon Horman Reviewed-by: Jiri Pirko --- 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 #include #include +#include #include #include #include @@ -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; }