From: "Marek Behún" <kabel@kernel.org>
To: Vinod Koul <vkoul@kernel.org>,
Kishon Vijay Abraham I <kishon@ti.com>,
Linux Phy <linux-phy@lists.infradead.org>,
Kees Cook <keescook@chromium.org>,
Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Cc: "Daniel Scally" <djrscally@gmail.com>,
"Gregory Clement" <gregory.clement@bootlin.com>,
"Heikki Krogerus" <heikki.krogerus@linux.intel.com>,
"Sakari Ailus" <sakari.ailus@linux.intel.com>,
linux-kernel@vger.kernel.org, pali@kernel.org,
josef.schlehofer@nic.cz, "Marek Behún" <kabel@kernel.org>
Subject: [PATCH linux-phy v2 1/4] string.h: Add str_has_proper_prefix()
Date: Wed, 17 Aug 2022 22:03:32 +0200 [thread overview]
Message-ID: <20220817200335.911-2-kabel@kernel.org> (raw)
In-Reply-To: <20220817200335.911-1-kabel@kernel.org>
Add str_has_proper_prefix(), similar to str_has_prefix(), but requires
that the prefix is proper: the string itself must be longer than the
prefix.
Signed-off-by: Marek Behún <kabel@kernel.org>
---
Andy, Kees, could you ack this if it is ok?
---
include/linux/string.h | 18 ++++++++++++++++++
1 file changed, 18 insertions(+)
diff --git a/include/linux/string.h b/include/linux/string.h
index 61ec7e4f6311..375f51b9182c 100644
--- a/include/linux/string.h
+++ b/include/linux/string.h
@@ -316,4 +316,22 @@ static __always_inline size_t str_has_prefix(const char *str, const char *prefix
return strncmp(str, prefix, len) == 0 ? len : 0;
}
+/**
+ * str_has_proper_prefix - Test if a string has a proper prefix
+ * @str: The string to test
+ * @prefix: The string to see if @str starts with
+ *
+ * This is like str_has_prefix(), but fails if the strings are equal.
+ *
+ * Returns:
+ * * strlen(@prefix) if @str starts with @prefix and they aren't equal
+ * * 0 otherwise
+ */
+static __always_inline size_t str_has_proper_prefix(const char *str,
+ const char *prefix)
+{
+ size_t len = strlen(prefix);
+ return strncmp(str, prefix, len) == 0 && len != strlen(str) ? len : 0;
+}
+
#endif /* _LINUX_STRING_H_ */
--
2.35.1
--
linux-phy mailing list
linux-phy@lists.infradead.org
https://lists.infradead.org/mailman/listinfo/linux-phy
WARNING: multiple messages have this Message-ID (diff)
From: "Marek Behún" <kabel@kernel.org>
To: Vinod Koul <vkoul@kernel.org>,
Kishon Vijay Abraham I <kishon@ti.com>,
Linux Phy <linux-phy@lists.infradead.org>,
Kees Cook <keescook@chromium.org>,
Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Cc: "Daniel Scally" <djrscally@gmail.com>,
"Gregory Clement" <gregory.clement@bootlin.com>,
"Heikki Krogerus" <heikki.krogerus@linux.intel.com>,
"Sakari Ailus" <sakari.ailus@linux.intel.com>,
linux-kernel@vger.kernel.org, pali@kernel.org,
josef.schlehofer@nic.cz, "Marek Behún" <kabel@kernel.org>
Subject: [PATCH linux-phy v2 1/4] string.h: Add str_has_proper_prefix()
Date: Wed, 17 Aug 2022 22:03:32 +0200 [thread overview]
Message-ID: <20220817200335.911-2-kabel@kernel.org> (raw)
In-Reply-To: <20220817200335.911-1-kabel@kernel.org>
Add str_has_proper_prefix(), similar to str_has_prefix(), but requires
that the prefix is proper: the string itself must be longer than the
prefix.
Signed-off-by: Marek Behún <kabel@kernel.org>
---
Andy, Kees, could you ack this if it is ok?
---
include/linux/string.h | 18 ++++++++++++++++++
1 file changed, 18 insertions(+)
diff --git a/include/linux/string.h b/include/linux/string.h
index 61ec7e4f6311..375f51b9182c 100644
--- a/include/linux/string.h
+++ b/include/linux/string.h
@@ -316,4 +316,22 @@ static __always_inline size_t str_has_prefix(const char *str, const char *prefix
return strncmp(str, prefix, len) == 0 ? len : 0;
}
+/**
+ * str_has_proper_prefix - Test if a string has a proper prefix
+ * @str: The string to test
+ * @prefix: The string to see if @str starts with
+ *
+ * This is like str_has_prefix(), but fails if the strings are equal.
+ *
+ * Returns:
+ * * strlen(@prefix) if @str starts with @prefix and they aren't equal
+ * * 0 otherwise
+ */
+static __always_inline size_t str_has_proper_prefix(const char *str,
+ const char *prefix)
+{
+ size_t len = strlen(prefix);
+ return strncmp(str, prefix, len) == 0 && len != strlen(str) ? len : 0;
+}
+
#endif /* _LINUX_STRING_H_ */
--
2.35.1
next prev parent reply other threads:[~2022-08-17 20:03 UTC|newest]
Thread overview: 28+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-08-17 20:03 [PATCH linux-phy v2 0/4] mvebu a3720 comphy: Fix serdes transmit amplitude Marek Behún
2022-08-17 20:03 ` Marek Behún
2022-08-17 20:03 ` Marek Behún [this message]
2022-08-17 20:03 ` [PATCH linux-phy v2 1/4] string.h: Add str_has_proper_prefix() Marek Behún
2022-08-18 19:10 ` Andy Shevchenko
2022-08-18 19:10 ` Andy Shevchenko
2022-08-18 19:48 ` Marek Behún
2022-08-18 19:48 ` Marek Behún
2022-08-18 19:56 ` Andy Shevchenko
2022-08-18 19:56 ` Andy Shevchenko
2022-08-18 20:03 ` Marek Behún
2022-08-18 20:03 ` Marek Behún
2022-08-18 20:12 ` Marek Behún
2022-08-18 20:12 ` Marek Behún
2022-08-17 20:03 ` [PATCH linux-phy v2 2/4] device property: Add {fwnode/device}_get_tx_p2p_amplitude() Marek Behún
2022-08-17 20:03 ` Marek Behún
2022-08-18 19:22 ` Andy Shevchenko
2022-08-18 19:22 ` Andy Shevchenko
2022-08-18 19:41 ` Marek Behún
2022-08-18 19:41 ` Marek Behún
2022-08-18 20:10 ` Andy Shevchenko
2022-08-18 20:10 ` Andy Shevchenko
2022-08-18 20:17 ` Marek Behún
2022-08-18 20:17 ` Marek Behún
2022-08-17 20:03 ` [PATCH linux-phy v2 3/4] phy: marvell: phy-mvebu-a3700-comphy: Support changing tx amplitude for ethernet Marek Behún
2022-08-17 20:03 ` Marek Behún
2022-08-17 20:03 ` [PATCH linux-phy v2 4/4] arm64: dts: armada-3720-turris-mox: Change comphy tx amplitude for 2500base-x mode Marek Behún
2022-08-17 20:03 ` Marek Behún
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20220817200335.911-2-kabel@kernel.org \
--to=kabel@kernel.org \
--cc=andriy.shevchenko@linux.intel.com \
--cc=djrscally@gmail.com \
--cc=gregory.clement@bootlin.com \
--cc=heikki.krogerus@linux.intel.com \
--cc=josef.schlehofer@nic.cz \
--cc=keescook@chromium.org \
--cc=kishon@ti.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-phy@lists.infradead.org \
--cc=pali@kernel.org \
--cc=sakari.ailus@linux.intel.com \
--cc=vkoul@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.