Received: by 2002:a05:7412:8d10:b0:f3:1519:9f41 with SMTP id bj16csp5564261rdb; Wed, 13 Dec 2023 12:19:03 -0800 (PST) X-Google-Smtp-Source: AGHT+IEXSwPNf/xpS/5ickAzqoMWjwyhdg3OUDEPGHqkOsZDPZNyN04AEynhfMvjmjeaXhc4SZuK X-Received: by 2002:a05:6e02:1b0d:b0:35f:71bf:e8c7 with SMTP id i13-20020a056e021b0d00b0035f71bfe8c7mr2219209ilv.38.1702498743272; Wed, 13 Dec 2023 12:19:03 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702498743; cv=none; d=google.com; s=arc-20160816; b=gbNwh39loHLEEA6+xDflVDPs4eJaVJp4U69apiBRhELRAD4HizrXsctok8qaCecX9+ qK79y1QUuuFqRgW3Y7SJGixgwvv0MaOjbbZjip/EGSAPVk1tzZ6CdbmNuVdR+h7hUj3f P8gY5fnKokHRm9VRGYxhEbTYVIllCa8UzMiTPopGlt+f85EiwTp0KmfTQJaOENESzaKn s14fXU8tAOIawd09J4FVf+avn54mRMbx4D+FsDhLExhnIN6nJcJcAd0PpoYSwgl/PvD4 U/xtK62jjW7V/WJC3Pac4jdNe9+uqR/34CgR6wEvW2gFvVY+uUNUzDE+yZHpwOxdjkBv zzng== 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=WtvYARQIvVa42V3Ts7AHp1j9HKVZUD4Uobx17kdWS4k=; fh=9p34L7KF7bfMLHxp/5OUkfV8x0r4g3aazwcd2QJ5G+E=; b=NRvoM54isz/bUwm6a1ktSgONkz2uoC+0+MvB4JD0uXOUmvVc8xGGirOnEXrQicsPJj FOiQ1a9JUA6bH0ulw+8rUcBOG+EGgteisiYovrcbhwlhEkf5PP1GQdMkAb4mhbDFJDjn jB/Lu+Bzl8tedApOBYOtcJHthidsGZ437AyU8KLJuTXF0ohUYLdf61wiyBscTLHzx6YB UpoCZJGCwPsed/6bQ4reoHX257NGffF57X0jbM+zHLl+h+AUaTWAur8mL5DHcwQrx3FM P1iNiYaGEQxRLJ8Eezw9nQdnuCK0LFtK4Bi7+HcmMEcHbf+N0Gxx1/ejIrW198mwK6BS pg8g== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail (test mode) header.i=@armlinux.org.uk header.s=pandora-2019 header.b=CRhE5vnt; 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 m184-20020a6326c1000000b0056952b496efsi10144729pgm.366.2023.12.13.12.19.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Dec 2023 12:19:03 -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=CRhE5vnt; 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 9206F826EEBA; Wed, 13 Dec 2023 12:19:00 -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 S233770AbjLMUSl (ORCPT + 99 others); Wed, 13 Dec 2023 15:18:41 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44366 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229671AbjLMUSk (ORCPT ); Wed, 13 Dec 2023 15:18:40 -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 AEEA6E8; Wed, 13 Dec 2023 12:18:46 -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=WtvYARQIvVa42V3Ts7AHp1j9HKVZUD4Uobx17kdWS4k=; b=CRhE5vntcCn8A/MP0nkCfEkUIT 2396T3Xj4sTyz/+OIZCSmi4+zRL7syDn04N10WK0Ag9CiU3zb1upFRkgA3nqJ5bFgjemfhA3CUagM F04TfXvMKSdjxUFsNP7o5QYyzZTVsTpYcGR1E3C+8qE4OqQ5x2KusZIG88vGinB+zQ69cj3OJqrRi z7JGr3P7bgQg3lFBOVkaRAPy6DFFrVdlbodpQu3QESxVckNkxmI4RBt75Mpk6PhgQX7B9SK7HGeuh /i46O8eM4aqXfXIk1/S8k2WegjW2ml65/o6FtuAohLz7m5BmbaiwIkfE5jkAi0hur6iHCS3aZpez+ nfVtkA7A==; Received: from shell.armlinux.org.uk ([fd8f:7570:feb6:1:5054:ff:fe00:4ec]:47214) by pandora.armlinux.org.uk with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1rDVgj-0000Y3-0e; Wed, 13 Dec 2023 20:18:37 +0000 Received: from linux by shell.armlinux.org.uk with local (Exim 4.94.2) (envelope-from ) id 1rDVgk-0001om-Rm; Wed, 13 Dec 2023 20:18:38 +0000 Date: Wed, 13 Dec 2023 20:18:38 +0000 From: "Russell King (Oracle)" To: Christian Marangi Cc: Andrew Lunn , Heiner Kallweit , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Vladimir Oltean , Vincent Mailhol , Kees Cook , Piergiorgio Beruto , netdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [net-next PATCH 2/2] net: phy: leds: use new define for link speed modes number Message-ID: References: <20231213181554.4741-1-ansuelsmth@gmail.com> <20231213181554.4741-3-ansuelsmth@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20231213181554.4741-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]); Wed, 13 Dec 2023 12:19:00 -0800 (PST) On Wed, Dec 13, 2023 at 07:15:54PM +0100, Christian Marangi wrote: > Use new define __LINK_SPEEDS_NUM for the speeds array instead of > declaring a big enough array of 50 elements to handle future link speed > modes. > > Signed-off-by: Christian Marangi > --- > drivers/net/phy/phy_led_triggers.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/drivers/net/phy/phy_led_triggers.c b/drivers/net/phy/phy_led_triggers.c > index f550576eb9da..40cb0fa9ace0 100644 > --- a/drivers/net/phy/phy_led_triggers.c > +++ b/drivers/net/phy/phy_led_triggers.c > @@ -84,7 +84,7 @@ static void phy_led_trigger_unregister(struct phy_led_trigger *plt) > int phy_led_triggers_register(struct phy_device *phy) > { > int i, err; > - unsigned int speeds[50]; > + unsigned int speeds[__LINK_SPEEDS_NUM]; > > phy->phy_num_led_triggers = phy_supported_speeds(phy, speeds, > ARRAY_SIZE(speeds)); Yes, I agree the original code is utterly horrid, and there should be a definition for its size. However, this is about the only place it would be used - if you look at the code in phy_supported_speeds() and in phy_speeds() which it calls, there is nothing in there which would know the speed. The only two solution I can think would be either a new function: size_t phy_num_supported_speeds(struct phy_device *phydev); or have phy_speeds() return the number of entries if "speeds" was NULL. Then kmalloc_array() the speed array - but that seems a bit on the side of things. The code as it stands is safe, because the passed ARRAY_SIZE() limits the maximum index into speeds[] that will be written, and it will result in the slower speeds not being added into the array. -- RMK's Patch system: https://www.armlinux.org.uk/developer/patches/ FTTP is here! 80Mbps down 10Mbps up. Decent connectivity at last!