为什么有些linux头文件在声明后定义一个函数到return0?

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

我正在查看 Linux 4.14 内核的 include/linux/clk.h 文件,并注意到一些函数已声明,然后定义为 return 0 或 NULL。

例如:

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

这样做的目的是什么?我看到多个 C 源文件完全定义了这个函数并且仍然包含 linux/clk.h.

Linux 内核带有很多配置参数。对于此特定功能,如果定义了 CONFIG_HAVE_CLK 参数,您将获得服务:

#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;
}
[...]

此参数在arch/Kconfig中定义为:

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.