Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp118566pxf; Wed, 10 Mar 2021 22:53:29 -0800 (PST) X-Google-Smtp-Source: ABdhPJwkT0d+G/QxuQVj+8E6XdzuzQcJbEotd98ZHVEzQ+VqUVUq/GWqNkrw5dkD0JTp5QwD7EUg X-Received: by 2002:a17:906:1453:: with SMTP id q19mr1681183ejc.76.1615445609625; Wed, 10 Mar 2021 22:53:29 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1615445609; cv=none; d=google.com; s=arc-20160816; b=evDggZA6icvU7bCyCMgdJkIeNx40Yk8IQ9OZCz2nlH+3ZFlrTVMSoz090WjPhUOEL1 RJwjIUaLZkJHA1LS0aX4BX1E4ojCPFRiYOZ/bzUzzuEEeqXIgdy5RxmkjDrgNkkkc2PM BDclmpzq5le0eErRmZRkpIQObZGPH5/Q9C3M+fBuwqHtsIIpsyj54TU5cUNnks5gYc8G 4Yd1oEYCYhfTQatmTugEGDYAeQnpjUrSSliUGNPN7ZdLhhj7YuvMQGJVM3K1lLO1chd4 IkWZBrDqOwLK5uZyrxoa6Xa65/GJ3otVFMe8C4Ma5B06nUTbA40BlDuuty14H6pzS60g fgQw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=/TWjmkYOsjWxuSvsZczTiKRCUZs8/TXiLhq6HTYxrkc=; b=0UKaqrq694XWcPsy+tDdGbhNDTKyS5wdHb1FWUijoyJdUpFZiK0cZTnxyFSshgAkqC bHQEitwrDVT2WbrDGy+0MCwyXaZErwxwgK/qVx41CLNbIHT8sHqc3wRDc2e5i+wjUR13 TsngAMC72Z0n3mZ8QVVtodqSBU/bsKFYMrhFE68USTYwor2PG4liArIokYpmIbw9kye7 YW00uWnxdSYjbiUH+xQ052J8r8hsK9DEb5ZgMxuuBFusuB5fG0fzq8s3eM0Yu+xEobPU ly+i5oAc/1rBrlh9ZMGitkgHJJvVv85fFEjtMFfNUnYuB0ydSHSxgM+FxwZpmbkfO5gZ TiNA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=ZiX9Rg7l; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id w9si1252771edi.363.2021.03.10.22.53.06; Wed, 10 Mar 2021 22:53:29 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=ZiX9Rg7l; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231455AbhCKGwF (ORCPT + 99 others); Thu, 11 Mar 2021 01:52:05 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45784 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229731AbhCKGve (ORCPT ); Thu, 11 Mar 2021 01:51:34 -0500 Received: from mail-yb1-xb2e.google.com (mail-yb1-xb2e.google.com [IPv6:2607:f8b0:4864:20::b2e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EA00EC061760 for ; Wed, 10 Mar 2021 22:51:33 -0800 (PST) Received: by mail-yb1-xb2e.google.com with SMTP id u75so20598028ybi.10 for ; Wed, 10 Mar 2021 22:51:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=/TWjmkYOsjWxuSvsZczTiKRCUZs8/TXiLhq6HTYxrkc=; b=ZiX9Rg7lAbNihf5ARUd3fj7zUcwh3LumoEDPAk5Ai99apA62qWW2GkHJk6efyfiEy7 coJVlTQ102RjumLiZAw6DPjna6+4gPzHFKWtY5g+xILHxGYvd6jDQPDP5QtdTlQD/Hc9 ik5KFF9f83yCTuTTdV2f8XqHJ6sJIrr/hnF6DlsiO+xBdbFU+FaYxKUTgWWqQ2fFmQqt eZEkduD+GIm6/za07O/KG2PEyO/LxQHG0B1W632QMeeJXb5cYOQ2FRa+nfD+UdCXcCvn N3naoX+/jUCKauItbzKRwv5w5FelkgvfUjxo6FypJWGjGHvc72A44VN4Nq0XUONe9PV+ 4C3w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=/TWjmkYOsjWxuSvsZczTiKRCUZs8/TXiLhq6HTYxrkc=; b=iJFnXGiMrRzOT3nVIh3J5IdeWM8mssBtxY/6JOs4MQlTTAv340aFr6BMYYyo0+sTCE HIYgKjlZ/+cIW1odypyzNq/iH986h/fxVFn6w1iD/F/4WjhT8u9rIZNSMd+zaLXQc3eD hprinx5npgWxCNuce4lP008Rw5cw5SSyoSESga0mKwMP2aajU9eEmLokNH0FlHX7npTT u5NVIOF7IzAmaVNhvCNErkOtBc3g3t3/pC/ib1sWkzjvsi+lSLfiQUZNCyZHHt9+ZMVJ oWqKqIjtpjue4PV9pf59rR9EUF+h70m2NbdBu+/gHpsrhEA+LHeOOmtgo+sT0V9AxoNK aa4Q== X-Gm-Message-State: AOAM5329cLtxNsPcNQcBvwM6h+3BWuUhk2BhoezCDsAyquETtGde4kOK FY652eTaWSBLV1je4siUhs03IX2LtZO6xzmOBGP0Ag== X-Received: by 2002:a25:aa43:: with SMTP id s61mr10180775ybi.32.1615445492980; Wed, 10 Mar 2021 22:51:32 -0800 (PST) MIME-Version: 1.0 References: <20210311062011.8054-1-calvin.johnson@oss.nxp.com> <20210311062011.8054-3-calvin.johnson@oss.nxp.com> In-Reply-To: <20210311062011.8054-3-calvin.johnson@oss.nxp.com> From: Saravana Kannan Date: Wed, 10 Mar 2021 22:50:57 -0800 Message-ID: Subject: Re: [net-next PATCH v7 02/16] net: phy: Introduce fwnode_mdio_find_device() To: Calvin Johnson Cc: Grant Likely , "Rafael J . Wysocki" , Jeremy Linton , Andrew Lunn , Andy Shevchenko , Florian Fainelli , Russell King - ARM Linux admin , Cristi Sovaiala , Florin Laurentiu Chiculita , Ioana Ciornei , Madalin Bucur , Heikki Krogerus , Marcin Wojtas , Pieter Jansen Van Vuuren , Jon , Randy Dunlap , linux-arm-kernel , Diana Madalina Craciun , ACPI Devel Maling List , LKML , "linux.cj" , netdev , Laurentiu Tudor , "David S. Miller" , Heiner Kallweit , Jakub Kicinski Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Mar 10, 2021 at 10:21 PM Calvin Johnson wrote: > > Define fwnode_mdio_find_device() to get a pointer to the > mdio_device from fwnode passed to the function. > > Refactor of_mdio_find_device() to use fwnode_mdio_find_device(). > > Signed-off-by: Calvin Johnson > --- > > Changes in v7: > - correct fwnode_mdio_find_device() description > > Changes in v6: > - fix warning for function parameter of fwnode_mdio_find_device() > > Changes in v5: None > Changes in v4: None > Changes in v3: None > Changes in v2: None > > drivers/net/mdio/of_mdio.c | 11 +---------- > drivers/net/phy/phy_device.c | 23 +++++++++++++++++++++++ > include/linux/phy.h | 6 ++++++ > 3 files changed, 30 insertions(+), 10 deletions(-) > > diff --git a/drivers/net/mdio/of_mdio.c b/drivers/net/mdio/of_mdio.c > index ea9d5855fb52..d5e0970b2561 100644 > --- a/drivers/net/mdio/of_mdio.c > +++ b/drivers/net/mdio/of_mdio.c > @@ -347,16 +347,7 @@ EXPORT_SYMBOL(of_mdiobus_register); > */ > struct mdio_device *of_mdio_find_device(struct device_node *np) > { > - struct device *d; > - > - if (!np) > - return NULL; > - > - d = bus_find_device_by_of_node(&mdio_bus_type, np); > - if (!d) > - return NULL; > - > - return to_mdio_device(d); > + return fwnode_mdio_find_device(of_fwnode_handle(np)); > } > EXPORT_SYMBOL(of_mdio_find_device); > > diff --git a/drivers/net/phy/phy_device.c b/drivers/net/phy/phy_device.c > index cc38e326405a..daabb17bba00 100644 > --- a/drivers/net/phy/phy_device.c > +++ b/drivers/net/phy/phy_device.c > @@ -2819,6 +2819,29 @@ static bool phy_drv_supports_irq(struct phy_driver *phydrv) > return phydrv->config_intr && phydrv->handle_interrupt; > } > > +/** > + * fwnode_mdio_find_device - Given a fwnode, find the mdio_device > + * @fwnode: pointer to the mdio_device's fwnode > + * > + * If successful, returns a pointer to the mdio_device with the embedded > + * struct device refcount incremented by one, or NULL on failure. > + * The caller should call put_device() on the mdio_device after its use. > + */ > +struct mdio_device *fwnode_mdio_find_device(struct fwnode_handle *fwnode) > +{ > + struct device *d; > + > + if (!fwnode) > + return NULL; > + > + d = bus_find_device_by_fwnode(&mdio_bus_type, fwnode); Sorry about the late review, but can you look into using get_dev_from_fwnode()? As long as you aren't registering two devices for the same fwnode, it's an O(1) operation instead of having to loop through a list of devices in a bus. You can check the returned device's bus type if you aren't sure about not registering two devices with the same fw_node and then fall back to this looping. -Saravana > + if (!d) > + return NULL; > + > + return to_mdio_device(d); > +} > +EXPORT_SYMBOL(fwnode_mdio_find_device); > + > /** > * phy_probe - probe and init a PHY device > * @dev: device to probe and init > diff --git a/include/linux/phy.h b/include/linux/phy.h > index 1a12e4436b5b..f5eb1e3981a1 100644 > --- a/include/linux/phy.h > +++ b/include/linux/phy.h > @@ -1366,11 +1366,17 @@ struct phy_device *phy_device_create(struct mii_bus *bus, int addr, u32 phy_id, > bool is_c45, > struct phy_c45_device_ids *c45_ids); > #if IS_ENABLED(CONFIG_PHYLIB) > +struct mdio_device *fwnode_mdio_find_device(struct fwnode_handle *fwnode); > struct phy_device *get_phy_device(struct mii_bus *bus, int addr, bool is_c45); > int phy_device_register(struct phy_device *phy); > void phy_device_free(struct phy_device *phydev); > #else > static inline > +struct mdio_device *fwnode_mdio_find_device(struct fwnode_handle *fwnode) > +{ > + return 0; > +} > +static inline > struct phy_device *get_phy_device(struct mii_bus *bus, int addr, bool is_c45) > { > return NULL; > -- > 2.17.1 >