Re: [PATCH] of: reserved-mem: Warn for missing initfn in __reservedmem_of_table
From: 1425075683
Date: Tue Apr 15 2025 - 22:02:45 EST
> On Tue, Apr 15, 2025 at 9:16 AM Liya Huang <1425075683@xxxxxx> wrote:
> >
> > For the data in __reservedmem_of_table, its function pointer initfn might
> > be NULL. However, __reserved_mem_init_node() only considers non-NULL cases
> > and ignores NULL function pointers.
>
> If initfn is NULL, there's no point to the entry and that's a bug.
> Unless you have a build time check, there's no point to add this.
>
> Rob
Thank you for your response. Based on your suggestion, I have made the
modifications and used static_assert() to perform the check at compile
time. The specific code is as follows. Could you please review whether
this modification is reasonable? If it is acceptable, I will proceed with
submitting the patch.
I did not find any usage of static_assert() for null pointer checks in the
kernel code. Additionally, BUILD_BUG_ON() cannot be used globally.
---
diff --git a/include/linux/of_reserved_mem.h b/include/linux/of_reserved_mem.h
index e338282da652..87446ad2deb2 100644
--- a/include/linux/of_reserved_mem.h
+++ b/include/linux/of_reserved_mem.h
@@ -29,6 +29,7 @@ typedef int (*reservedmem_of_init_fn)(struct reserved_mem *rmem);
#ifdef CONFIG_OF_RESERVED_MEM
#define RESERVEDMEM_OF_DECLARE(name, compat, init) \
+ static_assert((init) != NULL); \
_OF_DECLARE(reservedmem, name, compat, init, reservedmem_of_init_fn)
int of_reserved_mem_device_init_by_idx(struct device *dev,
---
Thanks,
--
Liya Huang <1425075683@xxxxxx>