From patchwork Mon Feb 6 16:13:12 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andy Shevchenko X-Patchwork-Id: 13130301 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 60C59C05027 for ; Mon, 6 Feb 2023 16:13:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231851AbjBFQNr (ORCPT ); Mon, 6 Feb 2023 11:13:47 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51422 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231785AbjBFQNa (ORCPT ); Mon, 6 Feb 2023 11:13:30 -0500 Received: from mga12.intel.com (mga12.intel.com [192.55.52.136]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9EBD32196E; Mon, 6 Feb 2023 08:13:13 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1675699994; x=1707235994; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=nqrQtqd1T9xl/j9igH6LicfTqt28OCju6w046xOfGT8=; b=R9Ki1kspX3VfeFMu/fKN1mHTYox6ZinvaNu+9w6n0WuRTSB4Qb50aAa2 JLDKEd1wLl5l+KqX0QkTTXaLaCn/AVWHE3ccoGU/NwPPl0iXMjmmFDvjS AgWdoXVaCNG/UI9c520NT3489C93fzh3V9KU5O4XpzqyG/SuyY5ku9vG6 EH2n4+e5+ab4gdE7JQvi/K0zy2c5GMgHjYFVDvOwAB66wxcPhm8Z1CSwk EoTp6r+wp2lehBOfOwfcQC3jT8sYgngf9x/5ZXKzJZjKbutePE0LIN20z 5WsqKa0lZ6AQd8zzMFlPo6C33dMkX9LNmu1Ie1IrYvQHhicA33lNrVBLA w==; X-IronPort-AV: E=McAfee;i="6500,9779,10613"; a="308888751" X-IronPort-AV: E=Sophos;i="5.97,276,1669104000"; d="scan'208";a="308888751" Received: from orsmga001.jf.intel.com ([10.7.209.18]) by fmsmga106.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 06 Feb 2023 08:12:42 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6500,9779,10613"; a="698884370" X-IronPort-AV: E=Sophos;i="5.97,276,1669104000"; d="scan'208";a="698884370" Received: from black.fi.intel.com ([10.237.72.28]) by orsmga001.jf.intel.com with ESMTP; 06 Feb 2023 08:12:37 -0800 Received: by black.fi.intel.com (Postfix, from userid 1003) id D6DDB1EA; Mon, 6 Feb 2023 18:13:15 +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: Andy Shevchenko , "David S. Miller" , Eric Dumazet , Paolo Abeni , Pravin B Shelar , Jon Maloy , Ying Xue , Simon Horman Subject: [PATCH net-next v2 1/3] string_helpers: Move string_is_valid() to the header Date: Mon, 6 Feb 2023 18:13:12 +0200 Message-Id: <20230206161314.15667-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. Signed-off-by: Andy Shevchenko Reviewed-by: Simon Horman --- v2: added tag and updated subject (Simon) include/linux/string_helpers.h | 5 +++++ net/tipc/netlink_compat.c | 6 +----- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/include/linux/string_helpers.h b/include/linux/string_helpers.h index 88fb8e1d0421..01c9a432865a 100644 --- a/include/linux/string_helpers.h +++ b/include/linux/string_helpers.h @@ -12,6 +12,11 @@ struct device; struct file; struct task_struct; +static inline bool string_is_valid(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..75186cd551a0 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) From patchwork Mon Feb 6 16:13:13 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andy Shevchenko X-Patchwork-Id: 13130302 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 0E662C05027 for ; Mon, 6 Feb 2023 16:14:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231878AbjBFQOR (ORCPT ); Mon, 6 Feb 2023 11:14:17 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51700 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231747AbjBFQNw (ORCPT ); Mon, 6 Feb 2023 11:13:52 -0500 Received: from mga12.intel.com (mga12.intel.com [192.55.52.136]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1891121A34; Mon, 6 Feb 2023 08:13:31 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1675700011; x=1707236011; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=opG93wOQRIEErRHxhGk0I3FgKRpuFZyL/E0+9hZucw0=; b=Jc7QLODUsDsFgeyXlfByDiFntbY/QpvZRHhuWDyWvN5qSCBbcksammns RCZIXjgrCcU5/xOoL1soZDfJ+ZUGYgMtvKo9HYHykjR5YWjNRxZXl8jDc DOJTLeMLqL37uPAAJgmRReIlXqYYaYBGHIB3wHRNsbs9cmlhgw/5BWpcq ebCBMfdEAFACrg8r/ni1VLMfEFKfXqBqC1PXc74QMP53HBpIhZ4axW4ze 0nnGrrQS10BZMnVErFEGPPPiDQqx6S1s2yemPUuVWvl7FyPKyfNpT5aPD qBUhhNEE07oU5FfvNAXw8tKrZr7+IPgTOyKCClRHErBe8lWHbBaqxh3hI Q==; X-IronPort-AV: E=McAfee;i="6500,9779,10613"; a="308888767" X-IronPort-AV: E=Sophos;i="5.97,276,1669104000"; d="scan'208";a="308888767" Received: from orsmga001.jf.intel.com ([10.7.209.18]) by fmsmga106.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 06 Feb 2023 08:12:42 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6500,9779,10613"; a="698884369" X-IronPort-AV: E=Sophos;i="5.97,276,1669104000"; d="scan'208";a="698884369" Received: from black.fi.intel.com ([10.237.72.28]) by orsmga001.jf.intel.com with ESMTP; 06 Feb 2023 08:12:37 -0800 Received: by black.fi.intel.com (Postfix, from userid 1003) id E75381DD; Mon, 6 Feb 2023 18:13:15 +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: Andy Shevchenko , "David S. Miller" , Eric Dumazet , Paolo Abeni , Pravin B Shelar , Jon Maloy , Ying Xue , Simon Horman Subject: [PATCH net-next v2 2/3] genetlink: Use string_is_valid() helper Date: Mon, 6 Feb 2023 18:13:13 +0200 Message-Id: <20230206161314.15667-2-andriy.shevchenko@linux.intel.com> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230206161314.15667-1-andriy.shevchenko@linux.intel.com> References: <20230206161314.15667-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_valid() helper instead of cpecific memchr() call. This shows better the intention of the call. Signed-off-by: Andy Shevchenko Reviewed-by: Simon Horman --- 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..d7616c1bda93 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_valid(grp->name, GENL_NAMSIZ))) return -EINVAL; } From patchwork Mon Feb 6 16:13:14 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andy Shevchenko X-Patchwork-Id: 13130291 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 7B3A8C05027 for ; Mon, 6 Feb 2023 16:13:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231765AbjBFQNW (ORCPT ); Mon, 6 Feb 2023 11:13:22 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50214 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231771AbjBFQNN (ORCPT ); Mon, 6 Feb 2023 11:13:13 -0500 Received: from mga07.intel.com (mga07.intel.com [134.134.136.100]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C496C2FCEB; Mon, 6 Feb 2023 08:12:44 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1675699964; x=1707235964; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=l/z8Ht549NtECTSxHC6f4gPVeQdnVs1kMMhg97KXrdY=; b=ElcICijSmWubzlx63RORU8S54xKAXeKuIJfW4fAiZL35b0B+szfKbYQT 8sMKt/VJWfDQ1VLROOD3MiwjyMp2la/R6woUEM398MNUCsjlLBPMnPZu9 +ap2LkR3vw+seZRhG8+qTOQ3bbtQPNeL3PQ67Vj8CEGUYL09Kh4PAti0q +xkFWtlxXVJefPmlUc/cmkRF8rKwn7loJkhRDkmD4lLJznpC2umbm/6hi PQM0HuSqql/lJCLk6p0MfZGkGoL78R2e726JMWB7F/q9vg/j3tAcRLw3c V5tXSZUZGIEoVB2HVyxqPwPZxAA+wUaA6vqqW2ALHuVCANUFSFsC4S7m2 w==; X-IronPort-AV: E=McAfee;i="6500,9779,10613"; a="393840633" X-IronPort-AV: E=Sophos;i="5.97,276,1669104000"; d="scan'208";a="393840633" Received: from orsmga008.jf.intel.com ([10.7.209.65]) by orsmga105.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 06 Feb 2023 08:12:42 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6500,9779,10613"; a="696902426" X-IronPort-AV: E=Sophos;i="5.97,276,1669104000"; d="scan'208";a="696902426" Received: from black.fi.intel.com ([10.237.72.28]) by orsmga008.jf.intel.com with ESMTP; 06 Feb 2023 08:12:37 -0800 Received: by black.fi.intel.com (Postfix, from userid 1003) id 02DAC27B; Mon, 6 Feb 2023 18:13:15 +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: Andy Shevchenko , "David S. Miller" , Eric Dumazet , Paolo Abeni , Pravin B Shelar , Jon Maloy , Ying Xue , Simon Horman Subject: [PATCH net-next v2 3/3] openvswitch: Use string_is_valid() helper Date: Mon, 6 Feb 2023 18:13:14 +0200 Message-Id: <20230206161314.15667-3-andriy.shevchenko@linux.intel.com> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230206161314.15667-1-andriy.shevchenko@linux.intel.com> References: <20230206161314.15667-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_valid() helper instead of cpecific memchr() call. This shows better the intention of the call. Signed-off-by: Andy Shevchenko Reviewed-by: Simon Horman --- 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..1d65805e79b4 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_valid(*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_valid(info->timeout, nla_len(a))) { OVS_NLERR(log, "Invalid conntrack timeout"); return -EINVAL; }