Received: by 2002:a05:7412:8d10:b0:f3:1519:9f41 with SMTP id bj16csp6543431rdb; Fri, 15 Dec 2023 01:16:52 -0800 (PST) X-Google-Smtp-Source: AGHT+IEFmyh9wW9X9LwEntbceoQc26t8tHa9nccHGxGTM9FKzjHrJCMev4lQpvoN+X3782wkvft0 X-Received: by 2002:a05:620a:26a4:b0:77f:d52:f791 with SMTP id c36-20020a05620a26a400b0077f0d52f791mr13386702qkp.68.1702631812323; Fri, 15 Dec 2023 01:16:52 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702631812; cv=none; d=google.com; s=arc-20160816; b=riuqK5iSg4jRegGvRtVZkQJla0ioIBZs912RmQEkiSC0A8+s7KrNJPp7j7RdmATQQU DLngZvKqv1vgPOwNLA7VtW9m55dM9tQp86c5xElXQrkqjHvFEtgokWgSc0unSZCw22aO 7ae31Eg8AADAJFjhxB/cGlfjpiU6Qaj0nwHEHOPlsJz9P1SShFPZI98bdx2d4cfIEKQ2 HuFpbmXwtOztvxP7yXloGzWCb34JXM8CxlhOu/QgqJM47r3vzY1YLSYyw9F0oH1R+TfI zFuYslF94hJr9BdOSoUSYxLpQIzDQIUz/pcyqrqUBYhRL290ZS/xNIzbOp6G7hz5tL0r Wulw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:in-reply-to:content-disposition:mime-version :list-unsubscribe:list-subscribe:list-id:precedence:references :message-id:subject:cc:to:from:date:dkim-signature; bh=L8q7VvWi1VZ46dfphKynAQs7E8HdoHkmIWEzQFSMVyE=; fh=LGSOQ228QAUynDa/vXbuzvXIWpQ7ysUFfAoDYzISVGE=; b=cyJWW8vvc7001z4go5cfqen9dub9KJNv5iyuysND6mXh3xyEiunc5+PfAdBkzVM1OB 3T6WTAUoWTmj9fO/CpzmLE6d4+IDUHzY7fHRuJ+QnVjW4wsSg3jMhVxLhj5QB8jghkzJ w7O8FZiNLF1S7q0dqMEGg/wcIE4iLOPca0cNo34NAfYxguV/qpDhXL1EGZaTf+ZyW/3T 8bAP5UORXQal/yJtuP3AxZPsO9UvSmFxDYxWb5sADdgImxdHqnAxzG6Lfwj4am2+9LzF usQSst4Oagb49Fz0JDKHQreu6lamZqcAxxuJar1WtswtMyuPpUU4XZNSWg+FSA2nGD+L CV9Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail (test mode) header.i=@armlinux.org.uk header.s=pandora-2019 header.b=SIjj4ClP; spf=pass (google.com: domain of linux-kernel+bounces-678-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-678-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=armlinux.org.uk Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id qs14-20020a05620a394e00b0077dabd088desi14438476qkn.388.2023.12.15.01.16.52 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Dec 2023 01:16:52 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-678-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=fail (test mode) header.i=@armlinux.org.uk header.s=pandora-2019 header.b=SIjj4ClP; spf=pass (google.com: domain of linux-kernel+bounces-678-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-678-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=armlinux.org.uk Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 0BE491C2288D for ; Fri, 15 Dec 2023 09:16:52 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 7B36C1803F; Fri, 15 Dec 2023 09:16:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=armlinux.org.uk header.i=@armlinux.org.uk header.b="SIjj4ClP" X-Original-To: linux-kernel@vger.kernel.org Received: from pandora.armlinux.org.uk (pandora.armlinux.org.uk [78.32.30.218]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id AE16117994; Fri, 15 Dec 2023 09:16:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=armlinux.org.uk Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=armlinux.org.uk 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=L8q7VvWi1VZ46dfphKynAQs7E8HdoHkmIWEzQFSMVyE=; b=SIjj4ClPT3DhO7FFkPTNVYr2C8 gviPBKUqPoArRpx79RrpmusZ5y0EWM4mPieRb1vEfkyOhKA+WZwXAU6nCbSMDOTr0vgby2+PDNY9L vu+VbR5I7xPaTqy683MTpCtvow4sto2z4wA+peTFrZTnbYper+uFuAhVHdJ6HjfgAu7e2v3p5oMbe zKQORm7otDe5osLhY9dJUnAuRugn0uYewMwr3MKeCTYB4bhYREsq6MD3i5uoZYx39nmuNPaSHTpeJ ERJtA0NUJ8kkB+GJNcRY/HHifYVSKaZNXjMO+r25CLHcTLsxXaT1MBk4uDq3pKmBqdjeE9We4EsfN +29y8HlQ==; Received: from shell.armlinux.org.uk ([fd8f:7570:feb6:1:5054:ff:fe00:4ec]:42556) by pandora.armlinux.org.uk with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1rE4J1-0002QP-2g; Fri, 15 Dec 2023 09:16:27 +0000 Received: from linux by shell.armlinux.org.uk with local (Exim 4.94.2) (envelope-from ) id 1rE4J1-0003Tl-Tk; Fri, 15 Dec 2023 09:16:27 +0000 Date: Fri, 15 Dec 2023 09:16:27 +0000 From: "Russell King (Oracle)" To: Christian Marangi Cc: Florian Fainelli , Broadcom internal kernel review list , Andrew Lunn , Heiner Kallweit , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Vladimir Oltean , David Epping , Harini Katakam , netdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [net-next PATCH v7 2/4] net: phy: extend PHY package API to support multiple global address Message-ID: References: <20231214121026.4340-1-ansuelsmth@gmail.com> <20231214121026.4340-3-ansuelsmth@gmail.com> <657b921d.5d0a0220.7815b.87dd@mx.google.com> <657b9999.5d0a0220.ec414.ed08@mx.google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <657b9999.5d0a0220.ec414.ed08@mx.google.com> Sender: Russell King (Oracle) On Thu, Dec 14, 2023 at 06:29:28PM +0100, Christian Marangi wrote: > On Thu, Dec 14, 2023 at 11:54:26PM +0000, Russell King (Oracle) wrote: > > On Thu, Dec 14, 2023 at 05:54:51PM +0100, Christian Marangi wrote: > > > What I don't like is the wrap check. > > > > > > But I wonder... Isn't it easier to have > > > > > > unsigned int addr = shared->base_addr + addr_offset; > > > > > > and check if >= PHY_MAC_ADDR? > > > > > > Everything is unsigned (so no negative case) and wrap is not possible as > > > nothing is downcasted. > > > > I'm afraid that I LOL'd at "wrap is not possible" ! Of course it's > > possible. Here's an example: > > > > Yes I just think about it and I'm also LOLing at the "not possible"... > > > shared->base_addr is 20 > > addr_offset is ~0 (or -1 casted to an unsigned int) > > addr becomes 19 > > > > How about: > > > > if (addr_offset >= PHY_MAX_ADDR) > > return -EIO; > > > > addr = shared->base_addr + addr_offset; > > if (addr >= PHY_MAX_ADDR) > > return -EIO; > > > > and then we could keep 'addr' as u8. > > Ok just to make sure > > static int phy_package_address(struct phy_device *phydev, > unsigned int addr_offset) > { > struct phy_package_shared *shared = phydev->shared; > unsigned int addr; > > if (addr_offset >= PHY_MAX_ADDR) > return -EIO; > > addr = shared->base_addr + addr_offset; > if (addr >= PHY_ADDR_MAX) > return -EIO; > > /* we know that addr will be in the range 0..31 and thus the > * implicit cast to a signed int is not a problem. > */ > return addr; > } Yep. > And call u8 addr = phy_package_address(phydev, addr_offset); This has to be int to cater for -EIO > Maybe one if can be skipped with the following fun thing? > > static int phy_package_address(struct phy_device *phydev, > unsigned int addr_offset) > { > struct phy_package_shared *shared = phydev->shared; > u8 base_addr = shared->base_addr; > > if (addr_offset >= PHY_MAX_ADDR - base_addr) > return -EIO; That also works. > > /* we know that addr will be in the range 0..31 and thus the > * implicit cast to a signed int is not a problem. > */ > return base_addr + addr_offset; > } > > (don't hate me it's late here and my brain is half working ahahha) > > > > > Honestly, I have wondered why the mdio bus address is a signed int, but > > never decided to do anything about it. > > > > Maybe because direct usage of mdiobus_ is discouraged and phy_write will > use an addr that is already validated. It's discourged in PHY drivers where one has the phy_device. -- RMK's Patch system: https://www.armlinux.org.uk/developer/patches/ FTTP is here! 80Mbps down 10Mbps up. Decent connectivity at last!