Skip to content

Improve readability of devicemodel_remove() version-dependent definition #313

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
EricccTaiwan opened this issue Apr 24, 2025 · 0 comments

Comments

@EricccTaiwan
Copy link
Contributor

EricccTaiwan commented Apr 24, 2025

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant