Search code examples
clinuxapilinux-kernelvoid

What is the reason for returning int when it's actually void?


I faced with some strange (for me) code in Linux kernel sources. There is xt_register_target() function:

int xt_register_target(struct xt_target *target)
{
    u_int8_t af = target->family;

    mutex_lock(&xt[af].mutex);
    list_add(&target->list, &xt[af].target);
    mutex_unlock(&xt[af].mutex);
    return 0;
}
EXPORT_SYMBOL(xt_register_target);

This is an API function. So it seems that it must have some obvious (for API user) reason for the value it returns. But this function has no variability - it always returns 0. So basically it is void.
What is the reason for such API coding pattern? Is this best practice or a mistake?


Solution

  • Digging into the git history, it seems this function did previously have failure conditions but those conditions were later removed in this commit.

    So it made sense to keep the function's implementation the same to prevent changes to calling functions.