Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.1 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5988BC43387 for ; Wed, 16 Jan 2019 07:07:50 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 1F9BC2082F for ; Wed, 16 Jan 2019 07:07:50 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="NQ8FcvF5" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388357AbfAPHHt (ORCPT ); Wed, 16 Jan 2019 02:07:49 -0500 Received: from mail-wm1-f68.google.com ([209.85.128.68]:33475 "EHLO mail-wm1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731056AbfAPHHs (ORCPT ); Wed, 16 Jan 2019 02:07:48 -0500 Received: by mail-wm1-f68.google.com with SMTP id r24so268432wmh.0 for ; Tue, 15 Jan 2019 23:07:47 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:subject:to:cc:message-id:date:user-agent:mime-version :content-language:content-transfer-encoding; bh=QBGrmvcS7Oy8UgeLqWHR5Mdzi4HTInkk+4zc4dgPf7c=; b=NQ8FcvF5Y7/3RXF2fKYM3olk7kf9cZJIwq00CPsYCmPenkC2vQfLFSvdMv92tbozoh 1eNCX2tQURgIssCZ4jHHI5Sr3QZVShoyPKoxYIrnfX7BWqgvamf0ckpF95qBte7eyOjY r2fmwRzEuGALTveidVzh1dsU2LOGWLWAPwEambPff7w/Vn4SNVsXDhuFa2+sWX0T8pMc V9nmYLLZ1TAjlsYmpn2VNkEAO+g2bHTWw5hjnDHrXcNPsigFHtC9Evhm0+/PdgOy7KKY xTQKc6rV5as87KUe6xmzs68PWqBzV3l8qEsxTQCU7NUbMR4vwenf2FKHpyegVYzfdRk6 yMuw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:subject:to:cc:message-id:date:user-agent :mime-version:content-language:content-transfer-encoding; bh=QBGrmvcS7Oy8UgeLqWHR5Mdzi4HTInkk+4zc4dgPf7c=; b=C+hqKoT0ncCKckI86gnpXU8/b7kCozU8zoVU/XjuWK0hMU3Q1ItNcPNaycant4G0Qj OzjCW0JOJvSSWWt1SFoYvdYYUHJZRh7uKLh8w9bCh0XMWETuUAjjsXNQpnLMmAaf8+6Q ECzG6yKD+j0pAxli2+Zqad00dlPA4uiwjRrofYYzH9ebCfsVHZL8v/oXdE6MeqXufnO1 KvCAFTZJauKCr6hvTRKZF6AklJ2y+pqp6M5ChttC8HWopivogAwiFc2NcBE4sYL1aocL hredk5Wn7QTrJXKN42+tmAhyrugsezlAjJVPVei0JH1sYgmPvr+iIB4EIT9A/zphyBgJ Zf+Q== X-Gm-Message-State: AJcUukdra/ZOiDEw97H8M++xOE0RCPZFp1gyFVUzPk+MLe34tH+x4vi5 Nn+Fb7XPgNniPpdcl3xxPIw0iRPM X-Google-Smtp-Source: ALg8bN4IDx6vC2Z0K3hQSCm7PMaUaiBCQjO6DwBjMyg6VYKGfxWvOjes+oYdb44Dyfbwec1G61/8xQ== X-Received: by 2002:a7b:c44d:: with SMTP id l13mr6238090wmi.144.1547622466365; Tue, 15 Jan 2019 23:07:46 -0800 (PST) Received: from ?IPv6:2003:ea:8bf1:e200:8451:148b:48eb:db9b? (p200300EA8BF1E2008451148B48EBDB9B.dip0.t-ipconnect.de. [2003:ea:8bf1:e200:8451:148b:48eb:db9b]) by smtp.googlemail.com with ESMTPSA id h13sm63259447wrp.61.2019.01.15.23.07.45 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 15 Jan 2019 23:07:45 -0800 (PST) From: Heiner Kallweit Subject: [PATCH v2 net-next] net: phy: check return code when requesting PHY driver module To: Andrew Lunn , Florian Fainelli , David Miller Cc: "netdev@vger.kernel.org" Message-ID: Date: Wed, 16 Jan 2019 08:07:38 +0100 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:60.0) Gecko/20100101 Thunderbird/60.4.0 MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org When requesting the PHY driver module fails we'll bind the genphy driver later. This isn't obvious to the user and may cause, depending on the PHY, different types of issues. Therefore check the return code of request_module(). Note that we only check for failures in loading the module, not whether a module exists for the respective PHY ID. v2: - add comment explaining what is checked and what is not - return error from phy_device_create() if loading module fails Signed-off-by: Heiner Kallweit --- drivers/net/phy/phy_device.c | 35 ++++++++++++++++++++++++++++++----- 1 file changed, 30 insertions(+), 5 deletions(-) diff --git a/drivers/net/phy/phy_device.c b/drivers/net/phy/phy_device.c index a2423cbb2..32772f422 100644 --- a/drivers/net/phy/phy_device.c +++ b/drivers/net/phy/phy_device.c @@ -548,12 +548,31 @@ static const struct device_type mdio_bus_phy_type = { .pm = MDIO_BUS_PHY_PM_OPS, }; +static int phy_request_driver_module(struct phy_device *dev, int phy_id) +{ + int ret; + + ret = request_module(MDIO_MODULE_PREFIX MDIO_ID_FMT, + MDIO_ID_ARGS(phy_id)); + /* we only check for failures in executing the usermode binary, + * not whether a PHY driver module exists for the PHY ID + */ + if (IS_ENABLED(CONFIG_MODULES) && ret < 0) { + phydev_err(dev, "error %d loading PHY driver module for ID 0x%08x\n", + ret, phy_id); + return ret; + } + + return 0; +} + struct phy_device *phy_device_create(struct mii_bus *bus, int addr, int phy_id, bool is_c45, struct phy_c45_device_ids *c45_ids) { struct phy_device *dev; struct mdio_device *mdiodev; + int ret = 0; /* We allocate the device, and initialize the default values */ dev = kzalloc(sizeof(*dev), GFP_KERNEL); @@ -610,15 +629,21 @@ struct phy_device *phy_device_create(struct mii_bus *bus, int addr, int phy_id, if (!(c45_ids->devices_in_package & (1 << i))) continue; - request_module(MDIO_MODULE_PREFIX MDIO_ID_FMT, - MDIO_ID_ARGS(c45_ids->device_ids[i])); + ret = phy_request_driver_module(dev, + c45_ids->device_ids[i]); + if (ret) + break; } } else { - request_module(MDIO_MODULE_PREFIX MDIO_ID_FMT, - MDIO_ID_ARGS(phy_id)); + ret = phy_request_driver_module(dev, phy_id); } - device_initialize(&mdiodev->dev); + if (!ret) { + device_initialize(&mdiodev->dev); + } else { + kfree(dev); + dev = ERR_PTR(ret); + } return dev; } -- 2.20.1