Received: by 2002:a05:7412:8d10:b0:f3:1519:9f41 with SMTP id bj16csp6132975rdb; Thu, 14 Dec 2023 09:07:11 -0800 (PST) X-Google-Smtp-Source: AGHT+IHeDfvhKZKR+vo5Xz+2wSnI46r8b6+Jr/toST/9GbbKtfHqX6J71EIyCwDg/MNpbNaO9+b5 X-Received: by 2002:a05:6a21:81af:b0:18c:44d3:d314 with SMTP id pd47-20020a056a2181af00b0018c44d3d314mr9833059pzb.10.1702573631399; Thu, 14 Dec 2023 09:07:11 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702573631; cv=none; d=google.com; s=arc-20160816; b=hnvHrsOyVwInL8NQa38WD0qp/DtLqmJu+iktlEOmv+6lfEzwWRvv3wlNrOTykKz6pT Wjp/XOOWlnahT+2Ux9xoCrw2Ena01qhMpFg6HQCIkCq8q485SHCL9lBMIO9SHp2pxsag pwOw34vna7KkWA4PqM9SPQo+IqGsgerZTSeypW3OY86X2gls6haEI+JDcOFJhbiBmFlv cpviwSZ/zUypTNFsX8FPrW6j+9neIp2TPA5w3mO1PETfXSoS3xb/Sn4Co1vaEiZ9jVEf /ePTuJnyFdw0HOkfpJUd1GjiAY+iUeF6I8eVYmNfta75DaSQVI5mdc7waAwHBMJX8yy4 Jwyg== 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=UGl67CfBtJWBJaR6WMT8VKfuJbenwbqnt8kzBiGAbeg=; fh=LGSOQ228QAUynDa/vXbuzvXIWpQ7ysUFfAoDYzISVGE=; b=R15wUN6DU2Ld1IyGS6fTXn62w4T/cDalkHuzP/883fd7+7hsXLd4GRObp7cRwjOgsP PTme3h5rHZE9aTX8EX7HBNzRWQsAkAu8q5QHrgvzttbXWfrrjTnbs/q7dLhMbbUAHvLv qhUNeAqwZReTDmeuxiKM0sMs5j0I18kD/c8GNtgiq9lKOEZUqjcQWqGbR1inhAiXAmjR RWJvr3e+jIgfLsqz68n5R8wzl35VFXTqI5yUnAGmvJO1gTuyNZ/4zAIDNYQa9gAec1cz GWnptOBnfK7IDyPBIXtw2pZ5YaikhJGkxWYdQWd3lHps5taznRaWNCvauCr6PK79eLNi Vkiw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail (test mode) header.i=@armlinux.org.uk header.s=pandora-2019 header.b=a6qt6zEs; 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 ka17-20020a056a00939100b006c0e02cdadcsi11665554pfb.208.2023.12.14.09.06.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Dec 2023 09:07:11 -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=a6qt6zEs; 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 9760F80A5B78; Thu, 14 Dec 2023 09:05:58 -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 S230260AbjLNRFm (ORCPT + 99 others); Thu, 14 Dec 2023 12:05:42 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46458 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1443630AbjLNRFl (ORCPT ); Thu, 14 Dec 2023 12:05:41 -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 E1541B2; Thu, 14 Dec 2023 09:05:47 -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=UGl67CfBtJWBJaR6WMT8VKfuJbenwbqnt8kzBiGAbeg=; b=a6qt6zEsUIzWoWtSp8KRomO448 hdn2McdZex7LKEW0yFTsRuln/OC86klDRrmCwt/NZqAOD/IdkpvMB+QqO5ab5XVdYLU973+p9ylf9 F7kgSZelT65kj7p9n2AcbBowq8mkA+EvXYSMmp6yJJ6b1w1qmDSnwMrIVW0K6rwWa1r6fX+/zM5J3 XIRjGJzfn/tJZeUU71VsCJjxr7cznfuyRk48aQV/cJ5AhUV2bjQGMf0waNVhV4GVdYH/5YPqvfVsM ptn8ArO9LemeuDWF2rPIl3rJtOU+v1Zd8OwieIeLEOH8+bCHFvw7mmbA7XR+7Z70TOVpWG98Kh7gs AIlFWbDw==; Received: from shell.armlinux.org.uk ([fd8f:7570:feb6:1:5054:ff:fe00:4ec]:41814) by pandora.armlinux.org.uk with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1rDp9W-0001jJ-0I; Thu, 14 Dec 2023 17:05:38 +0000 Received: from linux by shell.armlinux.org.uk with local (Exim 4.94.2) (envelope-from ) id 1rDp9X-0002hs-Nf; Thu, 14 Dec 2023 17:05:39 +0000 Date: Thu, 14 Dec 2023 17:05:39 +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> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20231214121026.4340-3-ansuelsmth@gmail.com> 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]); Thu, 14 Dec 2023 09:05:58 -0800 (PST) On Thu, Dec 14, 2023 at 01:10:24PM +0100, Christian Marangi wrote: > @@ -1998,46 +1999,54 @@ int __phy_hwtstamp_set(struct phy_device *phydev, > struct kernel_hwtstamp_config *config, > struct netlink_ext_ack *extack); > > -static inline int phy_package_read(struct phy_device *phydev, u32 regnum) > +static inline int phy_package_read(struct phy_device *phydev, > + unsigned int addr_offset, u32 regnum) > { > struct phy_package_shared *shared = phydev->shared; > + u8 addr = shared->base_addr + addr_offset; > > - if (!shared) > + if (addr >= PHY_MAX_ADDR) > return -EIO; I did notice that you're using u8 in patch 1 as well - and while it's fine in patch 1 (because we validate the range of the value we will assign to that variable) that is not the case here. Yes, shared->base_addr is a u8, but addr_offset is an unsigned int, and this is implicitly cast-down to a u8 in the calculation of addr, chopping off the bits above bit 7. How about this approach: static int phy_package_address(struct phy_device *phydev, unsigned int addr_offset) { struct phy_package_shared *shared = phydev->shared; unsigned int addr = shared->addr + addr_offset; /* detect wrap */ if (addr < addr_offset) return -EIO; /* detect invalid address */ 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; } and then these functions all become: int addr = phy_package_address(phydev, addr_offset); if (addr < 0) return addr; I'll give you that this is belt and braces, but it avoids problems should a negative errno value be passed in as addr_offset (which will be cast to a very large positive integer.) Andrew, any opinions on how far this should be taken? -- RMK's Patch system: https://www.armlinux.org.uk/developer/patches/ FTTP is here! 80Mbps down 10Mbps up. Decent connectivity at last!