Received: by 2002:a05:7412:40d:b0:e2:908c:2ebd with SMTP id 13csp997550rdf; Wed, 22 Nov 2023 02:53:09 -0800 (PST) X-Google-Smtp-Source: AGHT+IH+TfcpJZbOlza2osxNGZUA/yVIULhanzE5WSzM9TY9kSGPDNjWvPyBWur8uO6gSVTC1HFJ X-Received: by 2002:a17:903:5c3:b0:1cc:3daa:d368 with SMTP id kf3-20020a17090305c300b001cc3daad368mr1776710plb.65.1700650389173; Wed, 22 Nov 2023 02:53:09 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1700650389; cv=none; d=google.com; s=arc-20160816; b=LxrQR0TJPoSfrLqwGz+9AbIPs5/KtvVI6IpJj7kBZUMi/RAyZdW/+xLQLox39nBZfc tv2RWC7P1TqFhizbXDJH3UWmQZW8f4U3LTq1+ZEzfOObwEtV3pv1fEuutlTFozxCJWQa RkDOSYqIgw1wU4m6uR0stWmsIxIwHvDd4Gg7fR6dKNmr0vaKI64qJnnN/VMxIAhUE3bY 234OdS785TiTqQscxxEiFTH2U6HHYvqUMpa6/rJAIxjjFnPQRk8PCQLS9iR6YIriajHm t0lBdtvAJD/aDyJZ8DL8QjkvASWZtS1jJbAvvb8PxfVSibmjb/KY3aAXgAnc4BqOLXhk 9KDA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=ysDRUdNyjhSZ1cu+6OnJUJ9v5mLNhCKHViDqz25JT0w=; fh=/DW9tk17J1/HKn5o0Raq2YQbil5IR2pTxXXFFUnzcms=; b=wHMrNxIYQnCeKzFdMgCqUDhyHRXVTle+Tam1rXTpewf2YROnoSkQEGGgDfy8H1V6Ad dHXXLC5DIJ/wXfXgeEPTjSvcGZ27yYgrTkWj4AeKDtKQbf7lq1Xy0rN/nV22+N7IQJOT 7Isg8cT/gjBnuMBWGrWSSNoIRZ11nNAgRFKT2XzoWci1Ctvz7shTKLd9CplBgD5Z3GgE b0rnE1GfosGbXCZ0G76AL6YsfOddsGGYMvpXE+yv9XORkQfxxnFroA6Fcz8hmoDduTZs Md5EcXrgbo3GAXd2x6PFQPH8RrUYN247oO5+8nPxRo8EKlgBkC2lhwaVwLJpN80B9dwW +H8A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=geQ+d6ci; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:8 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 fry.vger.email (fry.vger.email. [2620:137:e000::3:8]) by mx.google.com with ESMTPS id jg12-20020a17090326cc00b001c20db25108si11701906plb.41.2023.11.22.02.53.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 22 Nov 2023 02:53:09 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:8 as permitted sender) client-ip=2620:137:e000::3:8; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=geQ+d6ci; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:8 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by fry.vger.email (Postfix) with ESMTP id BB1E681BE825; Wed, 22 Nov 2023 02:53:05 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at fry.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231461AbjKVKw5 (ORCPT + 99 others); Wed, 22 Nov 2023 05:52:57 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41498 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229714AbjKVKw4 (ORCPT ); Wed, 22 Nov 2023 05:52:56 -0500 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5D2F092 for ; Wed, 22 Nov 2023 02:52:52 -0800 (PST) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1B3E9C433CA; Wed, 22 Nov 2023 10:52:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1700650372; bh=vg1uuwvQT2sKrRMAHrj+xxj4ykdnjZw0VMW21gcYvUY=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=geQ+d6cieEbtA6MuRMTYcrI7LhaZsSiMpF6Z0EmxIjhHp2YFr4y5kS8qQGPHIReOx Gx/DQ3C+yWG1GL0GjjGldrto/KOVhyORCImcSSnYdzUxWs+Qm7t8ThARNQJtGM+ZJg +XqEQQ4vGjiD0TCYBukcu8HqtqO/OpbFWMV3SKenBjLcc1921paWbPMp51QrYNOdTi TAkG25biHSjNdtGJPixedr+oJQM/EI46CyD1CLw+EHpwBxyiVd9S3HLkAuxnLBccfN HBUxrr4qET/KN5se9nxEXapkamp5Gas3ngegBl2oENiIc1JZ9eccBVbxE9FimJYdrO +iuhip3TAaSAA== Date: Wed, 22 Nov 2023 10:52:43 +0000 From: Simon Horman To: Christian Marangi Cc: "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Andy Gross , Bjorn Andersson , Konrad Dybcio , Andrew Lunn , Heiner Kallweit , Russell King , Florian Fainelli , Broadcom internal kernel review list , Daniel Golle , Qingfang Deng , SkyLake Huang , Matthias Brugger , AngeloGioacchino Del Regno , David Epping , Vladimir Oltean , "Russell King (Oracle)" , Harini Katakam , Robert Marko , netdev@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-msm@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org Subject: Re: [net-next RFC PATCH 04/14] net: phy: add initial support for PHY package in DT Message-ID: <20231122105243.GB28959@kernel.org> References: <20231120135041.15259-1-ansuelsmth@gmail.com> <20231120135041.15259-5-ansuelsmth@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20231120135041.15259-5-ansuelsmth@gmail.com> X-Spam-Status: No, score=-1.3 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on fry.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (fry.vger.email [0.0.0.0]); Wed, 22 Nov 2023 02:53:05 -0800 (PST) On Mon, Nov 20, 2023 at 02:50:31PM +0100, Christian Marangi wrote: > Add initial support for PHY package in DT. > > Make it easier to define PHY package and describe the global PHY > directly in DT by refereincing them by phandles instead of custom > functions in each PHY driver. > > Each PHY in a package needs to be defined in a dedicated node in the > mdio node. This dedicated node needs to have the compatible set to > "ethernet-phy-package" and define "global-phys" and "#global-phy-cells" > respectively to a list of phandle to the global phy to define for the > PHY package and 0 for cells as the phandle won't take any args. > > With this defined, the generic PHY probe will join each PHY in this > dedicated node to the package. > > PHY driver MUST set the required global PHY count in > .phy_package_global_phy_num to correctly verify that DT define the > correct number of phandle to the required global PHY. > > mdio_bus.c and of_mdio.c is updated to now support and parse also > PHY package subnote that have the compatible "phy-package". > > Signed-off-by: Christian Marangi Hi Christian, I was a little hasty in hitting send on my previous message. Please find some more minor feedback from my side below. ... > diff --git a/drivers/net/mdio/of_mdio.c b/drivers/net/mdio/of_mdio.c > index 64ebcb6d235c..bb910651118f 100644 > --- a/drivers/net/mdio/of_mdio.c > +++ b/drivers/net/mdio/of_mdio.c > @@ -139,6 +139,44 @@ bool of_mdiobus_child_is_phy(struct device_node *child) > } > EXPORT_SYMBOL(of_mdiobus_child_is_phy); > > +static int __of_mdiobus_parse_phys(struct mii_bus *mdio, struct device_node *np, > + bool *scanphys) > +{ > + struct device_node *child; > + int addr, rc; > + > + /* Loop over the child nodes and register a phy_device for each phy */ > + for_each_available_child_of_node(np, child) { > + if (of_device_is_compatible(child, "ethernet-phy-package")) { > + rc = __of_mdiobus_parse_phys(mdio, child, scanphys); > + if (rc && rc != -ENODEV) > + return rc; for_each_available_child_of_node() makes calls to of_node_get() and of_node_put(), so when jumping out of a loop it is necessary to call of_node_put(), in this case of_node_put(child). As flagged by Coccinelle. Also flagged in of_mdiobus_find_phy() both before and after this patch. > + > + continue; > + } > + > + addr = of_mdio_parse_addr(&mdio->dev, child); > + if (addr < 0) { > + *scanphys = true; > + continue; > + } > + > + if (of_mdiobus_child_is_phy(child)) > + rc = of_mdiobus_register_phy(mdio, child, addr); > + else > + rc = of_mdiobus_register_device(mdio, child, addr); > + > + if (rc == -ENODEV) > + dev_err(&mdio->dev, > + "MDIO device at address %d is missing.\n", > + addr); > + else if (rc) > + return rc; > + } > + > + return 0; > +} > + > /** > * __of_mdiobus_register - Register mii_bus and create PHYs from the device tree > * @mdio: pointer to mii_bus structure > @@ -180,25 +218,9 @@ int __of_mdiobus_register(struct mii_bus *mdio, struct device_node *np, > return rc; > > /* Loop over the child nodes and register a phy_device for each phy */ > - for_each_available_child_of_node(np, child) { > - addr = of_mdio_parse_addr(&mdio->dev, child); > - if (addr < 0) { > - scanphys = true; > - continue; > - } > - > - if (of_mdiobus_child_is_phy(child)) > - rc = of_mdiobus_register_phy(mdio, child, addr); > - else > - rc = of_mdiobus_register_device(mdio, child, addr); > - > - if (rc == -ENODEV) > - dev_err(&mdio->dev, > - "MDIO device at address %d is missing.\n", > - addr); > - else if (rc) > - goto unregister; > - } > + rc = __of_mdiobus_parse_phys(mdio, np, &scanphys); > + if (rc) > + goto unregister; Jumping to unregister will call of_node_put(child), however child appears to be uninitialised here. Flagged by clang-16 W=1 build, and Smatch. > > if (!scanphys) > return 0; ...