Skip to content

Commit 38a991d

Browse files
committed
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 <[email protected]>
1 parent 0954458 commit 38a991d

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

examples/devicemodel.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,19 +23,21 @@ static int devicemodel_probe(struct platform_device *dev)
2323

2424
return 0;
2525
}
26+
2627
#if LINUX_VERSION_CODE >= KERNEL_VERSION(6, 11, 0)
2728
static void devicemodel_remove(struct platform_device *dev)
29+
{
30+
pr_info("devicemodel example removed\n");
31+
/* Your device removal code */
32+
}
2833
#else
2934
static int devicemodel_remove(struct platform_device *dev)
30-
#endif
3135
{
3236
pr_info("devicemodel example removed\n");
33-
3437
/* Your device removal code */
35-
#if LINUX_VERSION_CODE < KERNEL_VERSION(6, 11, 0)
3638
return 0;
37-
#endif
3839
}
40+
#endif
3941

4042
static int devicemodel_suspend(struct device *dev)
4143
{

0 commit comments

Comments
 (0)