Received: by 2002:a05:7412:8d10:b0:f3:1519:9f41 with SMTP id bj16csp1149875rdb; Wed, 6 Dec 2023 09:52:21 -0800 (PST) X-Google-Smtp-Source: AGHT+IEhvG3MfbQEefEJ0Jls6whocm8GZIxrQay5y4Y1QqA1v8i3l4bcqAhYVK9Isf8dzoddZ5nE X-Received: by 2002:a05:6a00:4218:b0:6ce:8113:42c9 with SMTP id cd24-20020a056a00421800b006ce811342c9mr1037338pfb.8.1701885141650; Wed, 06 Dec 2023 09:52:21 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701885141; cv=none; d=google.com; s=arc-20160816; b=jPqhpDUXxD3dhfykDDS2SGO9e4L9ttL1B+XzO33RfMvFLbE9d6sJ4dTAoQAQ8/swiu i4+dleHVYeC1dA7JeNp6SrB/eIegAlFII+bVaWuvEF89ZxNLMhK3u5JLhss6+5Vbpw3p ImhEbJgRBLTlU1SFTGqnsnHxYj5XqIoQ8xm3Dau9A70pzrA3SELwVnu5L+jyoQqJBNNm nC+9huIACz5acOZh6eQtKDv0CpVK9I7OchqTOZbWxk6q+3pycyIsXrGCXKxl3w/tfNYY sp18I42vSUtFJ7TPn/NzbkMynJAcPW9aMoHszfPtgWKj0UZ1Ysu3THPZtjKTPjbCQBKV XFdQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature; bh=xtEyYJ2fL6Bd/0ZQMBJdBd4JHYGCVwVdwTisB+sS+6c=; fh=kJcXMp4O4T0eOgyy/+VGeOLmnrmVyNT+X7mcHhSI3lc=; b=RDfD389lWjr6ymtkDAHwj4L+NeWra2Jlbt2BOROYT8NBuuMRyGnGVvFzc6AxTWnzns Gc4lYlOSPWlS3HglUFtjiqUS+aOM/JBL05U11z0cAezfFskwDIKvBsJ/ip1f66zadefI o2HpJF/muTFLsBF+wgx9ZuLBiL9IkJA7mSH5wpbHyGaavQFJMizus460ZE7YxE0QicTp bRU7BubMeSfDi5t6LZMcEoMiqR/C7XNGuMivjggpWSNH10z7tn9ism2WR0YvrNhNuka4 jZ92MDxUku9OzFbV8TH/5rlhlS2FQYqJBKyoDkLjkeNANBKQtojZJxsc9mHWlcWdEtKw Ziag== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail (test mode) header.i=@armlinux.org.uk header.s=pandora-2019 header.b="zH/nzGG9"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=armlinux.org.uk Return-Path: Received: from morse.vger.email (morse.vger.email. [23.128.96.31]) by mx.google.com with ESMTPS id cb10-20020a056a02070a00b005c662c8da7fsi244861pgb.730.2023.12.06.09.52.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 Dec 2023 09:52:21 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 as permitted sender) client-ip=23.128.96.31; Authentication-Results: mx.google.com; dkim=fail (test mode) header.i=@armlinux.org.uk header.s=pandora-2019 header.b="zH/nzGG9"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=armlinux.org.uk Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by morse.vger.email (Postfix) with ESMTP id 31918826EE06; Wed, 6 Dec 2023 09:52:19 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at morse.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1442716AbjLFRwD (ORCPT + 99 others); Wed, 6 Dec 2023 12:52:03 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38890 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1379751AbjLFRwC (ORCPT ); Wed, 6 Dec 2023 12:52:02 -0500 Received: from pandora.armlinux.org.uk (pandora.armlinux.org.uk [IPv6:2001:4d48:ad52:32c8:5054:ff:fe00:142]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 023F9D5A; Wed, 6 Dec 2023 09:52:05 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=armlinux.org.uk; s=pandora-2019; h=Sender:In-Reply-To:Content-Type: MIME-Version:References:Message-ID:Subject:Cc:To:From:Date:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=xtEyYJ2fL6Bd/0ZQMBJdBd4JHYGCVwVdwTisB+sS+6c=; b=zH/nzGG9C8Rq19EuObrG0yz4pf R93eD9OUVT4C3HY1QMdnol7HJPeIhWZROomiVjeEA5vOZl+0VpkragNpePVgochBymEUcb4tqXCE3 +cjT7SYIHITZerFDewzgXH17u0OEX74lJJgr1l0RhzVh/6LqsKCJhwiwCF7e2roBz4pIBnMbfKqer rsm1nvLceBhbmqXohGYuaIJpwIMyIwAia2po95HwUoKD2VVBzltSdO2VPi64RXLRe2cWd+jlWTZg7 LkNLQNz1yJGIvo73+eEPhriyAPciIpXk+54b0oGxPr5VdsfZ3ol0O1LZA6f3oOXKHIkbRLhsIHA6d 4E4Aed3w==; Received: from shell.armlinux.org.uk ([fd8f:7570:feb6:1:5054:ff:fe00:4ec]:45446) by pandora.armlinux.org.uk with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1rAw3e-0000CW-1J; Wed, 06 Dec 2023 17:51:38 +0000 Received: from linux by shell.armlinux.org.uk with local (Exim 4.94.2) (envelope-from ) id 1rAw3a-0002uY-MH; Wed, 06 Dec 2023 17:51:34 +0000 Date: Wed, 6 Dec 2023 17:51:34 +0000 From: "Russell King (Oracle)" To: Daniel Golle 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: <68bb81ac6bf99393c8de256f42e5715626590af8.1701826319.git.daniel@makrotopia.org> Sender: Russell King (Oracle) X-Spam-Status: No, score=-0.6 required=5.0 tests=DKIM_INVALID,DKIM_SIGNED, 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 morse.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 (morse.vger.email [0.0.0.0]); Wed, 06 Dec 2023 09:52:19 -0800 (PST) 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. 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. 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. -- RMK's Patch system: https://www.armlinux.org.uk/developer/patches/ FTTP is here! 80Mbps down 10Mbps up. Decent connectivity at last!