From mboxrd@z Thu Jan 1 00:00:00 1970 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=-4.0 required=3.0 tests=BAYES_00,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS autolearn=no 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 900B3C48BE6 for ; Fri, 11 Jun 2021 11:41:28 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 7D0E8613CC for ; Fri, 11 Jun 2021 11:41:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231698AbhFKLnY (ORCPT ); Fri, 11 Jun 2021 07:43:24 -0400 Received: from mail-ot1-f41.google.com ([209.85.210.41]:40646 "EHLO mail-ot1-f41.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231289AbhFKLnX (ORCPT ); Fri, 11 Jun 2021 07:43:23 -0400 Received: by mail-ot1-f41.google.com with SMTP id l15-20020a05683016cfb02903fca0eacd15so2834059otr.7; Fri, 11 Jun 2021 04:41:10 -0700 (PDT) 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=7QOkn9Hd+sQCvI8baU0dpPbaUWUsXvor6j6J5RvuZ0c=; b=XuOJ1NY+Iu6o+tGgf7b5E6CYOubH9+OtOw5wqTYIKgLN14CiifwgVwh2KntL9+9g5/ mbXRoHCCQwFjjDnsNgtJB3sIBayqkFo20aweSMpNYL3aFqEV1HF4wgHNCAo0TyraTaQ8 U/WbCOISIMfFstT7uCgptnB8Q1zumwP/DJZnf1tqB+2NzD0g6fUXBjBx2ofGlPEsDoud 47LTUR+WQrxokDv6LSxmyizl1fNG7n+vib+INxj3IaHdfP4U0TyFJi2e/3b1aXU8YlCV ZnDqfMe5PELnnu5ZcE8+REaZeUzQ/pE8QtGoZOHZ9UCcg4ZeU1sTzhZU98xl+lLvDV9T CgEg== X-Gm-Message-State: AOAM530EssBrbjwpbOFA9vVuZYbboSyVHjiIH4uCtGSqyf59Lciz1nPS VRE3pVENJwLVTuvSFgfwpHU1M1Ww0xco/svjcaQ= X-Google-Smtp-Source: ABdhPJwQTGdCRMLaGc9mpm/YGrESWdEScX68+bH9kYc33POVxW9M0l5xzZFSm1LsFO7c25vhgsQjPb21ulP9KNGySKA= X-Received: by 2002:a9d:6c4d:: with SMTP id g13mr2812244otq.321.1623411670173; Fri, 11 Jun 2021 04:41:10 -0700 (PDT) MIME-Version: 1.0 References: <20210611105401.270673-1-ciorneiioana@gmail.com> <20210611105401.270673-4-ciorneiioana@gmail.com> In-Reply-To: From: "Rafael J. Wysocki" Date: Fri, 11 Jun 2021 13:40:59 +0200 Message-ID: Subject: Re: [PATCH net-next v9 03/15] net: phy: Introduce phy related fwnode functions To: Andy Shevchenko Cc: Ioana Ciornei , "David S. Miller" , Jakub Kicinski , Heiner Kallweit , netdev , Grant Likely , "Rafael J . Wysocki" , Jeremy Linton , Andrew Lunn , Florian Fainelli , Russell King - ARM Linux admin , Heikki Krogerus , Marcin Wojtas , Pieter Jansen Van Vuuren , Jon , Saravana Kannan , Randy Dunlap , Calvin Johnson , Cristi Sovaiala , Florin Laurentiu Chiculita , Madalin Bucur , linux-arm Mailing List , Diana Madalina Craciun , ACPI Devel Maling List , Linux Kernel Mailing List , "linux.cj" , Laurentiu Tudor , Len Brown , "Rafael J . Wysocki" , Ioana Ciornei Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Jun 11, 2021 at 1:26 PM Andy Shevchenko wrote: > > On Fri, Jun 11, 2021 at 1:54 PM Ioana Ciornei wrote: > > > > From: Calvin Johnson > > > > Define fwnode_phy_find_device() to iterate an mdiobus and find the > > phy device of the provided phy fwnode. Additionally define > > device_phy_find_device() to find phy device of provided device. > > > > Define fwnode_get_phy_node() to get phy_node using named reference. > > using a named > > ... > > > +struct fwnode_handle *fwnode_get_phy_node(struct fwnode_handle *fwnode) > > +{ > > + struct fwnode_handle *phy_node; > > + > > + /* Only phy-handle is used for ACPI */ > > + phy_node = fwnode_find_reference(fwnode, "phy-handle", 0); > > + if (is_acpi_node(fwnode) || !IS_ERR(phy_node)) > > + return phy_node; > > + phy_node = fwnode_find_reference(fwnode, "phy", 0); > > + if (IS_ERR(phy_node)) > > + phy_node = fwnode_find_reference(fwnode, "phy-device", 0); > > + return phy_node; > > Looking into the patterns in this code I would perhaps refactor it the > following way: > > /* First try "phy-handle" as most common in use */ > phy_node = fwnode_find_reference(fwnode, "phy-handle", 0); > /* Only phy-handle is used for ACPI */ > if (is_acpi_node(fwnode)) > return phy_node; > if (!IS_ERR(phy_node)) > return phy_node; I'm not sure why you want the above to be two if () statements instead of one? I would change the ordering anyway, that is if (!IS_ERR(phy_node) || is_acpi_node(fwnode)) return phy_node; And I think that the is_acpi_node() check is there to return the error code right away so as to avoid returning a "not found" error later. But I'm not sure if this is really necessary. Namely, if nothing depends on the specific error code returned by this function, it would be somewhat cleaner to let the code below run if phy_node is an error pointer in the ACPI case, because in that case the code below will produce an error pointer anyway. > /* Try "phy" reference */ > phy_node = fwnode_find_reference(fwnode, "phy", 0); > if (!IS_ERR(phy_node)) > return phy_node; > /* At last try "phy-device" reference */ > return fwnode_find_reference(fwnode, "phy-device", 0); > > > +}