From 80ba29ee604d5b0b6a13adfdb9d741ff6671a6fc Mon Sep 17 00:00:00 2001 From: Gleb Chesnokov Date: Wed, 21 Oct 2026 15:03:43 +0300 Subject: [PATCH] scst/include/backport.h: Clarify sysfs buffer validation Compute the version-dependent buffer validity before WARN() instead of splitting its argument list with preprocessor branches. Preserve the old SLUB exception, NULL short-circuiting and offset bounds. Use __func__ for the unchanged diagnostic function names. Checkpatch reports EMBEDDED_FUNCTION_NAME: Prefer using '"%s...", __func__' to using 'sysfs_emit_at', this function's name, in a string --- scst/include/backport.h | 34 +++++++++++----------------------- 1 file changed, 11 insertions(+), 23 deletions(-) diff --git a/scst/include/backport.h b/scst/include/backport.h index 025bfb215..7b77f4cc0 100644 --- a/scst/include/backport.h +++ b/scst/include/backport.h @@ -1809,19 +1809,13 @@ int sysfs_emit(char *buf, const char *fmt, ...) { va_list args; int len; + bool invalid = !buf; - if (WARN(!buf || -#if LINUX_VERSION_CODE < KERNEL_VERSION(4, 20, 0) - /* - * For kernel releases older than 4.20, using the SLUB allocator will cause - * this alignment check to fail as that allocator did NOT align kmalloc - * allocations on a PAGE_SIZE boundary. - */ - false, -#else - offset_in_page(buf), +#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 20, 0) + /* Older SLUB allocators need not align the buffer to a page boundary. */ + invalid = invalid || offset_in_page(buf); #endif - "invalid sysfs_emit: buf:%p\n", buf)) + if (WARN(invalid, "invalid %s: buf:%p\n", __func__, buf)) return 0; va_start(args, fmt); @@ -1836,20 +1830,14 @@ int sysfs_emit_at(char *buf, int at, const char *fmt, ...) { va_list args; int len; + bool invalid = !buf; - if (WARN(!buf || -#if LINUX_VERSION_CODE < KERNEL_VERSION(4, 20, 0) - /* - * For kernel releases older than 4.20, using the SLUB allocator will cause - * this alignment check to fail as that allocator did NOT align kmalloc - * allocations on a PAGE_SIZE boundary. - */ - false || -#else - offset_in_page(buf) || +#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 20, 0) + /* Older SLUB allocators need not align the buffer to a page boundary. */ + invalid = invalid || offset_in_page(buf); #endif - at < 0 || at >= PAGE_SIZE, - "invalid sysfs_emit_at: buf:%p at:%d\n", buf, at)) + if (WARN(invalid || at < 0 || at >= PAGE_SIZE, + "invalid %s: buf:%p at:%d\n", __func__, buf, at)) return 0; va_start(args, fmt);