Browse Source

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 <yphbchou0911@gmail.com>
Cheng-Yang Chou 1 day ago
parent
commit
38a991d303
1 changed files with 6 additions and 4 deletions
  1. 6 4
      examples/devicemodel.c

+ 6 - 4
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)
 {