From e6a09861b9a76b5527aa1310cff3d4e772b292b8 Mon Sep 17 00:00:00 2001 From: Ahmad Fatoum Date: Wed, 26 Oct 2022 08:38:19 +0200 Subject: commands: add new stat command We have a couple of commands to help with debugging the VFS: ll, devinfo, devlookup, but we lack a command that can just dump all information we have in a struct stat or struct cdev. Add stat as such a command. For most uses, it's not needed, but it can come in handy for development. The stat_print and cdev_print functions underlying it are exported, so they can called for debugging purposes. Signed-off-by: Ahmad Fatoum Link: https://lore.barebox.org/20221026063819.2355568-1-a.fatoum@pengutronix.de Signed-off-by: Sascha Hauer --- include/fs.h | 3 +++ 1 file changed, 3 insertions(+) (limited to 'include') diff --git a/include/fs.h b/include/fs.h index b501db38ad..f96839f9eb 100644 --- a/include/fs.h +++ b/include/fs.h @@ -147,6 +147,9 @@ int ls(const char *path, ulong flags); char *mkmodestr(unsigned long mode, char *str); +void stat_print(const char *filename, const struct stat *st); +void cdev_print(const struct cdev *cdev); + char *canonicalize_path(const char *pathname); char *get_mounted_path(const char *path); -- cgit v1.2.3 From 0673a1d5e43c1360149f11724f277c82adc06d3e Mon Sep 17 00:00:00 2001 From: Ahmad Fatoum Date: Tue, 1 Nov 2022 07:43:10 +0100 Subject: lib: string: implement mempcpy mempcpy(3) is a GNU libc extension that like stpcpy returns not the start of the destination buffer, but the first byte after its end. Provide it as it is useful when concatenating buffers or known-size strings. Signed-off-by: Ahmad Fatoum Link: https://lore.barebox.org/20221101064310.3227410-1-a.fatoum@pengutronix.de Signed-off-by: Sascha Hauer --- include/string.h | 1 + lib/string.c | 5 +++++ 2 files changed, 6 insertions(+) (limited to 'include') diff --git a/include/string.h b/include/string.h index d423bee6fb..499f2ec03c 100644 --- a/include/string.h +++ b/include/string.h @@ -4,6 +4,7 @@ #include +void *mempcpy(void *dest, const void *src, size_t count); int strtobool(const char *str, int *val); char *strsep_unescaped(char **, const char *); char *stpcpy(char *dest, const char *src); diff --git a/lib/string.c b/lib/string.c index 6389217d5b..005f4532bb 100644 --- a/lib/string.c +++ b/lib/string.c @@ -603,6 +603,11 @@ void *__memcpy(void * dest, const void *src, size_t count) __alias(__default_memcpy); #endif +void *mempcpy(void *dest, const void *src, size_t count) +{ + return memcpy(dest, src, count) + count; +} +EXPORT_SYMBOL(mempcpy); #ifndef __HAVE_ARCH_MEMMOVE /** -- cgit v1.2.3 From ef617bbfe348b0e7e45a682cdb733107fedf0ca1 Mon Sep 17 00:00:00 2001 From: Ahmad Fatoum Date: Wed, 19 Oct 2022 14:38:15 +0200 Subject: include: debug_ll: define puthexc_ll puthex_ll prints a single zero-padded unsigned long, which for a single byte is not very readable, especially on 64-bit systems. Define puthexc_ll() as well, which just accepts a byte and formats its nibbles as hexadecimal characters. Signed-off-by: Ahmad Fatoum Link: https://lore.barebox.org/20221019123817.1659468-1-a.fatoum@pengutronix.de Signed-off-by: Sascha Hauer --- include/debug_ll.h | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) (limited to 'include') diff --git a/include/debug_ll.h b/include/debug_ll.h index 735033b314..856a157bf5 100644 --- a/include/debug_ll.h +++ b/include/debug_ll.h @@ -33,17 +33,25 @@ static inline void putc_ll(char value) PUTC_LL(value); } -static inline void puthex_ll(unsigned long value) +static inline void puthexc_ll(unsigned char value) { int i; unsigned char ch; - for (i = sizeof(unsigned long) * 2; i--; ) { + for (i = 2; i--; ) { ch = ((value >> (i * 4)) & 0xf); ch += (ch >= 10) ? 'a' - 10 : '0'; putc_ll(ch); } } +static inline void puthex_ll(unsigned long value) +{ + int i; + + for (i = sizeof(unsigned long); i--; ) + puthexc_ll(value >> (i * 8)); +} + /* * Be careful with puts_ll, it only works if the binary is running at the * link address which often is not the case during early startup. If in doubt @@ -66,6 +74,10 @@ static inline void putc_ll(char value) { } +static inline void puthexc_ll(unsigned char value) +{ +} + static inline void puthex_ll(unsigned long value) { } -- cgit v1.2.3 From 174253baaf9b7576517930b752f5e727d4b04914 Mon Sep 17 00:00:00 2001 From: Sascha Hauer Date: Mon, 7 Nov 2022 11:07:27 +0100 Subject: make IS_ERR_VALUE() complain about non-pointer-sized arguments IS_ERR_VALUE() needs a pointer sized argument, so warn when any int sized arguments sneak in. When this happens a warning is generated: warning: cast to pointer from integer of different size [-Wint-to-pointer-cast] Based on Kernel commit aa00edc1287a ("make IS_ERR_VALUE() complain about non-pointer-sized arguments") Signed-off-by: Sascha Hauer Link: https://lore.barebox.org/20221107100727.2510346-2-s.hauer@pengutronix.de Signed-off-by: Sascha Hauer --- include/linux/err.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'include') diff --git a/include/linux/err.h b/include/linux/err.h index 69efc7c4ac..db7ad6cc5b 100644 --- a/include/linux/err.h +++ b/include/linux/err.h @@ -19,7 +19,7 @@ #ifndef __ASSEMBLY__ -#define IS_ERR_VALUE(x) unlikely((x) >= (unsigned long)-MAX_ERRNO) +#define IS_ERR_VALUE(x) unlikely((unsigned long)(void *)(x) >= (unsigned long)-MAX_ERRNO) static inline void *ERR_PTR(long error) { -- cgit v1.2.3 From d87cb6746b2f6ae2409be78e83b10935d31405b0 Mon Sep 17 00:00:00 2001 From: Sascha Hauer Date: Mon, 7 Nov 2022 15:45:21 +0100 Subject: bitmap: Implement bitmap_*zalloc() Implement functions for allocating a bitmap. Signed-off-by: Sascha Hauer Link: https://lore.barebox.org/20221107144524.489471-2-s.hauer@pengutronix.de Signed-off-by: Sascha Hauer --- include/linux/bitmap.h | 7 +++++++ lib/bitmap.c | 10 ++++++++++ 2 files changed, 17 insertions(+) (limited to 'include') diff --git a/include/linux/bitmap.h b/include/linux/bitmap.h index adaf5428fe..7d06fac68d 100644 --- a/include/linux/bitmap.h +++ b/include/linux/bitmap.h @@ -80,6 +80,13 @@ * contain all bit positions from 0 to 'bits' - 1. */ +/* + * Allocation and deallocation of bitmap. + * Provided in lib/bitmap.c to avoid circular dependency. + */ +unsigned long *bitmap_zalloc(unsigned int nbits); +unsigned long *bitmap_xzalloc(unsigned int nbits); + /* * lib/bitmap.c provides these functions: */ diff --git a/lib/bitmap.c b/lib/bitmap.c index 5be6651941..dfc0f06b13 100644 --- a/lib/bitmap.c +++ b/lib/bitmap.c @@ -837,3 +837,13 @@ void bitmap_copy_le(void *dst, const unsigned long *src, int nbits) } } EXPORT_SYMBOL(bitmap_copy_le); + +unsigned long *bitmap_zalloc(unsigned int nbits) +{ + return calloc(BITS_TO_LONGS(nbits), sizeof(unsigned long)); +} + +unsigned long *bitmap_xzalloc(unsigned int nbits) +{ + return xzalloc(BITS_TO_LONGS(nbits) * sizeof(unsigned long)); +} -- cgit v1.2.3 From 5c43e199cbfd08180a02706d284d6c5834e97594 Mon Sep 17 00:00:00 2001 From: Sascha Hauer Date: Mon, 7 Nov 2022 15:45:22 +0100 Subject: bitops: include linux/types.h linux/types.h includes asm/types.h. linux/types.h declares 'bool' we need in the next patch, so include the former rather than the latter. Signed-off-by: Sascha Hauer Link: https://lore.barebox.org/20221107144524.489471-3-s.hauer@pengutronix.de Signed-off-by: Sascha Hauer --- include/linux/bitops.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'include') diff --git a/include/linux/bitops.h b/include/linux/bitops.h index 645fd2e6f6..84161e43a3 100644 --- a/include/linux/bitops.h +++ b/include/linux/bitops.h @@ -2,7 +2,7 @@ #ifndef _LINUX_BITOPS_H #define _LINUX_BITOPS_H -#include +#include #ifdef __KERNEL__ #define BIT(nr) (1UL << (nr)) -- cgit v1.2.3 From 2d11e1838be14b9f5ba409da0fd4b07a162cc03c Mon Sep 17 00:00:00 2001 From: Sascha Hauer Date: Mon, 7 Nov 2022 15:45:23 +0100 Subject: bitops: implement assign_bit() assign_bit() is a useful shortcut to if (foo) set_bit(); else clear_bit(); Signed-off-by: Sascha Hauer Link: https://lore.barebox.org/20221107144524.489471-4-s.hauer@pengutronix.de Signed-off-by: Sascha Hauer --- include/linux/bitops.h | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'include') diff --git a/include/linux/bitops.h b/include/linux/bitops.h index 84161e43a3..eb5ff37f2f 100644 --- a/include/linux/bitops.h +++ b/include/linux/bitops.h @@ -194,6 +194,20 @@ static inline unsigned long __ffs64(u64 word) return __ffs((unsigned long)word); } +/** + * assign_bit - Assign value to a bit in memory + * @nr: the bit to set + * @addr: the address to start counting from + * @value: the value to assign + */ +static inline void assign_bit(long nr, volatile unsigned long *addr, bool value) +{ + if (value) + set_bit(nr, addr); + else + clear_bit(nr, addr); +} + #ifdef __KERNEL__ #ifndef set_mask_bits -- cgit v1.2.3