Received: by 2002:a05:7412:8d10:b0:f3:1519:9f41 with SMTP id bj16csp1333568rdb; Wed, 6 Dec 2023 16:08:09 -0800 (PST) X-Google-Smtp-Source: AGHT+IE5aRnsA6ciQlwM8NH4p8bTIK+UOqi8w1CvEZQv9zU9hI6AYXN5idSKsCClPzNMV9uVvWla X-Received: by 2002:a17:902:bf0b:b0:1d1:cc20:451d with SMTP id bi11-20020a170902bf0b00b001d1cc20451dmr2151096plb.65.1701907689610; Wed, 06 Dec 2023 16:08:09 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701907689; cv=none; d=google.com; s=arc-20160816; b=CEtJ3Qfdgv/yhKa7R9f1spIA2I+M2YwPbiY9bvbjeClDdH6rj5Dd13mul2Pxc9RBM8 xoHvDTHt4Csd170j336jwWU8abAI6qWeypnHV+YDj80eEROXrAkc4qiQ02Sytl/xVPh5 S2CPfKPl9MecUy68Pbi8ZOPOt1ic4U2aDdjIr7IpNnB+ge/f8b2g4KCY6DUWQRC6h9Mm SDo4EDNOMt6OcV9yW2ZCKD1va09Exid8riwQgNAqKnGhvNp7ckQoCOFk9AutJrIh3cft 0TyikEFHAfyvZfcTxtP1AWtMkUp7UxNpe/L83LCHixB0UuEI5htC6PNv+dqF9H03nJWg xs3A== 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; bh=+a7WGq/Q1VmA74C6RCoEzcxtkMSaMJKT84Yz/Ifv3Ko=; fh=uY+7ONsNykR7xnB1nTQcaVQTLmIvLm97L6svsWS9qxw=; b=WE0uybVXRnUjQbwB6ij/91/UNYWSQvEJ2pw6mZwVxma+luxIqHFrTDpUJSxxt/Ys8b +HepYDfDPisZAzFwoMvWV27tXcio4m2mt0PtdlQbB5vpwKTDFNHo+wLknSNd7o7Ghh9t qJVehI4hGcj1DkRASc95WGLPZdPDGzpHfZRIeBIsBDGeWgPf3wG1Vya8bHW826wGtlJX HKdIgFo0WNyjVNz7KOkp+AoUvjA83sCxMsEtj8IXsoUph1rnA5OVW2UKUaTOX6wB7T7g DHZssxWkpULigzJG/iywill3/0UNWDCvM4LHBBUdx7ScaW2/e5IeYGr4HloI6mc5Q9Xy Sx3Q== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from agentk.vger.email (agentk.vger.email. [23.128.96.32]) by mx.google.com with ESMTPS id z11-20020a1709027e8b00b001c754f13381si52566pla.455.2023.12.06.16.07.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 Dec 2023 16:08:09 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) client-ip=23.128.96.32; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by agentk.vger.email (Postfix) with ESMTP id 0E14080ADEE1; Wed, 6 Dec 2023 16:07:52 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1441805AbjLGAHi (ORCPT + 99 others); Wed, 6 Dec 2023 19:07:38 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38210 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232043AbjLGAHf (ORCPT ); Wed, 6 Dec 2023 19:07:35 -0500 Received: from pidgin.makrotopia.org (pidgin.makrotopia.org [185.142.180.65]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BE1ECC9; Wed, 6 Dec 2023 16:07:40 -0800 (PST) Received: from local by pidgin.makrotopia.org with esmtpsa (TLS1.3:TLS_AES_256_GCM_SHA384:256) (Exim 4.96.2) (envelope-from ) id 1rB1vB-0000Eb-3C; Thu, 07 Dec 2023 00:07:19 +0000 Date: Thu, 7 Dec 2023 00:07:14 +0000 From: Daniel Golle To: "Russell King (Oracle)" Cc: "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Chunfeng Yun , Vinod Koul , Kishon Vijay Abraham I , Felix Fietkau , John Crispin , Sean Wang , Mark Lee , Lorenzo Bianconi , Matthias Brugger , AngeloGioacchino Del Regno , Andrew Lunn , Heiner Kallweit , Alexander Couzens , Qingfang Deng , SkyLake Huang , Philipp Zabel , netdev@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org, linux-phy@lists.infradead.org Subject: Re: [RFC PATCH v2 3/8] net: pcs: pcs-mtk-lynxi: add platform driver for MT7988 Message-ID: References: <68bb81ac6bf99393c8de256f42e5715626590af8.1701826319.git.daniel@makrotopia.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Spam-Status: No, score=-0.8 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, 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 agentk.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 (agentk.vger.email [0.0.0.0]); Wed, 06 Dec 2023 16:07:52 -0800 (PST) On Wed, Dec 06, 2023 at 05:51:34PM +0000, Russell King (Oracle) wrote: > On Wed, Dec 06, 2023 at 01:44:17AM +0000, Daniel Golle wrote: > > +struct phylink_pcs *mtk_pcs_lynxi_select_pcs(struct device_node *np, phy_interface_t mode) > > +{ > > + struct platform_device *pdev; > > + struct mtk_pcs_lynxi *mpcs; > > + > > + if (!np) > > + return NULL; > > + > > + if (!of_device_is_available(np)) > > + return ERR_PTR(-ENODEV); > > + > > + if (!of_match_node(mtk_pcs_lynxi_of_match, np)) > > + return ERR_PTR(-EINVAL); > > + > > + pdev = of_find_device_by_node(np); > > + if (!pdev || !platform_get_drvdata(pdev)) { > > + if (pdev) > > + put_device(&pdev->dev); > > + return ERR_PTR(-EPROBE_DEFER); > > + } > > + > > + mpcs = platform_get_drvdata(pdev); > > + put_device(&pdev->dev); > > + > > + return &mpcs->pcs; > > +} > > +EXPORT_SYMBOL(mtk_pcs_lynxi_select_pcs); > > If you're going to play games like this, then you must mark the driver > with .suppress_bind_attrs = true to remove the bind/unbind attributes > in userspace that could wreak havoc with the above - because there is > _nothing_ that guarantees that the memory you're returning from this > function will remain intact. Basically, it's racy. Ack, I've set .suppress_bind_attrs = true in the usxgmii driver but forgot to add it here. > Also, I'm not sure I approve of using the "select_pcs" suffix (I > haven't spotted _where_ you use this, but returning EPROBE_DEFER to > phylink's mac_select_pcs() method doesn't do anything to defer any > probe, so that's an entirely misleading error code. EPROBE_DEFER is handled when the function is called by mtk_add_mac() during probe of the Ethernet driver -- which we do want to postpone in case the PCS hasn't been probed yet as at this point that's the best we can do without adding lots of intrastructure to dynamically attach the PCS later on... But true, later the function is being called by mac_select_pcs() and what ever it returns is returned to the caller of mac_select_pcs(). If you think it's better to return ENODEV (or EAGAIN?) I can change that -- from what I could tell, the only error which receives special handling by phylink is -EOPNOTSUPP, everything else just gets passed- through to the callers. > If we are going to have device drivers for PCS, then we need to > seriously think about how we look up PCS and return the phylink_pcs > pointer - and also how we handle the PCS device going away. None of > that should be coded into _any_ PCS driver. I agree -- just wasn't up to design and implement all that at once.