[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <1a7fc356e5a78432f1b9b0c5e50b6f2dd2e1f56c.1653471377.git.baskov@ispras.ru>
Date: Wed, 25 May 2022 13:10:09 +0300
From: Evgeniy Baskov <baskov@...ras.ru>
To: Borislav Petkov <bp@...en8.de>
Cc: Evgeniy Baskov <baskov@...ras.ru>,
Thomas Gleixner <tglx@...utronix.de>,
Ingo Molnar <mingo@...hat.com>,
Dave Hansen <dave.hansen@...ux.intel.com>, x86@...nel.org,
linux-kernel@...r.kernel.org
Subject: [PATCH v4 1/5] x86/boot: Add strlcat() to compressed kernel
strlcat() simplifies the code of command line
concatenation and reduces the probability of mistakes.
Signed-off-by: Evgeniy Baskov <baskov@...ras.ru>
diff --git a/arch/x86/boot/compressed/string.c b/arch/x86/boot/compressed/string.c
index 81fc1eaa3229..6d74d31bf3d9 100644
--- a/arch/x86/boot/compressed/string.c
+++ b/arch/x86/boot/compressed/string.c
@@ -40,6 +40,25 @@ static void *____memcpy(void *dest, const void *src, size_t n)
}
#endif
+size_t strlcat(char *dest, const char *src, size_t count)
+{
+ size_t dsize = strlen(dest);
+ size_t len = strlen(src);
+ size_t res = dsize + len;
+
+ /* This would be a bug */
+ if (dsize >= count)
+ error("strlcat(): destination too big\n");
+
+ dest += dsize;
+ count -= dsize;
+ if (len >= count)
+ len = count-1;
+ memcpy(dest, src, len);
+ dest[len] = 0;
+ return res;
+}
+
void *memset(void *s, int c, size_t n)
{
int i;
diff --git a/arch/x86/purgatory/purgatory.c b/arch/x86/purgatory/purgatory.c
index 7558139920f8..65f0cedb65ae 100644
--- a/arch/x86/purgatory/purgatory.c
+++ b/arch/x86/purgatory/purgatory.c
@@ -57,3 +57,4 @@ void purgatory(void)
* arch/x86/boot/compressed/string.c
*/
void warn(const char *msg) {}
+void error(char *m) {}
--
2.36.1
Powered by blists - more mailing lists