Received: by 2002:ab2:710b:0:b0:1ef:a325:1205 with SMTP id z11csp1294685lql; Tue, 12 Mar 2024 12:43:53 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWKlM8cRmQ/JjszpGnLLm2qbbREvBxPPXrDsMiOhndefrkQARjXn2ty+CXEUd36NQ4GTQSLT8RdKY7PS4qoahsgH880Ry8K3KQ1omAEUQ== X-Google-Smtp-Source: AGHT+IFjAeaoNcPR/IFM49neT2izJ8sQrhFsdXRh/fvhVtJmzlMzCs0NtckSOaeUeC3lqbF7srMV X-Received: by 2002:a17:903:18f:b0:1dd:5bd5:5c21 with SMTP id z15-20020a170903018f00b001dd5bd55c21mr11578516plg.55.1710272632894; Tue, 12 Mar 2024 12:43:52 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1710272632; cv=pass; d=google.com; s=arc-20160816; b=YKjbO8jG7+M8GtI05Svu+PHhvvfuLBHHDmSG2t4pZ7l8xazaygZ0na2dA7aJJVlN+Y ArwYr70DP2PYRAV4h3ebxUR2/ovWjMMu5fZOsnFgdP3+OaOfI5sb4masCB0tfWcF7xud ylKabRrwQSRvDT+uMj4Mgp/E4fl1rm4bb7sDqN2xEG4ZxwY6eZeN3OqqxpbSvjoz4wZS nmHx3zEpEbIDaK4Du3o+5gy72e8xaFLlBp6T9k9e/SwcYitoiqmqZ3klx0hOqElE1rOZ 5+yJ7mnGYhhx5KVFwQXeJ94X7gqPqreIkChNEl3xzQ0ZHoBDiNeYC8G8322lI59tKCvC tCVQ== ARC-Message-Signature: i=2; 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=jQDsOwuAAPx1Ek5GFlKu13YSBeA1J7htLKf6fXH4K/4=; fh=m21+p8A38LqRJowoqLsQZpCf12r8Ml5N6e0ngTKG7og=; b=ElP9N8286aKd5/9mMJBV5pyfJ4WfjDuBP3kHvMxNr+TR8gDIv0/lsddeAGmmlWlXHP Ik4VqBCvj/3bJqnGPq7GJ2JiXT+9+st17fqrQJXCODUD7a/psji5umFdUsvVLz+B7QDY nabPB6aClaYknssD4fY88MDHh6IOpLSwRzbFWB0U9KVZ6RogL34h8aSsnlqQWu87teQL p3AmsHHOq1O/cfCk0MTCuT7cNmI9GSkoJ4c68jK3RpbEZ3q4NMZNwld8XIGeqhZnofKu pIVWTcZY6Ud2Qz5ijeNSQgkICB/N9JLLNzLY6p/p/teorYm9JpXl1CN+O60a5Exnod44 c0gQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=fail (test mode) header.i=@armlinux.org.uk header.s=pandora-2019 header.b=kOEdfTja; arc=pass (i=1 dkim=pass dkdomain=armlinux.org.uk dmarc=pass fromdomain=armlinux.org.uk); spf=pass (google.com: domain of linux-kernel+bounces-100719-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-100719-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 sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id d1-20020a170902cec100b001dda17fe7b6si4365726plg.590.2024.03.12.12.43.52 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Mar 2024 12:43:52 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-100719-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; dkim=fail (test mode) header.i=@armlinux.org.uk header.s=pandora-2019 header.b=kOEdfTja; arc=pass (i=1 dkim=pass dkdomain=armlinux.org.uk dmarc=pass fromdomain=armlinux.org.uk); spf=pass (google.com: domain of linux-kernel+bounces-100719-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-100719-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 sy.mirrors.kernel.org (Postfix) with ESMTPS id D7C91B23B6E for ; Tue, 12 Mar 2024 19:42:43 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id B5C17142654; Tue, 12 Mar 2024 19:42:35 +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="kOEdfTja" 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 1808123A6; Tue, 12 Mar 2024 19:42:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=78.32.30.218 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710272554; cv=none; b=T4hrfiQF/ToRL3i1fJV0Sdw/TanshCiOIwHJsM8wO4F2ecE/zux3UZux0NCLZEZLvIdl9WXEpKSK8WZ1MfjZx3k9wBP8zs7vwNpjfF0FmLfedYC2CKDFldg4HZLmn5EqFsbkslDS6PCWv+V+ss2Xh+NNd2fpgbOXpyu7AnnWwAA= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710272554; c=relaxed/simple; bh=68ALfO905AYUlS53YoIMyGx+1CjoW/ERgDY1HwnqKyM=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=osypJZP+/FgeYKj1ELwZOBg02s2rADZiVntSjz84cNNxcVqGN187CL0lgjehal4S0YLIkJvVLmh+6M8eIYj29TeauZ6WXjWvCZdN4G1IJXwSKPD9tCwkLanSxSTFDlK6vRjurfuJ23j1Kp+LskrxkZmg7YI7OcIOWpMw7Y8cvvE= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=armlinux.org.uk; spf=none smtp.mailfrom=armlinux.org.uk; dkim=pass (2048-bit key) header.d=armlinux.org.uk header.i=@armlinux.org.uk header.b=kOEdfTja; arc=none smtp.client-ip=78.32.30.218 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=jQDsOwuAAPx1Ek5GFlKu13YSBeA1J7htLKf6fXH4K/4=; b=kOEdfTja/SP3czPoQDuH0Qgb6y XXOoFSOI3Zrr7xGIO2sqKJXsFgSUzyS/XcDM/fJgvHhHWF1eQLtUm1B9HOJkWQPKcvl59nhYiXoSq XpM5qLdNVROYUvoDHkhYfaScouzQsPs0oAy2dW0VgYIs9mhiVUeNzH0zb5YpkUo4VM7TjiZObP3Rw I1c6CKXVS5RCVzFf7m3GCd/45VS4TYG4i7uMlrBSbhw9g6yFi4u+gsSCJ7enu+PigdMO+8/tHEIAl oBbvMVJnSY94YJXXsswkIsplMCqakeXbNPUBP8yVPHtLV35SVGaRBU0K2TwduWP9VW/DRmz/BBpy7 8cnsIKmQ==; Received: from shell.armlinux.org.uk ([fd8f:7570:feb6:1:5054:ff:fe00:4ec]:37158) by pandora.armlinux.org.uk with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1rk80y-0006vH-1d; Tue, 12 Mar 2024 19:42:20 +0000 Received: from linux by shell.armlinux.org.uk with local (Exim 4.94.2) (envelope-from ) id 1rk80u-0003oA-J8; Tue, 12 Mar 2024 19:42:16 +0000 Date: Tue, 12 Mar 2024 19:42:16 +0000 From: "Russell King (Oracle)" To: Doug Berger Cc: Florian Fainelli , Daniil Dulov , Jakub Kicinski , Florian Fainelli , Broadcom internal kernel review list , Andrew Lunn , Heiner Kallweit , "David S. Miller" , Eric Dumazet , Paolo Abeni , netdev@vger.kernel.org, linux-kernel@vger.kernel.org, lvc-project@linuxtesting.org Subject: Re: [PATCH net-next] net: phy: mdio-bcm-unimac: Cast denominator to unsigned long to avoid overflow Message-ID: References: <20240312165358.7712-1-d.dulov@aladdin.ru> 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: Sender: Russell King (Oracle) On Tue, Mar 12, 2024 at 12:23:20PM -0700, Doug Berger wrote: > On 3/12/2024 10:23 AM, Florian Fainelli wrote: > > On 3/12/24 10:18, Russell King (Oracle) wrote: > > > On Tue, Mar 12, 2024 at 07:53:58PM +0300, Daniil Dulov wrote: > > > > The expression priv->clk_freq * 2 can lead to overflow that will cause > > > > a division by zero. So, let's cast it to unsigned long to avoid it. > > > > > > How does casting this help? "unsigned long" can still be 32-bit. > > > Maybe unimac_mdio_probe() should be validating the value it read from > > > DT won't overflow? I suspect that a value of 2.1GHz is way too large > > > for this property in any case. > > > > > > https://en.wikipedia.org/wiki/Management_Data_Input/Output#Electrical_specification > > > > > > (note, this driver is clause-22 only.) > > > > > > > Had commented on the previous version (not sure why this was not > > prefixed with v2) that the maximum clock frequency for this clock is > > 250MHz, the driver could check that to prevent for an overflow, most > > certainly. > > Could also use: > - div = (rate / (2 * priv->clk_freq)) - 1; > + div = ((rate / priv->clk_freq) >> 1) - 1; > which is mathematically equivalent without the risk of overflow. What's the point when the maximum clock frequency that the driver should allow fits within u32, nay u28? -- RMK's Patch system: https://www.armlinux.org.uk/developer/patches/ FTTP is here! 80Mbps down 10Mbps up. Decent connectivity at last!