From: Alexey Dobriyan <adobriyan@gmail.com>
To: akpm@linux-foundation.org
Cc: linux-kernel@vger.kernel.org
Subject: [PATCH] string: implement streq()
Date: Sat, 1 Apr 2023 20:48:05 +0300 [thread overview]
Message-ID: <4b595ab9-238c-43a5-aba0-be5d6afc0f87@p183> (raw)
Most of the time strcmp() is being used, strings are checked for equality.
Add wrapper to relay such intent (it is shorter to type, too).
Use
if (streq(s, "s")) {
}
or
if (!streq(s, "s")) {
}
Signed-off-by: Alexey Dobriyan <adobriyan@gmail.com>
---
drivers/clk/socfpga/clk-gate-a10.c | 2 --
drivers/clk/socfpga/clk.h | 1 -
include/linux/string.h | 6 ++++++
scripts/dtc/dtc.h | 6 +++++-
4 files changed, 11 insertions(+), 4 deletions(-)
--- a/drivers/clk/socfpga/clk-gate-a10.c
+++ b/drivers/clk/socfpga/clk-gate-a10.c
@@ -11,8 +11,6 @@
#include "clk.h"
-#define streq(a, b) (strcmp((a), (b)) == 0)
-
#define to_socfpga_gate_clk(p) container_of(p, struct socfpga_gate_clk, hw.hw)
/* SDMMC Group for System Manager defines */
--- a/drivers/clk/socfpga/clk.h
+++ b/drivers/clk/socfpga/clk.h
@@ -19,7 +19,6 @@
#define SOCFPGA_MAX_PARENTS 5
-#define streq(a, b) (strcmp((a), (b)) == 0)
#define SYSMGR_SDMMC_CTRL_SET(smplsel, drvsel) \
((((smplsel) & 0x7) << 3) | (((drvsel) & 0x7) << 0))
--- a/include/linux/string.h
+++ b/include/linux/string.h
@@ -47,6 +47,12 @@ extern size_t strlcat(char *, const char *, __kernel_size_t);
#ifndef __HAVE_ARCH_STRCMP
extern int strcmp(const char *,const char *);
#endif
+
+static inline bool streq(const char *a, const char *b)
+{
+ return strcmp(a, b) == 0;
+}
+
#ifndef __HAVE_ARCH_STRNCMP
extern int strncmp(const char *,const char *,__kernel_size_t);
#endif
--- a/scripts/dtc/dtc.h
+++ b/scripts/dtc/dtc.h
@@ -88,7 +88,11 @@ static inline uint64_t dtb_ld64(const void *p)
| bp[7];
}
-#define streq(a, b) (strcmp((a), (b)) == 0)
+static inline bool streq(const char *a, const char *b)
+{
+ return strcmp(a, b) == 0;
+}
+
#define strstarts(s, prefix) (strncmp((s), (prefix), strlen(prefix)) == 0)
#define strprefixeq(a, n, b) (strlen(b) == (n) && (memcmp(a, b, n) == 0))
static inline bool strends(const char *str, const char *suffix)
next reply other threads:[~2023-04-01 17:48 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-04-01 17:48 Alexey Dobriyan [this message]
2023-04-03 21:16 ` Andrew Morton
2023-04-04 14:54 ` Alexey Dobriyan
2023-04-05 10:45 ` David Laight
2023-04-05 11:39 ` Alexey Dobriyan
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=4b595ab9-238c-43a5-aba0-be5d6afc0f87@p183 \
--to=adobriyan@gmail.com \
--cc=akpm@linux-foundation.org \
--cc=linux-kernel@vger.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®