On 4/19/22 08:30, Kirill A. Shutemov wrote:
>> I think the stuff coming from the linux/ namespace you can simply copy
>> into a header in compressed/, like I've done with efi.h.
> Hm. Dave was worried about having copies of _find_next_bit() and
> __bitmap_*() inside compressed/.
>
> How do we rectify code duplication and making decompresser self-contained?
> Do we care about multiple copies of the same code in the kernel?
> Do we care about keeping them in sync?
Would it be feasible to have the common code defined as a 'static
inline' in a header that both the main kernel and the decompressor could
include? Something like the attached patch.
I'd much rather duplicate something like this:
int strncasecmp(const char *s1, const char *s2, size_t len)
{
return __lib_strncasecmp(s1, s1, len);
}
in the decompressor versus a real full implementation.
commit d94fa6842b25809958903fdd33d498bb622695a5
Author: Dave Hansen <dave.hansen@xxxxxxxxxxxxxxx>
Date: Tue Apr 19 09:31:07 2022 -0700
foo
bar1
diff --git a/lib/string-internal.h b/lib/string-internal.h
new file mode 100644
index 000000000000..230c22864b75
--- /dev/null
+++ b/lib/string-internal.h
@@ -0,0 +1,31 @@
+#include <linux/ctype.h>
+
+/**
+ * strncasecmp - Case insensitive, length-limited string comparison
+ * @s1: One string
+ * @s2: The other string
+ * @len: the maximum number of characters to compare
+ */
+static inline int __lib_strncasecmp(const char *s1, const char *s2, size_t len)
+{
+ /* Yes, Virginia, it had better be unsigned */
+ unsigned char c1, c2;
+
+ if (!len)
+ return 0;
+
+ do {
+ c1 = *s1++;
+ c2 = *s2++;
+ if (!c1 || !c2)
+ break;
+ if (c1 == c2)
+ continue;
+ c1 = tolower(c1);
+ c2 = tolower(c2);
+ if (c1 != c2)
+ break;
+ } while (--len);
+ return (int)c1 - (int)c2;
+}
+#endif
diff --git a/lib/string.c b/lib/string.c
index 485777c9da83..705b799e3b5c 100644
--- a/lib/string.c
+++ b/lib/string.c
@@ -29,6 +29,7 @@
#include <asm/word-at-a-time.h>
#include <asm/page.h>
+#include "string-internal.h"
#ifndef __HAVE_ARCH_STRNCASECMP
/**
* strncasecmp - Case insensitive, length-limited string comparison
@@ -38,25 +39,7 @@
*/
int strncasecmp(const char *s1, const char *s2, size_t len)
{
- /* Yes, Virginia, it had better be unsigned */
- unsigned char c1, c2;
-
- if (!len)
- return 0;
-
- do {
- c1 = *s1++;
- c2 = *s2++;
- if (!c1 || !c2)
- break;
- if (c1 == c2)
- continue;
- c1 = tolower(c1);
- c2 = tolower(c2);
- if (c1 != c2)
- break;
- } while (--len);
- return (int)c1 - (int)c2;
+ return __lib_strncasecmp(s1, s1, len);
}
EXPORT_SYMBOL(strncasecmp);
#endif