From 38a991d303ebc54aa7c1e651548101f6ddfc3b00 Mon Sep 17 00:00:00 2001 From: Cheng-Yang Chou Date: Sun, 18 May 2025 17:15:40 +0800 Subject: [PATCH] examples: Refactor device model with version-based split The previous implementation of devicemodel_remove used conditional compilation to switch between void and int return types based on the kernel version. While functionally correct, the interleaved `#if/#endif` blocks made the logic harder to follow. This refactor cleanly separates the two function definitions using a full `#if/#else` block around the entire function. No functional behavior is changed. Close: #313 Signed-off-by: Cheng-Yang Chou --- examples/devicemodel.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/examples/devicemodel.c b/examples/devicemodel.c index 90a48519..e4dc2d26 100644 --- a/examples/devicemodel.c +++ b/examples/devicemodel.c @@ -23,19 +23,21 @@ static int devicemodel_probe(struct platform_device *dev) return 0; } + #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) -#endif { pr_info("devicemodel example removed\n"); - /* Your device removal code */ -#if LINUX_VERSION_CODE < KERNEL_VERSION(6, 11, 0) return 0; -#endif } +#endif static int devicemodel_suspend(struct device *dev) {