Patch Detail
get:
Show a patch.
patch:
Update a patch.
put:
Update a patch.
GET /api/patches/1314623/?format=api
{ "id": 1314623, "url": "http://patchwork.ozlabs.org/api/patches/1314623/?format=api", "web_url": "http://patchwork.ozlabs.org/project/intel-wired-lan/patch/20200622100056.10151-9-brgl@bgdev.pl/", "project": { "id": 46, "url": "http://patchwork.ozlabs.org/api/projects/46/?format=api", "name": "Intel Wired Ethernet development", "link_name": "intel-wired-lan", "list_id": "intel-wired-lan.osuosl.org", "list_email": "intel-wired-lan@osuosl.org", "web_url": "", "scm_url": "", "webscm_url": "", "list_archive_url": "", "list_archive_url_format": "", "commit_url_format": "" }, "msgid": "<20200622100056.10151-9-brgl@bgdev.pl>", "list_archive_url": null, "date": "2020-06-22T10:00:53", "name": "[08/11] net: phy: don't abuse devres in devm_mdiobus_register()", "commit_ref": null, "pull_url": null, "state": "awaiting-upstream", "archived": false, "hash": "7083fba0497403f1fec88e8e12e4940a884dae09", "submitter": { "id": 71346, "url": "http://patchwork.ozlabs.org/api/people/71346/?format=api", "name": "Bartosz Golaszewski", "email": "brgl@bgdev.pl" }, "delegate": null, "mbox": "http://patchwork.ozlabs.org/project/intel-wired-lan/patch/20200622100056.10151-9-brgl@bgdev.pl/mbox/", "series": [ { "id": 185056, "url": "http://patchwork.ozlabs.org/api/series/185056/?format=api", "web_url": "http://patchwork.ozlabs.org/project/intel-wired-lan/list/?series=185056", "date": "2020-06-22T10:00:52", "name": "net: improve devres helpers", "version": 1, "mbox": "http://patchwork.ozlabs.org/series/185056/mbox/" } ], "comments": "http://patchwork.ozlabs.org/api/patches/1314623/comments/", "check": "pending", "checks": "http://patchwork.ozlabs.org/api/patches/1314623/checks/", "tags": {}, "related": [], "headers": { "Return-Path": "<intel-wired-lan-bounces@osuosl.org>", "X-Original-To": [ "incoming@patchwork.ozlabs.org", "intel-wired-lan@lists.osuosl.org" ], "Delivered-To": [ "patchwork-incoming@bilbo.ozlabs.org", "intel-wired-lan@lists.osuosl.org" ], "Authentication-Results": [ "ozlabs.org;\n spf=pass (sender SPF authorized) smtp.mailfrom=osuosl.org\n (client-ip=140.211.166.133; helo=hemlock.osuosl.org;\n envelope-from=intel-wired-lan-bounces@osuosl.org; receiver=<UNKNOWN>)", "ozlabs.org;\n dmarc=none (p=none dis=none) header.from=bgdev.pl", "ozlabs.org;\n\tdkim=fail reason=\"signature verification failed\" (2048-bit key;\n unprotected) header.d=bgdev-pl.20150623.gappssmtp.com\n header.i=@bgdev-pl.20150623.gappssmtp.com header.a=rsa-sha256\n header.s=20150623 header.b=umsqc560;\n\tdkim-atps=neutral" ], "Received": [ "from hemlock.osuosl.org (smtp2.osuosl.org [140.211.166.133])\n\t(using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits))\n\t(No client certificate requested)\n\tby ozlabs.org (Postfix) with ESMTPS id 49rFh31DSYz9sRh\n\tfor <incoming@patchwork.ozlabs.org>; Tue, 23 Jun 2020 02:47:30 +1000 (AEST)", "from localhost (localhost [127.0.0.1])\n\tby hemlock.osuosl.org (Postfix) with ESMTP id 4DC2B86221;\n\tMon, 22 Jun 2020 16:47:29 +0000 (UTC)", "from hemlock.osuosl.org ([127.0.0.1])\n\tby localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024)\n\twith ESMTP id oCJUjHUzB3Tm; Mon, 22 Jun 2020 16:47:27 +0000 (UTC)", "from ash.osuosl.org (ash.osuosl.org [140.211.166.34])\n\tby hemlock.osuosl.org (Postfix) with ESMTP id CC8EF893C0;\n\tMon, 22 Jun 2020 16:47:27 +0000 (UTC)", "from fraxinus.osuosl.org (smtp4.osuosl.org [140.211.166.137])\n by ash.osuosl.org (Postfix) with ESMTP id D7EA51BF3C8\n for <intel-wired-lan@lists.osuosl.org>; Mon, 22 Jun 2020 10:08:31 +0000 (UTC)", "from localhost (localhost [127.0.0.1])\n by fraxinus.osuosl.org (Postfix) with ESMTP id D3C6886371\n for <intel-wired-lan@lists.osuosl.org>; Mon, 22 Jun 2020 10:08:31 +0000 (UTC)", "from fraxinus.osuosl.org ([127.0.0.1])\n by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024)\n with ESMTP id RUFkwNbJ0GAJ for <intel-wired-lan@lists.osuosl.org>;\n Mon, 22 Jun 2020 10:08:30 +0000 (UTC)", "from mail-wm1-f68.google.com (mail-wm1-f68.google.com\n [209.85.128.68])\n by fraxinus.osuosl.org (Postfix) with ESMTPS id 79B918458C\n for <intel-wired-lan@lists.osuosl.org>; Mon, 22 Jun 2020 10:08:30 +0000 (UTC)", "by mail-wm1-f68.google.com with SMTP id x16so5143076wmj.1\n for <intel-wired-lan@lists.osuosl.org>; Mon, 22 Jun 2020 03:08:30 -0700 (PDT)", "from localhost.localdomain (lfbn-nic-1-65-232.w2-15.abo.wanadoo.fr.\n [2.15.156.232])\n by smtp.gmail.com with ESMTPSA id x205sm16822187wmx.21.2020.06.22.03.01.17\n (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n Mon, 22 Jun 2020 03:01:18 -0700 (PDT)" ], "X-Virus-Scanned": [ "amavisd-new at osuosl.org", "amavisd-new at osuosl.org" ], "X-Greylist": "from auto-whitelisted by SQLgrey-1.7.6", "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/relaxed;\n d=bgdev-pl.20150623.gappssmtp.com; s=20150623;\n h=from:to:cc:subject:date:message-id:in-reply-to:references\n :mime-version:content-transfer-encoding;\n bh=TTj07T08NNZro/U2yWPFP3Dw02nhL5hB1K0t6Vwkyzw=;\n b=umsqc560VgWzO4IFGB8xbm9+eHaBnWiZ8GN88xIPqibz5h05dlWPTFWVVY+f69KlG0\n a4y7K5KJh92xDh9QC/FmqY1WMCLtVijDEi7mmlatAu20aNEY/OkwQAydZfniEo6v19ly\n 5UpNecI0rhyx7ljbmoN4ErSxXuJgzG2Pvn5qCM8hJ/gz7PmN8uAxqCEn0FKto6Yw3BQJ\n MwlWbDZgiEh6Bxwf6FJ+KhsXROfVkjFYGLxKZrFtIx6c3oqVOLqL2qrekxNXHOXLjNu7\n HsquwI/7md6BwXsqjVvJhh/XfV1XR78LuXr1JLkx4Xai6QrZExGPdzterXgVwn8Nlu2K\n +Dwg==", "X-Google-DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/relaxed;\n d=1e100.net; s=20161025;\n h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to\n :references:mime-version:content-transfer-encoding;\n bh=TTj07T08NNZro/U2yWPFP3Dw02nhL5hB1K0t6Vwkyzw=;\n b=guaCQ91uzfDb1/yXC/9vBRXciXo218wyTXxDkP4zTMgRdm9vQc2mF6aTL6M52ssU4G\n 0vrOhPQ3AtJOQSLLQZdItn4YVGd3nO97BaCeL25jFME3bbzr58q2iBsjPgp3DyDqy+BA\n TlqW1mWGhaaRorymFjQcDFL5MidgRpp14irKPsoFPZoZm1D+0a7uHLWzOE+MtpuEK094\n pIbwQEJIea5Nx0aipq0KclTX+V3l6x8xPbBDAqgqiS0TjRcVMjoBCQ+cD6p06shwgazx\n +DHEfqPfrldUGDhAIMOxX88bfPD2kHO0hJGVij8rMEecCPlNK/ZZ19hJW70hzebF52w+\n SqAg==", "X-Gm-Message-State": "AOAM532e/ieiWrxVUo0aqW1T0ft0xAduuMfxLiEErbXAi9nxknOgU18N\n 3Gx8/K7LieiGKkBpWF8GpQvrYaUT91U=", "X-Google-Smtp-Source": "\n ABdhPJwbtQnwhgQy4/PGrqFbGi4Rm4Vlma7uhso1tRe0BeUVnkpoIf981M/hc/QiwEw6xXi5+FRkFQ==", "X-Received": "by 2002:a05:600c:2dc1:: with SMTP id\n e1mr5038382wmh.108.1592820078894;\n Mon, 22 Jun 2020 03:01:18 -0700 (PDT)", "From": "Bartosz Golaszewski <brgl@bgdev.pl>", "To": "Jonathan Corbet <corbet@lwn.net>,\n Jeff Kirsher <jeffrey.t.kirsher@intel.com>,\n \"David S . Miller\" <davem@davemloft.net>, Jakub Kicinski <kuba@kernel.org>,\n John Crispin <john@phrozen.org>, Sean Wang <sean.wang@mediatek.com>,\n Mark Lee <Mark-MC.Lee@mediatek.com>,\n Matthias Brugger <matthias.bgg@gmail.com>,\n Realtek linux nic maintainers <nic_swsd@realtek.com>,\n Heiner Kallweit <hkallweit1@gmail.com>, Andrew Lunn <andrew@lunn.ch>,\n Florian Fainelli <f.fainelli@gmail.com>,\n Russell King <linux@armlinux.org.uk>, Rob Herring <robh+dt@kernel.org>,\n Frank Rowand <frowand.list@gmail.com>", "Date": "Mon, 22 Jun 2020 12:00:53 +0200", "Message-Id": "<20200622100056.10151-9-brgl@bgdev.pl>", "X-Mailer": "git-send-email 2.26.1", "In-Reply-To": "<20200622100056.10151-1-brgl@bgdev.pl>", "References": "<20200622100056.10151-1-brgl@bgdev.pl>", "MIME-Version": "1.0", "X-Mailman-Approved-At": "Mon, 22 Jun 2020 16:47:24 +0000", "Subject": "[Intel-wired-lan] [PATCH 08/11] net: phy: don't abuse devres in\n devm_mdiobus_register()", "X-BeenThere": "intel-wired-lan@osuosl.org", "X-Mailman-Version": "2.1.29", "Precedence": "list", "List-Id": "Intel Wired Ethernet Linux Kernel Driver Development\n <intel-wired-lan.osuosl.org>", "List-Unsubscribe": "<https://lists.osuosl.org/mailman/options/intel-wired-lan>,\n <mailto:intel-wired-lan-request@osuosl.org?subject=unsubscribe>", "List-Archive": "<http://lists.osuosl.org/pipermail/intel-wired-lan/>", "List-Post": "<mailto:intel-wired-lan@osuosl.org>", "List-Help": "<mailto:intel-wired-lan-request@osuosl.org?subject=help>", "List-Subscribe": "<https://lists.osuosl.org/mailman/listinfo/intel-wired-lan>,\n <mailto:intel-wired-lan-request@osuosl.org?subject=subscribe>", "Cc": "devicetree@vger.kernel.org,\n Bartosz Golaszewski <bgolaszewski@baylibre.com>,\n Stephane Le Provost <stephane.leprovost@mediatek.com>,\n linux-doc@vger.kernel.org, netdev@vger.kernel.org,\n linux-kernel@vger.kernel.org, Fabien Parent <fparent@baylibre.com>,\n linux-mediatek@lists.infradead.org,\n Andrew Perepech <andrew.perepech@mediatek.com>,\n Pedro Tsai <pedro.tsai@mediatek.com>, intel-wired-lan@lists.osuosl.org,\n linux-arm-kernel@lists.infradead.org", "Content-Type": "text/plain; charset=\"us-ascii\"", "Content-Transfer-Encoding": "7bit", "Errors-To": "intel-wired-lan-bounces@osuosl.org", "Sender": "\"Intel-wired-lan\" <intel-wired-lan-bounces@osuosl.org>" }, "content": "From: Bartosz Golaszewski <bgolaszewski@baylibre.com>\n\nWe currently have two managed helpers for mdiobus - devm_mdiobus_alloc()\nand devm_mdiobus_register(). The idea behind devres is that the release\ncallback releases whatever resource the devm function allocates. In the\nmdiobus case however there's no devres associated with the device by\ndevm_mdiobus_register(). Instead the release callback for\ndevm_mdiobus_alloc(): _devm_mdiobus_free() unregisters the device if\nit is marked as managed.\n\nThis all seems wrong. The managed structure shouldn't need to know or\ncare about whether it's managed or not - and this is the case now for\nstruct mii_bus. The devres wrapper should be opaque to the managed\nresource.\n\nThis changeset makes devm_mdiobus_alloc() and devm_mdiobus_register()\nconform to common devres standards: devm_mdiobus_alloc() allocates a\ndevres structure and registers a callback that will call mdiobus_free().\n__devm_mdiobus_register() allocated another devres and registers a\ncallback that will unregister the bus. Similarily to how we modified\ndevm_register_netdev() - we're not checking whether struct mii_bus is\nmanaged - it could have been allocated as part of a bigger structure.\n\nSigned-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>\n---\n .../driver-api/driver-model/devres.rst | 1 -\n drivers/net/ethernet/realtek/r8169_main.c | 2 +-\n drivers/net/phy/mdio_bus.c | 73 -------------------\n drivers/net/phy/mdio_devres.c | 70 ++++++++++++++++--\n include/linux/phy.h | 10 +--\n 5 files changed, 69 insertions(+), 87 deletions(-)", "diff": "diff --git a/Documentation/driver-api/driver-model/devres.rst b/Documentation/driver-api/driver-model/devres.rst\nindex 5463fc8a60c1..e0333d66a7f4 100644\n--- a/Documentation/driver-api/driver-model/devres.rst\n+++ b/Documentation/driver-api/driver-model/devres.rst\n@@ -342,7 +342,6 @@ LED\n MDIO\n devm_mdiobus_alloc()\n devm_mdiobus_alloc_size()\n- devm_mdiobus_free()\n devm_mdiobus_register()\n \n MEM\ndiff --git a/drivers/net/ethernet/realtek/r8169_main.c b/drivers/net/ethernet/realtek/r8169_main.c\nindex dad84ecf5a77..34d5797695ba 100644\n--- a/drivers/net/ethernet/realtek/r8169_main.c\n+++ b/drivers/net/ethernet/realtek/r8169_main.c\n@@ -5100,7 +5100,7 @@ static int r8169_mdio_register(struct rtl8169_private *tp)\n \tnew_bus->read = r8169_mdio_read_reg;\n \tnew_bus->write = r8169_mdio_write_reg;\n \n-\tret = devm_mdiobus_register(new_bus);\n+\tret = devm_mdiobus_register(&pdev->dev, new_bus);\n \tif (ret)\n \t\treturn ret;\n \ndiff --git a/drivers/net/phy/mdio_bus.c b/drivers/net/phy/mdio_bus.c\nindex 6ceee82b2839..42192991f55d 100644\n--- a/drivers/net/phy/mdio_bus.c\n+++ b/drivers/net/phy/mdio_bus.c\n@@ -165,79 +165,6 @@ struct mii_bus *mdiobus_alloc_size(size_t size)\n }\n EXPORT_SYMBOL(mdiobus_alloc_size);\n \n-static void _devm_mdiobus_free(struct device *dev, void *res)\n-{\n-\tstruct mii_bus *bus = *(struct mii_bus **)res;\n-\n-\tif (bus->is_managed_registered && bus->state == MDIOBUS_REGISTERED)\n-\t\tmdiobus_unregister(bus);\n-\n-\tmdiobus_free(bus);\n-}\n-\n-static int devm_mdiobus_match(struct device *dev, void *res, void *data)\n-{\n-\tstruct mii_bus **r = res;\n-\n-\tif (WARN_ON(!r || !*r))\n-\t\treturn 0;\n-\n-\treturn *r == data;\n-}\n-\n-/**\n- * devm_mdiobus_alloc_size - Resource-managed mdiobus_alloc_size()\n- * @dev:\t\tDevice to allocate mii_bus for\n- * @sizeof_priv:\tSpace to allocate for private structure.\n- *\n- * Managed mdiobus_alloc_size. mii_bus allocated with this function is\n- * automatically freed on driver detach.\n- *\n- * If an mii_bus allocated with this function needs to be freed separately,\n- * devm_mdiobus_free() must be used.\n- *\n- * RETURNS:\n- * Pointer to allocated mii_bus on success, NULL on failure.\n- */\n-struct mii_bus *devm_mdiobus_alloc_size(struct device *dev, int sizeof_priv)\n-{\n-\tstruct mii_bus **ptr, *bus;\n-\n-\tptr = devres_alloc(_devm_mdiobus_free, sizeof(*ptr), GFP_KERNEL);\n-\tif (!ptr)\n-\t\treturn NULL;\n-\n-\t/* use raw alloc_dr for kmalloc caller tracing */\n-\tbus = mdiobus_alloc_size(sizeof_priv);\n-\tif (bus) {\n-\t\t*ptr = bus;\n-\t\tdevres_add(dev, ptr);\n-\t\tbus->is_managed = 1;\n-\t} else {\n-\t\tdevres_free(ptr);\n-\t}\n-\n-\treturn bus;\n-}\n-EXPORT_SYMBOL_GPL(devm_mdiobus_alloc_size);\n-\n-/**\n- * devm_mdiobus_free - Resource-managed mdiobus_free()\n- * @dev:\t\tDevice this mii_bus belongs to\n- * @bus:\t\tthe mii_bus associated with the device\n- *\n- * Free mii_bus allocated with devm_mdiobus_alloc_size().\n- */\n-void devm_mdiobus_free(struct device *dev, struct mii_bus *bus)\n-{\n-\tint rc;\n-\n-\trc = devres_release(dev, _devm_mdiobus_free,\n-\t\t\t devm_mdiobus_match, bus);\n-\tWARN_ON(rc);\n-}\n-EXPORT_SYMBOL_GPL(devm_mdiobus_free);\n-\n /**\n * mdiobus_release - mii_bus device release callback\n * @d: the target struct device that contains the mii_bus\ndiff --git a/drivers/net/phy/mdio_devres.c b/drivers/net/phy/mdio_devres.c\nindex 3ee887733d4a..344d2c748c16 100644\n--- a/drivers/net/phy/mdio_devres.c\n+++ b/drivers/net/phy/mdio_devres.c\n@@ -1,25 +1,83 @@\n // SPDX-License-Identifier: GPL-2.0-or-later\n \n+#include <linux/device.h>\n #include <linux/phy.h>\n+#include <linux/stddef.h>\n+\n+struct mdiobus_devres {\n+\tstruct mii_bus *mii;\n+};\n+\n+static void devm_mdiobus_free(struct device *dev, void *this)\n+{\n+\tstruct mdiobus_devres *dr = this;\n+\n+\tmdiobus_free(dr->mii);\n+}\n+\n+/**\n+ * devm_mdiobus_alloc_size - Resource-managed mdiobus_alloc_size()\n+ * @dev:\t\tDevice to allocate mii_bus for\n+ * @sizeof_priv:\tSpace to allocate for private structure\n+ *\n+ * Managed mdiobus_alloc_size. mii_bus allocated with this function is\n+ * automatically freed on driver detach.\n+ *\n+ * RETURNS:\n+ * Pointer to allocated mii_bus on success, NULL on out-of-memory error.\n+ */\n+struct mii_bus *devm_mdiobus_alloc_size(struct device *dev, int sizeof_priv)\n+{\n+\tstruct mdiobus_devres *dr;\n+\n+\tdr = devres_alloc(devm_mdiobus_free, sizeof(*dr), GFP_KERNEL);\n+\tif (!dr)\n+\t\treturn NULL;\n+\n+\tdr->mii = mdiobus_alloc_size(sizeof_priv);\n+\tif (!dr->mii) {\n+\t\tdevres_free(dr);\n+\t\treturn NULL;\n+\t}\n+\n+\tdevres_add(dev, dr);\n+\treturn dr->mii;\n+}\n+EXPORT_SYMBOL(devm_mdiobus_alloc_size);\n+\n+static void devm_mdiobus_unregister(struct device *dev, void *this)\n+{\n+\tstruct mdiobus_devres *dr = this;\n+\n+\tmdiobus_unregister(dr->mii);\n+}\n \n /**\n * __devm_mdiobus_register - Resource-managed variant of mdiobus_register()\n+ * @dev:\tDevice to register mii_bus for\n * @bus:\tMII bus structure to register\n * @owner:\tOwning module\n *\n * Returns 0 on success, negative error number on failure.\n */\n-int __devm_mdiobus_register(struct mii_bus *bus, struct module *owner)\n+int __devm_mdiobus_register(struct device *dev, struct mii_bus *bus,\n+\t\t\t struct module *owner)\n {\n+\tstruct mdiobus_devres *dr;\n \tint ret;\n \n-\tif (!bus->is_managed)\n-\t\treturn -EPERM;\n+\tdr = devres_alloc(devm_mdiobus_unregister, sizeof(*dr), GFP_KERNEL);\n+\tif (!dr)\n+\t\treturn -ENOMEM;\n \n \tret = __mdiobus_register(bus, owner);\n-\tif (!ret)\n-\t\tbus->is_managed_registered = 1;\n+\tif (ret) {\n+\t\tdevres_free(dr);\n+\t\treturn ret;\n+\t}\n \n-\treturn ret;\n+\tdr->mii = bus;\n+\tdevres_add(dev, dr);\n+\treturn 0;\n }\n EXPORT_SYMBOL(__devm_mdiobus_register);\ndiff --git a/include/linux/phy.h b/include/linux/phy.h\nindex 62149945c5b3..fa6697edefb3 100644\n--- a/include/linux/phy.h\n+++ b/include/linux/phy.h\n@@ -260,9 +260,6 @@ struct mii_bus {\n \tint (*reset)(struct mii_bus *bus);\n \tstruct mdio_bus_stats stats[PHY_MAX_ADDR];\n \n-\tunsigned int is_managed:1;\t/* is device-managed */\n-\tunsigned int is_managed_registered:1;\n-\n \t/*\n \t * A lock to ensure that only one thing can read/write\n \t * the MDIO bus at a time\n@@ -313,9 +310,11 @@ static inline struct mii_bus *mdiobus_alloc(void)\n }\n \n int __mdiobus_register(struct mii_bus *bus, struct module *owner);\n-int __devm_mdiobus_register(struct mii_bus *bus, struct module *owner);\n+int __devm_mdiobus_register(struct device *dev, struct mii_bus *bus,\n+\t\t\t struct module *owner);\n #define mdiobus_register(bus) __mdiobus_register(bus, THIS_MODULE)\n-#define devm_mdiobus_register(bus) __devm_mdiobus_register(bus, THIS_MODULE)\n+#define devm_mdiobus_register(dev, bus) \\\n+\t\t__devm_mdiobus_register(dev, bus, THIS_MODULE)\n \n void mdiobus_unregister(struct mii_bus *bus);\n void mdiobus_free(struct mii_bus *bus);\n@@ -326,7 +325,6 @@ static inline struct mii_bus *devm_mdiobus_alloc(struct device *dev)\n }\n \n struct mii_bus *mdio_find_bus(const char *mdio_name);\n-void devm_mdiobus_free(struct device *dev, struct mii_bus *bus);\n struct phy_device *mdiobus_scan(struct mii_bus *bus, int addr);\n \n #define PHY_INTERRUPT_DISABLED\tfalse\n", "prefixes": [ "08/11" ] }