Why do some linux header files define a function to return 0 after the declaration?

The B-52s Bassist

I am looking at the Linux 4.14 kernel's include/linux/clk.h file, and have noticed that some of the functions are declared, and then later defined to return 0 or NULL.

For example:

struct clk *clk_get(struct device *dev, const char *id);
...
static inline struct clk *clk_get(struct device *dev, const char *id)
{
        return NULL;
}

What is the purpose of doing this? I see multiple C source files that fully define this function and still include linux/clk.h.

Rachid K.

Linux kernel comes with lots of configuration parameters. For this particular function, you get the service if CONFIG_HAVE_CLK parameter is defined:

#ifdef CONFIG_HAVE_CLK
/**
 * clk_get - lookup and obtain a reference to a clock producer.
 * @dev: device for clock "consumer"
 * @id: clock consumer ID
 *
 * Returns a struct clk corresponding to the clock producer, or
 * valid IS_ERR() condition containing errno.  The implementation
 * uses @dev and @id to determine the clock consumer, and thereby
 * the clock producer.  (IOW, @id may be identical strings, but
 * clk_get may return different clock producers depending on @dev.)
 *
 * Drivers must assume that the clock source is not enabled.
 *
 * clk_get should not be called from within interrupt context.
 */
struct clk *clk_get(struct device *dev, const char *id);
[...]
#else /* !CONFIG_HAVE_CLK */

static inline struct clk *clk_get(struct device *dev, const char *id)
{
    return NULL;
}
[...]

This parameter is defined in arch/Kconfig as:

config HAVE_CLK
    bool
    help
      The <linux/clk.h> calls support software clock gating and
      thus are a key power management tool on many systems.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Why do some js files begin with (function() {

From Dev

Why is it not advised to define macros in header files?

From Dev

Why do some Linux files have a 'd' suffix?

From Dev

Why do some files names in Linux start with numbers?

From Dev

How do you define functions in header files?

From Dev

Why return value from a function following local declaration in bash is always 0?

From Dev

Why does this Solidity function return a 0 after assert?

From Java

Why do some functions have underscores "__" before and after the function name?

From Java

Why do some functions have underscores "__" before and after the function name?

From Dev

C: Why do we include header files, which declare but don't define?

From Dev

Why do some files of working packages return "not found" for some libraries of ldd's output?

From Dev

using declaration in header files

From Dev

Shell, bash, linux ; after variable declaration, why semi-colon and what does it do?

From Dev

Why do some people define objects as pointers?

From Dev

Calling function with no declaration in header

From Dev

Why does this function return 0

From Java

Why do some comparable classes in the JDK limit the comparison function to {−1, 0, 1} and some don't?

From Dev

why we are not using semicolon after header files

From Dev

Typescript why can't return header in function?

From

Why are #ifndef and #define used in C++ header files?

From Dev

Why is a template parameter or return type of a function declaration not instantiated?

From Dev

Duplicate class declaration in the header files

From Dev

why cant I define a global function in a header file?

From Javascript

What do empty parentheses () after a function declaration do in javascript?

From Dev

Why do cv-qualifiers get removed from function return type in some cases?

From Dev

Why do some C compilers set the return value of a function in weird places?

From Dev

Install matching Linux header files after Linux kernel upgrade

From Dev

Missing function's return type declaration - do declarations increate efficiency

From Dev

Why do variable in an inner function return nan when there is the same variable name at the inner function declared after log

Related Related

  1. 1

    Why do some js files begin with (function() {

  2. 2

    Why is it not advised to define macros in header files?

  3. 3

    Why do some Linux files have a 'd' suffix?

  4. 4

    Why do some files names in Linux start with numbers?

  5. 5

    How do you define functions in header files?

  6. 6

    Why return value from a function following local declaration in bash is always 0?

  7. 7

    Why does this Solidity function return a 0 after assert?

  8. 8

    Why do some functions have underscores "__" before and after the function name?

  9. 9

    Why do some functions have underscores "__" before and after the function name?

  10. 10

    C: Why do we include header files, which declare but don't define?

  11. 11

    Why do some files of working packages return "not found" for some libraries of ldd's output?

  12. 12

    using declaration in header files

  13. 13

    Shell, bash, linux ; after variable declaration, why semi-colon and what does it do?

  14. 14

    Why do some people define objects as pointers?

  15. 15

    Calling function with no declaration in header

  16. 16

    Why does this function return 0

  17. 17

    Why do some comparable classes in the JDK limit the comparison function to {−1, 0, 1} and some don't?

  18. 18

    why we are not using semicolon after header files

  19. 19

    Typescript why can't return header in function?

  20. 20

    Why are #ifndef and #define used in C++ header files?

  21. 21

    Why is a template parameter or return type of a function declaration not instantiated?

  22. 22

    Duplicate class declaration in the header files

  23. 23

    why cant I define a global function in a header file?

  24. 24

    What do empty parentheses () after a function declaration do in javascript?

  25. 25

    Why do cv-qualifiers get removed from function return type in some cases?

  26. 26

    Why do some C compilers set the return value of a function in weird places?

  27. 27

    Install matching Linux header files after Linux kernel upgrade

  28. 28

    Missing function's return type declaration - do declarations increate efficiency

  29. 29

    Why do variable in an inner function return nan when there is the same variable name at the inner function declared after log

HotTag

Archive