From patchwork Tue May 28 11:43:21 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexandre Belloni X-Patchwork-Id: 2624141 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork1.kernel.org Received: from casper.infradead.org (casper.infradead.org [85.118.1.10]) by patchwork1.kernel.org (Postfix) with ESMTP id 4D8BC40077 for ; Tue, 28 May 2013 11:45:13 +0000 (UTC) Received: from merlin.infradead.org ([2001:4978:20e::2]) by casper.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1UhIKX-0003IC-J8; Tue, 28 May 2013 11:44:42 +0000 Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1UhIKM-0003YU-PN; Tue, 28 May 2013 11:44:30 +0000 Received: from mail.free-electrons.com ([94.23.35.102]) by merlin.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1UhIKA-0003W3-RH for linux-arm-kernel@lists.infradead.org; Tue, 28 May 2013 11:44:20 +0000 Received: by mail.free-electrons.com (Postfix, from userid 106) id 51CC8E48; Tue, 28 May 2013 13:44:01 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on mail.free-electrons.com X-Spam-Level: X-Spam-Status: No, score=-1.0 required=5.0 tests=ALL_TRUSTED,SHORTCIRCUIT, URIBL_BLOCKED shortcircuit=ham autolearn=disabled version=3.3.2 Received: from localhost (128-79-216-144.hfc.dyn.abo.bbox.fr [128.79.216.144]) by mail.free-electrons.com (Postfix) with ESMTPSA id C37767BD; Tue, 28 May 2013 13:44:00 +0200 (CEST) From: Alexandre Belloni To: netdev@vger.kernel.org Subject: [PATCHv2 1/3] net: phy: prevent linking breakage Date: Tue, 28 May 2013 13:43:21 +0200 Message-Id: <1369741403-25315-2-git-send-email-alexandre.belloni@free-electrons.com> X-Mailer: git-send-email 1.8.1.2 In-Reply-To: <1369741403-25315-1-git-send-email-alexandre.belloni@free-electrons.com> References: <1369741403-25315-1-git-send-email-alexandre.belloni@free-electrons.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20130528_074419_123813_8B8F27FA X-CRM114-Status: GOOD ( 14.24 ) X-Spam-Score: -3.0 (---) X-Spam-Report: SpamAssassin version 3.3.2 on merlin.infradead.org summary: Content analysis details: (-3.0 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 SPF_PASS SPF: sender matches SPF record -1.1 RP_MATCHES_RCVD Envelope sender domain matches handover relay domain -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] Cc: Russell King , linux-kernel@vger.kernel.org, Alexandre Belloni , Sascha Hauer , Shawn Guo , linux-arm-kernel@lists.infradead.org X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org phy_register_fixup{,_for_uid,_for_id} are called from arch/, quite often, there is no protection to check whether CONFIG_PHYLIB=y which is the only case where this would work. Having phylib as a module or not compiled at all will result in that kind of linking failure: arch/arm/mach-at91/built-in.o: In function `ksz9021rn_phy_fixup': :(.text+0x1174): undefined reference to `mdiobus_write' :(.text+0x1188): undefined reference to `mdiobus_write' :(.text+0x119c): undefined reference to `mdiobus_write' :(.text+0x11b0): undefined reference to `mdiobus_write' arch/arm/mach-at91/built-in.o: In function `sama5_dt_device_init': :(.init.text+0x1e34): undefined reference to `phy_register_fixup_for_uid' Signed-off-by: Alexandre Belloni --- drivers/net/phy/phy_device.c | 6 ++++++ include/linux/phy.h | 33 ++++++++++++++++++++++++++++++--- 2 files changed, 36 insertions(+), 3 deletions(-) diff --git a/drivers/net/phy/phy_device.c b/drivers/net/phy/phy_device.c index 3657b4a..df36367 100644 --- a/drivers/net/phy/phy_device.c +++ b/drivers/net/phy/phy_device.c @@ -64,6 +64,11 @@ static int phy_attach_direct(struct net_device *dev, struct phy_device *phydev, u32 flags, phy_interface_t interface); /* + * phy_register_fixup{,_for_uid,_for_id} are called from arch/ so this won't + * work unless phylib is compiled in the kernel. + */ +#ifdef CONFIG_PHYLIB +/* * Creates a new phy_fixup and adds it to the list * @bus_id: A string which matches phydev->dev.bus_id (or PHY_ANY_ID) * @phy_uid: Used to match against phydev->phy_id (the UID of the PHY) @@ -109,6 +114,7 @@ int phy_register_fixup_for_id(const char *bus_id, return phy_register_fixup(bus_id, PHY_ANY_UID, 0xffffffff, run); } EXPORT_SYMBOL(phy_register_fixup_for_id); +#endif /* CONFIG_PHYLIB */ /* * Returns 1 if fixup matches phydev in bus_id and phy_uid. diff --git a/include/linux/phy.h b/include/linux/phy.h index 9e11039..2cc3383 100644 --- a/include/linux/phy.h +++ b/include/linux/phy.h @@ -556,12 +556,39 @@ int phy_start_interrupts(struct phy_device *phydev); void phy_print_status(struct phy_device *phydev); void phy_device_free(struct phy_device *phydev); +/* + * phy_register_fixup{,_for_uid,_for_id} are called from arch/ so this won't + * work unless phylib is compiled in the kernel. + * Defining stubs allows to prevent linking errors. + */ +#ifdef CONFIG_PHYLIB int phy_register_fixup(const char *bus_id, u32 phy_uid, u32 phy_uid_mask, - int (*run)(struct phy_device *)); + int (*run)(struct phy_device *)); int phy_register_fixup_for_id(const char *bus_id, - int (*run)(struct phy_device *)); + int (*run)(struct phy_device *)); int phy_register_fixup_for_uid(u32 phy_uid, u32 phy_uid_mask, - int (*run)(struct phy_device *)); + int (*run)(struct phy_device *)); +#else +static inline int phy_register_fixup(const char *bus_id, u32 phy_uid, + u32 phy_uid_mask, + int (*run)(struct phy_device *)) +{ + return -ENOTSUPP; +} + +static inline int phy_register_fixup_for_id(const char *bus_id, + int (*run)(struct phy_device *)) +{ + return -ENOTSUPP; +} + +static inline int phy_register_fixup_for_uid(u32 phy_uid, u32 phy_uid_mask, + int (*run)(struct phy_device *)) +{ + return -ENOTSUPP; +} +#endif /* CONFIG_PHYLIB */ + int phy_scan_fixups(struct phy_device *phydev); int phy_init_eee(struct phy_device *phydev, bool clk_stop_enable);