2012-10-01 12:27:32

by Anisse Astier

[permalink] [raw]
Subject: [PATCH 1/2] kconfig: Introduce IS_DEPENDENCY_SATISFIED()

Most of the time, when we use IS_ENABLED() it's to specify a dependency
on a config option that might be enabled. But if this option is enabled
as a module, and we are built-in, then we'll have missing symbols.

This new macro is therefore useful to specify a dependency on another
config. But it also needs to know our own config option in order to
check if the dependency is properly satisfied.

IS_DEPENDENCY_SATISFIED(CONFIG_SELF, CONFIG_FOO) evaluates to 1 if
CONFIG_FOO is set to 'y' or 'm', and set the same as CONFIG_SELF. It
evaluates to 0 otherwise.

Signed-off-by: Anisse Astier <[email protected]>
---
include/linux/kconfig.h | 10 ++++++++++
1 file changed, 10 insertions(+)

diff --git a/include/linux/kconfig.h b/include/linux/kconfig.h
index be342b9..8b8ec1f 100644
--- a/include/linux/kconfig.h
+++ b/include/linux/kconfig.h
@@ -43,4 +43,14 @@
*/
#define IS_MODULE(option) config_enabled(option##_MODULE)

+
+/*
+ * IS_DEPENDENCY_SATISFIED(CONFIG_SELF, CONFIG_FOO) evaluates to 1 if
+ * CONFIG_FOO is set to 'y' or 'm', and set the same as CONFIG_SELF.
+ * Useful for specifying build-time config dependencies.
+ */
+#define IS_DEPENDENCY_SATISFIED(self, dependency) \
+ ((config_enabled(self) && config_enabled(dependency)) || \
+ (config_enabled(self##_MODULE) && config_enabled(dependency##_MODULE)))
+
#endif /* __LINUX_KCONFIG_H */
--
1.7.10.3


2012-10-01 12:27:36

by Anisse Astier

[permalink] [raw]
Subject: [PATCH 2/2] tg3: fix build-time dependency with IS_DEPENDENCY_SATISFIED()

When CONFIG_TIGON3=y and CONFIG_HWMON=y, we will get this error:
LD init/built-in.o
drivers/built-in.o: In function `tg3_hwmon_open':
tg3.c:(.text+0xc1d12): undefined reference to `hwmon_device_register'
drivers/built-in.o: In function `tg3_close':
tg3.c:(.text+0xc2e7f): undefined reference to `hwmon_device_unregister'
make: *** [vmlinux] Error 1

Use the new IS_DEPENDENCY_SATISFIED() facility to solve this problem.

Signed-off-by: Anisse Astier <[email protected]>
---
drivers/net/ethernet/broadcom/tg3.c | 8 ++++----
drivers/net/ethernet/broadcom/tg3.h | 2 +-
2 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/drivers/net/ethernet/broadcom/tg3.c b/drivers/net/ethernet/broadcom/tg3.c
index bf906c5..cc81a59 100644
--- a/drivers/net/ethernet/broadcom/tg3.c
+++ b/drivers/net/ethernet/broadcom/tg3.c
@@ -44,7 +44,7 @@
#include <linux/prefetch.h>
#include <linux/dma-mapping.h>
#include <linux/firmware.h>
-#if IS_ENABLED(CONFIG_HWMON)
+#if IS_DEPENDENCY_SATISFIED(CONFIG_TIGON3, CONFIG_HWMON)
#include <linux/hwmon.h>
#include <linux/hwmon-sysfs.h>
#endif
@@ -9517,7 +9517,7 @@ static int tg3_init_hw(struct tg3 *tp, int reset_phy)
return tg3_reset_hw(tp, reset_phy);
}

-#if IS_ENABLED(CONFIG_HWMON)
+#if IS_DEPENDENCY_SATISFIED(CONFIG_TIGON3, CONFIG_HWMON)
static void tg3_sd_scan_scratchpad(struct tg3 *tp, struct tg3_ocir *ocir)
{
int i;
@@ -9574,7 +9574,7 @@ static const struct attribute_group tg3_group = {

static void tg3_hwmon_close(struct tg3 *tp)
{
-#if IS_ENABLED(CONFIG_HWMON)
+#if IS_DEPENDENCY_SATISFIED(CONFIG_TIGON3, CONFIG_HWMON)
if (tp->hwmon_dev) {
hwmon_device_unregister(tp->hwmon_dev);
tp->hwmon_dev = NULL;
@@ -9585,7 +9585,7 @@ static void tg3_hwmon_close(struct tg3 *tp)

static void tg3_hwmon_open(struct tg3 *tp)
{
-#if IS_ENABLED(CONFIG_HWMON)
+#if IS_DEPENDENCY_SATISFIED(CONFIG_TIGON3, CONFIG_HWMON)
int i, err;
u32 size = 0;
struct pci_dev *pdev = tp->pdev;
diff --git a/drivers/net/ethernet/broadcom/tg3.h b/drivers/net/ethernet/broadcom/tg3.h
index 6d52cb2..867dae1 100644
--- a/drivers/net/ethernet/broadcom/tg3.h
+++ b/drivers/net/ethernet/broadcom/tg3.h
@@ -3252,7 +3252,7 @@ struct tg3 {
const struct firmware *fw;
u32 fw_len; /* includes BSS */

-#if IS_ENABLED(CONFIG_HWMON)
+#if IS_DEPENDENCY_SATISFIED(CONFIG_TIGON3, CONFIG_HWMON)
struct device *hwmon_dev;
#endif
};
--
1.7.10.3

2012-10-01 16:11:16

by Paul Gortmaker

[permalink] [raw]
Subject: Re: [PATCH 2/2] tg3: fix build-time dependency with IS_DEPENDENCY_SATISFIED()

[[PATCH 2/2] tg3: fix build-time dependency with IS_DEPENDENCY_SATISFIED()] On 01/10/2012 (Mon 14:21) Anisse Astier wrote:

> When CONFIG_TIGON3=y and CONFIG_HWMON=y, we will get this error:
> LD init/built-in.o
> drivers/built-in.o: In function `tg3_hwmon_open':
> tg3.c:(.text+0xc1d12): undefined reference to `hwmon_device_register'
> drivers/built-in.o: In function `tg3_close':
> tg3.c:(.text+0xc2e7f): undefined reference to `hwmon_device_unregister'
> make: *** [vmlinux] Error 1
>
> Use the new IS_DEPENDENCY_SATISFIED() facility to solve this problem.

Even though my fingerprints may be on IS_ENABLED, I'm not a fan of using
it (or things like this extension) all over the place for #ifdef blocks
that can be avoided some other clean way.

How about we just fix this the way Dave suggested a few months ago?

P.

--

>From e7c432cf5eb44b188c1aa2b188877c42300de8b9 Mon Sep 17 00:00:00 2001
From: Paul Gortmaker <[email protected]>
Date: Mon, 1 Oct 2012 11:43:49 -0400
Subject: [PATCH] tg3: unconditionally select HWMON support when tg3 is
enabled.

There is the seldom used corner case where HWMON=m at the same
time as TIGON3=y (typically randconfigs) which will cause a link
fail like:

drivers/built-in.o: In function `tg3_close':
tg3.c:(.text+0x16bd86): undefined reference to `hwmon_device_unregister'
drivers/built-in.o: In function `tg3_hwmon_open':
tg3.c:(.text+0x16fc4b): undefined reference to `hwmon_device_register'
make[1]: *** [vmlinux] Error 1

Fix it as suggested by DaveM[1] by having the Kconfig logic simply
select HWMON when TIGON3 is selected. This gets rid of all the
extra IS_ENABLED ifdeffery in tg3.c as a side benefit.

[1] http://marc.info/?l=linux-netdev&m=134250573718151&w=2

Cc: Michael Chan <[email protected]>
Reported-by: Benjamin Herrenschmidt <[email protected]>
Reported-by: Anisse Astier <[email protected]>
Suggested-by: David S. Miller <[email protected]>
Signed-off-by: Paul Gortmaker <[email protected]>
---
drivers/net/ethernet/broadcom/Kconfig | 1 +
drivers/net/ethernet/broadcom/tg3.c | 9 ---------
2 files changed, 1 insertion(+), 9 deletions(-)

diff --git a/drivers/net/ethernet/broadcom/Kconfig b/drivers/net/ethernet/broadcom/Kconfig
index f15e72e..4bd416b 100644
--- a/drivers/net/ethernet/broadcom/Kconfig
+++ b/drivers/net/ethernet/broadcom/Kconfig
@@ -101,6 +101,7 @@ config TIGON3
tristate "Broadcom Tigon3 support"
depends on PCI
select PHYLIB
+ select HWMON
---help---
This driver supports Broadcom Tigon3 based gigabit Ethernet cards.

diff --git a/drivers/net/ethernet/broadcom/tg3.c b/drivers/net/ethernet/broadcom/tg3.c
index bf906c5..711eb14 100644
--- a/drivers/net/ethernet/broadcom/tg3.c
+++ b/drivers/net/ethernet/broadcom/tg3.c
@@ -44,10 +44,8 @@
#include <linux/prefetch.h>
#include <linux/dma-mapping.h>
#include <linux/firmware.h>
-#if IS_ENABLED(CONFIG_HWMON)
#include <linux/hwmon.h>
#include <linux/hwmon-sysfs.h>
-#endif

#include <net/checksum.h>
#include <net/ip.h>
@@ -9517,7 +9515,6 @@ static int tg3_init_hw(struct tg3 *tp, int reset_phy)
return tg3_reset_hw(tp, reset_phy);
}

-#if IS_ENABLED(CONFIG_HWMON)
static void tg3_sd_scan_scratchpad(struct tg3 *tp, struct tg3_ocir *ocir)
{
int i;
@@ -9570,22 +9567,17 @@ static const struct attribute_group tg3_group = {
.attrs = tg3_attributes,
};

-#endif
-
static void tg3_hwmon_close(struct tg3 *tp)
{
-#if IS_ENABLED(CONFIG_HWMON)
if (tp->hwmon_dev) {
hwmon_device_unregister(tp->hwmon_dev);
tp->hwmon_dev = NULL;
sysfs_remove_group(&tp->pdev->dev.kobj, &tg3_group);
}
-#endif
}

static void tg3_hwmon_open(struct tg3 *tp)
{
-#if IS_ENABLED(CONFIG_HWMON)
int i, err;
u32 size = 0;
struct pci_dev *pdev = tp->pdev;
@@ -9617,7 +9609,6 @@ static void tg3_hwmon_open(struct tg3 *tp)
dev_err(&pdev->dev, "Cannot register hwmon device, aborting\n");
sysfs_remove_group(&pdev->dev.kobj, &tg3_group);
}
-#endif
}


--
1.7.11.1

2012-10-01 21:45:40

by David Miller

[permalink] [raw]
Subject: Re: [PATCH 2/2] tg3: fix build-time dependency with IS_DEPENDENCY_SATISFIED()

From: Paul Gortmaker <[email protected]>
Date: Mon, 1 Oct 2012 12:10:59 -0400

> From e7c432cf5eb44b188c1aa2b188877c42300de8b9 Mon Sep 17 00:00:00 2001
> From: Paul Gortmaker <[email protected]>
> Date: Mon, 1 Oct 2012 11:43:49 -0400
> Subject: [PATCH] tg3: unconditionally select HWMON support when tg3 is
> enabled.
>
> There is the seldom used corner case where HWMON=m at the same
> time as TIGON3=y (typically randconfigs) which will cause a link
> fail like:
>
> drivers/built-in.o: In function `tg3_close':
> tg3.c:(.text+0x16bd86): undefined reference to `hwmon_device_unregister'
> drivers/built-in.o: In function `tg3_hwmon_open':
> tg3.c:(.text+0x16fc4b): undefined reference to `hwmon_device_register'
> make[1]: *** [vmlinux] Error 1
>
> Fix it as suggested by DaveM[1] by having the Kconfig logic simply
> select HWMON when TIGON3 is selected. This gets rid of all the
> extra IS_ENABLED ifdeffery in tg3.c as a side benefit.
>
> [1] http://marc.info/?l=linux-netdev&m=134250573718151&w=2
>
> Cc: Michael Chan <[email protected]>
> Reported-by: Benjamin Herrenschmidt <[email protected]>
> Reported-by: Anisse Astier <[email protected]>
> Suggested-by: David S. Miller <[email protected]>
> Signed-off-by: Paul Gortmaker <[email protected]>

Applied, thanks.