Skip to content

Commit 0ab1438

Browse files
committed
linux/kconfig.h: replace IF_ENABLED() with PTR_IF() in <linux/kernel.h>
<linux/kconfig.h> is included from all the kernel-space source files, including C, assembly, linker scripts. It is intended to contain a minimal set of macros to evaluate CONFIG options. IF_ENABLED() is an intruder here because (x ? y : z) is C code, which should not be included from assembly files or linker scripts. Also, <linux/kconfig.h> is no longer self-contained because NULL is defined in <linux/stddef.h>. Move IF_ENABLED() out to <linux/kernel.h> as PTR_IF(). PTF_IF() takes the general boolean expression instead of a CONFIG option so that it fits better in <linux/kernel.h>. Signed-off-by: Masahiro Yamada <[email protected]> Reviewed-by: Kees Cook <[email protected]>
1 parent 51eb95e commit 0ab1438

File tree

3 files changed

+5
-6
lines changed

3 files changed

+5
-6
lines changed

drivers/pinctrl/pinctrl-ingenic.c

+3
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include <linux/gpio/driver.h>
1212
#include <linux/interrupt.h>
1313
#include <linux/io.h>
14+
#include <linux/kernel.h>
1415
#include <linux/of_device.h>
1516
#include <linux/of_irq.h>
1617
#include <linux/of_platform.h>
@@ -3854,6 +3855,8 @@ static int __init ingenic_pinctrl_probe(struct platform_device *pdev)
38543855
return 0;
38553856
}
38563857

3858+
#define IF_ENABLED(cfg, ptr) PTR_IF(IS_ENABLED(cfg), (ptr))
3859+
38573860
static const struct of_device_id ingenic_pinctrl_of_match[] = {
38583861
{
38593862
.compatible = "ingenic,jz4730-pinctrl",

include/linux/kconfig.h

-6
Original file line numberDiff line numberDiff line change
@@ -70,10 +70,4 @@
7070
*/
7171
#define IS_ENABLED(option) __or(IS_BUILTIN(option), IS_MODULE(option))
7272

73-
/*
74-
* IF_ENABLED(CONFIG_FOO, ptr) evaluates to (ptr) if CONFIG_FOO is set to 'y'
75-
* or 'm', NULL otherwise.
76-
*/
77-
#define IF_ENABLED(option, ptr) (IS_ENABLED(option) ? (ptr) : NULL)
78-
7973
#endif /* __LINUX_KCONFIG_H */

include/linux/kernel.h

+2
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@
4848
*/
4949
#define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]) + __must_be_array(arr))
5050

51+
#define PTR_IF(cond, ptr) ((cond) ? (ptr) : NULL)
52+
5153
#define u64_to_user_ptr(x) ( \
5254
{ \
5355
typecheck(u64, (x)); \

0 commit comments

Comments
 (0)