Closed
Description
The current implementation of devicemodel_remove()
uses conditional compilation to switch the return type between void
and int
, as shown below:
#if LINUX_VERSION_CODE >= KERNEL_VERSION(6, 11, 0)
static void devicemodel_remove(struct platform_device *dev)
#else
static int devicemodel_remove(struct platform_device *dev)
#endif
{
pr_info("devicemodel example removed\n");
/* Your device removal code */
#if LINUX_VERSION_CODE < KERNEL_VERSION(6, 11, 0)
return 0;
#endif
}
This approach works functionally, but it's not intuitive. The logic is split across multiple #if
/#endif
blocks, making it harder to read and maintain.
I propose replacing it with a clearer structure by splitting the entire function definition based on kernel version:
#if LINUX_VERSION_CODE >= KERNEL_VERSION(6, 11, 0)
static void devicemodel_remove(struct platform_device *dev)
{
pr_info("devicemodel example removed\n");
/* Your device removal code */
}
#else
static int devicemodel_remove(struct platform_device *dev)
{
pr_info("devicemodel example removed\n");
/* Your device removal code */
return 0;
}
#endif
This makes the logic easier to understand and reduces potential confusion for future readers.
If this looks good, I can send a patch for it.
Metadata
Metadata
Assignees
Labels
No labels