Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp501840pxj; Fri, 11 Jun 2021 04:44:36 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwwBUdkorNDjEEhdCAaFzmRkd5izbc1qpsVKeozLsEQnLJ0zzyLbVPYOqXtmpD0DkUkeJIX X-Received: by 2002:a17:906:5407:: with SMTP id q7mr3355155ejo.158.1623411876000; Fri, 11 Jun 2021 04:44:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1623411875; cv=none; d=google.com; s=arc-20160816; b=boX+3xPjh2t+cpU1TY4JPFJWfGwG9RtUmUO+QAs7etTKQAZo0KPZHv75Km2Y3qiaud 6d647XvTYSJezpH37RGyxL2yGlcj3d51QxZ+aGUQl73ud8/T3y0nQ0OrSVP13OsaCjQZ JQ64KS1liGmdTlTWdSrhxS9IM3NyThz11ycUZtCFUUCZ485wacMuARTN+3XWXJp5ye/n FkcMOIJ17Z3Af9VhEx1cT1CoSit2NKWR7/h/9qlWKo4+drmhBqCqPImuGp7dgssKmCkU qcv8uWqfPotxSSyqZL33zy49gbc6O2RFYtL8fv+9A9L57OEXpoykqJ184YMK0F20/8Am BsJw== 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; bh=7QOkn9Hd+sQCvI8baU0dpPbaUWUsXvor6j6J5RvuZ0c=; b=ph6EFygGHV4LB1yHfxK64G567fDCuY2ICUZINPQoAWnrVbf+KxBOQ9gZsa4WGPKpC7 CPWiJ5/NQrK9Ilut6HYuRGjH6L5l35Cn9cNYbDBquP9/TEB0kmjIfPusGmSf5+m6Tex/ 24j27RoZ698fXjFxf3S904cxEGRammL22fiBmJ0nPOnsDCHH3XbtKyqbaUWAMydddgMu US45yxXQ9mo+DPitk4NYPPLXyIF/D2oB/UoujarsjSxCFTDrVyJQfc+Etcw3Mvzr+nrL aq4EcmjxMlhZMmukGnJeeFQi1kooG+zVjLACoMBOb/Dr6+YGWD7Z1H8DT1cIqpz6xqLn avjQ== ARC-Authentication-Results: i=1; mx.google.com; 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=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id a8si4664952ejc.334.2021.06.11.04.44.12; Fri, 11 Jun 2021 04:44:35 -0700 (PDT) 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; 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=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231604AbhFKLnY (ORCPT + 99 others); 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-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); > > > +}