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
This commit is contained in:
Gleb Chesnokov
2026-10-21 22:12:25 +03:00
parent cd0e840804
commit 80ba29ee60
+11 -23
View File
@@ -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);