@@ -934,16 +934,8 @@ struct dx_hash_info {
/* pr_warn_once is in linux/printk.h */
/* lockdep_assert_held_read is in linux/lockdep.h */
-
-/* strtomem_pad - copy string to fixed-size buffer with padding */
-#define strtomem_pad(dest, src, pad) do { \
- size_t _len = strlen(src); \
- if (_len >= sizeof(dest)) \
- _len = sizeof(dest); \
- memcpy(dest, src, _len); \
- if (_len < sizeof(dest)) \
- memset((char *)(dest) + _len, (pad), sizeof(dest) - _len); \
-} while (0)
+/* strtomem_pad is in linux/string.h */
+/* strscpy_pad is in linux/string.h */
/* Memory weight - count set bits */
static inline unsigned long memweight(const void *ptr, size_t bytes)
@@ -2075,10 +2067,7 @@ struct dentry *generic_fh_to_parent(struct super_block *sb, struct fid *fid,
/* I/O priority - declaration for stub.c */
int IOPRIO_PRIO_VALUE(int class, int data);
-/* String operations */
-char *kmemdup_nul(const char *s, size_t len, gfp_t gfp);
-#define strscpy_pad(dst, src) strncpy(dst, src, sizeof(dst))
-
+/* kmemdup_nul is in linux/slab.h */
/* fscrypt declarations are in ext4_fscrypt.h */
/* Memory allocation - declarations for stub.c */
@@ -2191,8 +2180,7 @@ struct mb_cache_entry {
void generic_set_sb_d_ops(struct super_block *sb);
struct dentry *d_make_root(struct inode *inode);
-/* String operations - declarations for stub.c */
-char *strreplace(const char *str, char old, char new);
+/* strreplace is in linux/string.h */
/* Ratelimit - declaration for stub.c */
void ratelimit_state_init(void *rs, int interval, int burst);
@@ -373,32 +373,8 @@ int ext4_update_overhead(struct super_block *sb, bool force)
return 0;
}
-/* String stubs */
-/* strtomem_pad is now a macro in ext4_uboot.h */
-
-char *strreplace(const char *str, char old, char new)
-{
- char *s = (char *)str;
-
- while (*s) {
- if (*s == old)
- *s = new;
- s++;
- }
- return (char *)str;
-}
-
-char *kmemdup_nul(const char *s, size_t len, gfp_t gfp)
-{
- char *buf;
-
- buf = kmalloc(len + 1, gfp);
- if (buf) {
- memcpy(buf, s, len);
- buf[len] = '\0';
- }
- return buf;
-}
+/* strtomem_pad, strscpy_pad, strreplace are now in linux/string.h */
+/* kmemdup_nul is now in linux/slab.h, with implementation in lib/string.c */
/* Page allocation */
unsigned long get_zeroed_page(gfp_t gfp)
@@ -506,8 +482,8 @@ int sb_set_blocksize(struct super_block *sb, int size)
return size;
}
-/* strscpy_pad is now a macro in ext4_uboot.h */
-/* kmemdup_nul is defined earlier in this file */
+/* strscpy_pad is now a macro in linux/string.h */
+/* kmemdup_nul is now in lib/string.c */
/* Address check */
int generic_check_addressable(unsigned int blocksize_bits, u64 num_blocks)
@@ -87,6 +87,19 @@ static inline void *krealloc(const void *p, size_t new_size, gfp_t flags)
void *kmemdup(const void *src, size_t len, gfp_t gfp);
+/**
+ * kmemdup_nul - Duplicate a string with null termination
+ * @s: Source string
+ * @len: Maximum length to copy
+ * @gfp: GFP flags for allocation
+ *
+ * Allocates len + 1 bytes, copies up to @len bytes from @s, and
+ * ensures the result is null-terminated.
+ *
+ * Return: pointer to new string, or NULL on allocation failure
+ */
+char *kmemdup_nul(const char *s, size_t len, gfp_t gfp);
+
/* kmem_cache stubs */
struct kmem_cache {
int sz;
@@ -147,6 +147,47 @@ char *memdup(const void *src, size_t len);
unsigned long ustrtoul(const char *cp, char **endp, unsigned int base);
unsigned long long ustrtoull(const char *cp, char **endp, unsigned int base);
+/**
+ * strreplace() - Replace all occurrences of a character in a string
+ * @str: The string to operate on
+ * @old: The character being replaced
+ * @new: The character @old is replaced with
+ *
+ * Replaces all occurrences of character @old with character @new in
+ * the string @str in place.
+ *
+ * Return: pointer to the string @str itself
+ */
+char *strreplace(char *str, char old, char new);
+
+/**
+ * strtomem_pad - Copy string to fixed-size buffer with padding
+ * @dest: Destination buffer (must be an array, not a pointer)
+ * @src: Source string
+ * @pad: Padding character to fill remaining space
+ *
+ * Copy @src to @dest, truncating if necessary. If @src is shorter
+ * than @dest, fill the remaining bytes with @pad.
+ */
+#define strtomem_pad(dest, src, pad) do { \
+ size_t _len = strlen(src); \
+ if (_len >= sizeof(dest)) \
+ _len = sizeof(dest); \
+ memcpy(dest, src, _len); \
+ if (_len < sizeof(dest)) \
+ memset((char *)(dest) + _len, (pad), \
+ sizeof(dest) - _len); \
+} while (0)
+
+/**
+ * strscpy_pad - Copy string to fixed-size buffer with padding
+ * @dest: Destination buffer (must be an array)
+ * @src: Source string
+ *
+ * Copy @src to @dest ensuring null termination and zero-padding.
+ */
+#define strscpy_pad(dest, src) strncpy(dest, src, sizeof(dest))
+
#ifdef __cplusplus
}
#endif
@@ -20,6 +20,7 @@
#include <limits.h>
#include <linux/compiler.h>
#include <linux/ctype.h>
+#include <linux/slab.h>
#include <linux/string.h>
#include <linux/types.h>
#include <malloc.h>
@@ -802,3 +803,27 @@ void *memchr_inv(const void *start, int c, size_t bytes)
return check_bytes8(start, value, bytes % 8);
}
#endif
+
+char *strreplace(char *str, char old, char new)
+{
+ char *s = str;
+
+ while (*s) {
+ if (*s == old)
+ *s = new;
+ s++;
+ }
+ return str;
+}
+
+char *kmemdup_nul(const char *s, size_t len, gfp_t gfp)
+{
+ char *buf;
+
+ buf = kmalloc(len + 1, gfp);
+ if (buf) {
+ memcpy(buf, s, len);
+ buf[len] = '\0';
+ }
+ return buf;
+}