CONFIG_COMPILE_TEST: additional examples and checkpatch rule
Subsystems (3)
cover CONFIG_COMPILE_TEST: additional examples and checkpatch rule
I only just noticed the existence of CONFIG_COMPILE_TEST (now in mainline as of merge fc76a258d41 ("Merge tag 'driver-core-3.11-rc1' ofgit://git.kernel.org/pub/scm/linux/kernel/git/gregkh/driver-core")
I like this; it parallels a discussion I had with Andrew a while ago:
https://lkml.org/lkml/2013/3/7/456
I wish I had seen it earlier, as at the moment it only has three use case instances/examples. I have at my fingertips three more that were cases where I wanted to add a real world dependency that limited the option to those who it was useful to, but the rebuttals I got were that the maintainers liked the compile coverage (see links in each commmit.)
It might be nice to have a few more examples showing proper dependency usage of COMPILE_TEST, if the opportunity arises. In the same vein as having more available examples, we can teach checkpatch to spot when people incorrectly try and use this in C (as has already happened.) It might help avoid doing that education campaign via lkml lessons.
That said, I realize we are well into week one of the merge window, so if need be, it isn't a problem for me to hang on to them for 3.12.
Thanks,
Paul.
---
[I made a temporary bad commit to test the new checkpatch rule. I [also build tested for OMAP2 with USB options on & COMPILE_TEST off]
Paul Gortmaker (4):
usb: limit OMAP related USB options to OMAP2PLUS platforms
power: make goldfish_battery depend on GOLDFISH || COMPILE_TEST
video: make goldfish video depend on GOLDFISH || COMPILE_TEST
checkpatch: only allow COMPILE_TEST in Kconfig dependency lines
drivers/power/Kconfig | 2 +- drivers/usb/phy/Kconfig | 2 ++ drivers/video/Kconfig | 2 +- scripts/checkpatch.pl | 6 ++++++ 4 files changed, 10 insertions(+), 2 deletions(-)
Signature · 1 line
1.8.1.2
PATCH 1/4 usb: limit OMAP related USB options to OMAP2PLUS platforms
commit 57f6ce072e35770a63be0c5d5e82f90d8da7d665 ("usb: phy:
add a new driver for usb3 phy") added the new Kconfig option OMAP_USB3, but it had no dependencies whatsoever, and hence became available across all arch/platforms.
Which presumably caused this to show up in x86 randconfig:
warning: (USB_MUSB_HDRC && OMAP_USB3) selects \
OMAP_CONTROL_USB which has unmet direct \
dependencies (USB_SUPPORT && ARCH_OMAP2PLUS)Then commit 6992819feb39cb9adac72170555d957d07f869f2 ("usb: phy:
fix Kconfig warning") was added. However, this just deleted the ARCH_OMAP2PLUS dependency from OMAP_CONTROL_USB, further compounding the problem by opening up OMAP_CONTROL_USB to all arch/platforms as well.
Earlier it was suggested[1] that we revert the change of 6992819feb to restore the dependency, and add a same ARCH_OMAP2PLUS dependency to the new OMAP_USB3 entry. However that was discouraged on the grounds of people wanting the extra sanity compile testing on x86, even though the driver could probably never be used there.
Now we have CONFIG_COMPILE_TEST, so developers who value the ability to compile drivers on an architecture that it never can be used for can have that, and people who want dependencies to shield them from seeing options that aren't relevant to their platform get what they want too.
Here we restore the dependency but couple it with COMPILE_TEST, in order to achieve both of the above goals.
[1] https://patchwork.kernel.org/patch/2194511/
--- drivers/usb/phy/Kconfig | 2 ++ 1 file changed, 2 insertions(+)
drivers/usb/phy/Kconfig +2 -0
@@ -65,6 +65,7 @@ config NOP_USB_XCEIV config OMAP_CONTROL_USB tristate "OMAP CONTROL USB Driver" + depends on ARCH_OMAP2PLUS || COMPILE_TEST help Enable this to add support for the USB part present in the control module. This driver has API to power on the USB2 PHY and to write to
@@ -84,6 +85,7 @@ config OMAP_USB2 config OMAP_USB3 tristate "OMAP USB3 PHY Driver" + depends on ARCH_OMAP2PLUS || COMPILE_TEST select OMAP_CONTROL_USB help Enable this to support the USB3 PHY that is part of SOC. This
Signature · 1 line
1.8.1.2
Re: [PATCH 1/4] usb: limit OMAP related USB options to OMAP2PLUS platforms
Quoted 32 lines · Paul Gortmaker
commit
57f6ce072e35770a63be0c5d5e82f90d8da7d665("usb: phy:
add a new driver for usb3 phy") added the newKconfigoptionOMAP_USB3, but it had no dependencies whatsoever, and hence became available across allarch/platforms.Which presumably caused this to show up in x86 randconfig:
warning: (USB_MUSB_HDRC && OMAP_USB3) selects \ OMAP_CONTROL_USB which has unmet direct \ dependencies (USB_SUPPORT && ARCH_OMAP2PLUS)Then commit
6992819feb39cb9adac72170555d957d07f869f2("usb: phy:
fixKconfigwarning") was added. However, this just deleted theARCH_OMAP2PLUSdependency fromOMAP_CONTROL_USB, further compounding the problem by opening upOMAP_CONTROL_USBto allarch/platformsas well.Earlier it was suggested[1] that we revert the change of
6992819febto restore the dependency, and add a sameARCH_OMAP2PLUSdependency to the newOMAP_USB3entry. However that was discouraged on the grounds of people wanting the extra sanity compile testing on x86, even though the driver could probably never be used there.Now we have
CONFIG_COMPILE_TEST, so developers who value the ability to compile drivers on an architecture that it never can be used for can have that, and people who want dependencies to shield them from seeing options that aren't relevant to their platform get what they want too.Here we restore the dependency but couple it with
COMPILE_TEST, in order to achieve both of the above goals.
Quoted 8 lines
[1] https://patchwork.kernel.org/patch/2194511/
Cc Felipe Balbi <[email protected]>Cc Kishon Vijay Abraham I <[email protected]>Cc Moiz Sonasath <[email protected]>Cc Jiri Slaby <[email protected]>Cc Greg Kroah-Hartman <[email protected]>Signed-off-by Paul Gortmaker <[email protected]>
Signature · 1 line
balbi
PATCH 2/4 power: make goldfish_battery depend on GOLDFISH || COMPILE_TEST
In reply to Paul GortmakerNearly all the other goldfish peripherals (mtd, keyboard, etc) have a dependency on the main platform's GOLDFISH Kconfig item, but this one got skipped. Even with consistency as a justification, there was initial resistance[1] from some people to adding it however, as they wanted the extra compile coverage.
Now, with CONFIG_COMPILE_TEST, we have the middle ground that will give people the coverage who want it, and let those who don't want it to skip ever seeing the option presented.
[1] https://lkml.org/lkml/2013/2/27/333
--- drivers/power/Kconfig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/power/Kconfig +1 -1
@@ -357,7 +357,7 @@ config AB8500_BM config BATTERY_GOLDFISH tristate "Goldfish battery driver" - depends on GENERIC_HARDIRQS + depends on GENERIC_HARDIRQS && (GOLDFISH || COMPILE_TEST) help Say Y to enable support for the battery and AC power in the Goldfish emulator.
Signature · 1 line
1.8.1.2
Re: [PATCH 2/4] power: make goldfish_battery depend on GOLDFISH || COMPILE_TEST
Quoted 10 lines · Paul Gortmaker
Nearly all the other goldfish peripherals (mtd, keyboard, etc) have a dependency on the main platform's GOLDFISH
Kconfigitem, but this one got skipped. Even with consistency as a justification, there was initial resistance[1] from some people to adding it however, as they wanted the extra compile coverage.Now, with
CONFIG_COMPILE_TEST, we have the middle ground that will give people the coverage who want it, and let those who don't want it to skip ever seeing the option presented.
Quoted 8 lines
[1] https://lkml.org/lkml/2013/2/27/333
Cc Anton Vorontsov <[email protected]>Cc David Woodhouse <[email protected]>Cc Jiri Slaby <[email protected]>Cc Greg Kroah-Hartman <[email protected]>Signed-off-by Paul Gortmaker <[email protected]>---
So, CONFIG_AKPM... kinda. :) It works for me. Applied, thank you!
Anton
PATCH 3/4 video: make goldfish video depend on GOLDFISH || COMPILE_TEST
In reply to Paul GortmakerNearly all the other goldfish peripherals (mtd, keyboard, etc) have a dependency on the main platform's GOLDFISH Kconfig item, but this one got skipped. It was suggested to add it earlier[1], but that never got responded to or picked up -- presumably because some developers desired the extra compile coverage at the cost of exposing unusable options to end users.
With CONFIG_COMPILE_TEST, we can have the best of both worlds. Add the GOLDFISH dependency, in conjunction with COMPILE_TEST.
[1] https://lkml.org/lkml/2013/2/27/169
--- drivers/video/Kconfig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/video/Kconfig +1 -1
@@ -2199,7 +2199,7 @@ config FB_XILINX config FB_GOLDFISH tristate "Goldfish Framebuffer" - depends on FB && HAS_DMA + depends on FB && HAS_DMA && (GOLDFISH || COMPILE_TEST) select FB_CFB_FILLRECT select FB_CFB_COPYAREA select FB_CFB_IMAGEBLIT
Signature · 1 line
1.8.1.2
PATCH 4/4 checkpatch: only allow COMPILE_TEST in Kconfig dependency lines
In reply to Paul GortmakerThe option CONFIG_COMPILE_TEST, added in commit 4bb1667255a ("build some drivers only when compile-testing") is meant to give a middle ground[1] between those who want the widest compile coverage possible (e.g. building sparc drivers for mips) and those who want dependencies to represent real world systems (e.g. don't allow me to see OMAP options when building x86).
As such, this addition is meant to be used in dependency lines, properly or'd in with the real world hardware dependency. Those who select it, get wide compile coverage. Those who do not, get real world dependencies that match where the hardware is available and/or where the driver is useful.
With that in mind, it is clear that this is _not_ to be used in any C code with "#ifdef CONFIG_COMPILE_TEST" etc. However there will (and already has been) instances of people thinking this is an OK practice[2]. So teach checkpatch to spot them as an error.
[1] https://lkml.org/lkml/2013/3/7/456
[2] https://lkml.org/lkml/2013/7/1/641
--- scripts/checkpatch.pl | 6 ++++++ 1 file changed, 6 insertions(+)
scripts/checkpatch.pl +6 -0
@@ -1922,6 +1922,12 @@ sub process { "Use of CONFIG_EXPERIMENTAL is deprecated. For alternatives, see https://lkml.org/lkml/2012/10/23/580\n"); } +# disallow the addition of CONFIG_COMPILE_TEST in #if(def). + if ($line =~ /^\+\s*\#\s*if.*\bCONFIG_COMPILE_TEST\b/) { + ERROR("CONFIG_COMPILE_TEST", + "Use of COMPILE_TEST is only allowed in Kconfig dependency lines.\n"); + } + # check for RCS/CVS revision markers if ($rawline =~ /^\+.*\$(Revision|Log|Id)(?:\$|)/) { WARN("CVS_KEYWORD",
Signature · 1 line
1.8.1.2
Re: [PATCH 4/4] checkpatch: only allow COMPILE_TEST in Kconfig dependency lines
Quoted 4 lines · Paul Gortmaker
With that in mind, it is clear that this is _not_ to be used in any C code with "#ifdef
CONFIG_COMPILE_TEST" etc. However there will (and already has been) instances of people thinking this is an OK practice[2]. So teach checkpatch to spot them as an error.
Gr{oetje,eeting}s,
Geert
--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]
In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds
Re: [PATCH 4/4] checkpatch: only allow COMPILE_TEST in Kconfig dependency lines
In reply to Paul GortmakerQuoted 21 lines · Paul Gortmaker
The option
CONFIG_COMPILE_TEST, added in commit4bb1667255a("build some drivers only when compile-testing") is meant to give a middle ground[1] between those who want the widest compile coverage possible (e.g. building sparc drivers for mips) and those who want dependencies to represent real world systems (e.g. don't allow me to see OMAP options when building x86).As such, this addition is meant to be used in dependency lines, properly or'd in with the real world hardware dependency. Those who select it, get wide compile coverage. Those who do not, get real world dependencies that match where the hardware is available and/or where the driver is useful.
With that in mind, it is clear that this is _not_ to be used in any C code with "#ifdef
CONFIG_COMPILE_TEST" etc. However there will (and already has been) instances of people thinking this is an OK practice[2]. So teach checkpatch to spot them as an error.[1] https://lkml.org/lkml/2013/3/7/456
[2] https://lkml.org/lkml/2013/7/1/641
Quoted 7 lines
Cc Joe Perches <[email protected]>Cc Andy Whitcroft <[email protected]>Cc Arnd Bergmann <[email protected]>Cc Geert Uytterhoeven <[email protected]>Cc Jiri Slaby <[email protected]>Cc Greg Kroah-Hartman <[email protected]>Signed-off-by Paul Gortmaker <[email protected]>
Joe Perches
maintainerRe: [PATCH 4/4] checkpatch: only allow COMPILE_TEST in Kconfig dependency lines
In reply to Paul GortmakerQuoted 37 lines · Paul Gortmaker
The option
CONFIG_COMPILE_TEST, added in commit4bb1667255a("build some drivers only when compile-testing") is meant to give a middle ground[1] between those who want the widest compile coverage possible (e.g. building sparc drivers for mips) and those who want dependencies to represent real world systems (e.g. don't allow me to see OMAP options when building x86).As such, this addition is meant to be used in dependency lines, properly or'd in with the real world hardware dependency. Those who select it, get wide compile coverage. Those who do not, get real world dependencies that match where the hardware is available and/or where the driver is useful.
With that in mind, it is clear that this is _not_ to be used in any C code with "#ifdef
CONFIG_COMPILE_TEST" etc. However there will (and already has been) instances of people thinking this is an OK practice[2]. So teach checkpatch to spot them as an error.[1] https://lkml.org/lkml/2013/3/7/456
[2] https://lkml.org/lkml/2013/7/1/641Cc Joe Perches <[email protected]>Cc Andy Whitcroft <[email protected]>Cc Arnd Bergmann <[email protected]>Cc Geert Uytterhoeven <[email protected]>Cc Jiri Slaby <[email protected]>Cc Greg Kroah-Hartman <[email protected]>Signed-off-by Paul Gortmaker <[email protected]>--- scripts/checkpatch.pl | 6 ++++++ 1 file changed, 6 insertions(+)scripts/checkpatch.pl +0
-0
scripts/checkpatch.pl sub process { · line 1928
Quoted 7 lines
scripts/checkpatch.pl +4
-0@@ -1922,6 +1922,12 @@ sub process { "Use of CONFIG_EXPERIMENTAL is deprecated. For alternatives, see https://lkml.org/lkml/2012/10/23/580\n"); } +# disallow the addition of CONFIG_COMPILE_TEST in #if(def). + if ($line =~ /^\+\s*\#\s*if.*\bCONFIG_COMPILE_TEST\b/) { + ERROR("CONFIG_COMPILE_TEST", + "Use of COMPILE_TEST is only allowed in Kconfig dependency lines.\n");
Why not just look for \bCONFIG_COMPILE_TEST\b?
I see it's the same style as the CONFIG_EXPERIMENTAL above it, but perhaps code could be written like
#if defined CONFIG_FOO || \
defined CONFIG_BAR
and this wouldn't trigger.
Re: [PATCH 4/4] checkpatch: only allow COMPILE_TEST in Kconfig dependency lines
Quoted 48 lines · [Re: [PATCH 4/4] checkpatch: only allow COMPILE_TEST in Kconfig dependency…
Quoted 37 lines · Paul Gortmaker
The option
CONFIG_COMPILE_TEST, added in commit4bb1667255a("build some drivers only when compile-testing") is meant to give a middle ground[1] between those who want the widest compile coverage possible (e.g. building sparc drivers for mips) and those who want dependencies to represent real world systems (e.g. don't allow me to see OMAP options when building x86).As such, this addition is meant to be used in dependency lines, properly or'd in with the real world hardware dependency. Those who select it, get wide compile coverage. Those who do not, get real world dependencies that match where the hardware is available and/or where the driver is useful.
With that in mind, it is clear that this is _not_ to be used in any C code with "#ifdef
CONFIG_COMPILE_TEST" etc. However there will (and already has been) instances of people thinking this is an OK practice[2]. So teach checkpatch to spot them as an error.[1] https://lkml.org/lkml/2013/3/7/456
[2] https://lkml.org/lkml/2013/7/1/641Cc Joe Perches <[email protected]>Cc Andy Whitcroft <[email protected]>Cc Arnd Bergmann <[email protected]>Cc Geert Uytterhoeven <[email protected]>Cc Jiri Slaby <[email protected]>Cc Greg Kroah-Hartman <[email protected]>Signed-off-by Paul Gortmaker <[email protected]>--- scripts/checkpatch.pl | 6 ++++++ 1 file changed, 6 insertions(+)scripts/checkpatch.pl +0
-0scripts/checkpatch.pl sub process { · line 1928
Quoted 7 lines
scripts/checkpatch.pl +4
-0@@ -1922,6 +1922,12 @@ sub process { "Use of CONFIG_EXPERIMENTAL is deprecated. For alternatives, see https://lkml.org/lkml/2012/10/23/580\n"); } +# disallow the addition of CONFIG_COMPILE_TEST in #if(def). + if ($line =~ /^\+\s*\#\s*if.*\bCONFIG_COMPILE_TEST\b/) { + ERROR("CONFIG_COMPILE_TEST", + "Use of COMPILE_TEST is only allowed in Kconfig dependency lines.\n");Why not just look for \bCONFIG_COMPILE_TEST\b?
Quoted 2 lines
I see it's the same style as the
CONFIG_EXPERIMENTALabove it, but perhaps code could be written like
That is exactly why. I valued consistency and the fact that this was already a tested and working check, vs. me reinventing my own and then having a "Oh crap, I never thought of that false positive" moment.
I'd suggest leaving it consistent with the existing solution as lowest risk and then later (post 3.11) you could come along and recode all similar instances to increase their scope if you really wanted to.
P.
--
Quoted 7 lines
#if defined
CONFIG_FOO|| \
definedCONFIG_BARand this wouldn't trigger.