Message ID | 20231213181554.4741-3-ansuelsmth@gmail.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:3b04:b0:fb:cd0c:d3e with SMTP id c4csp7974302dys; Wed, 13 Dec 2023 10:17:18 -0800 (PST) X-Google-Smtp-Source: AGHT+IH8UpqnhMoca420ppJyOprdZhsu6lAuNzyGaZBOzztBNNolM+7x1f505xc9x7CL34O1um25 X-Received: by 2002:a17:902:d489:b0:1d2:ed15:b6ad with SMTP id c9-20020a170902d48900b001d2ed15b6admr5155666plg.16.1702491438326; Wed, 13 Dec 2023 10:17:18 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702491438; cv=none; d=google.com; s=arc-20160816; b=X1V3ma45kmFEoKoGwuZpk/Vv+y2vYkQiwKcSgv90N55Ce/zwntuYr+osf6ZWi7/F07 J5KijqAeuKLBRep/vlExvnZJ5sQ4Uw5EdolyUqSSZkl7kIFOtj3eTbyxzQjqVjSROLJ4 Ym2GcVmEnpWE/8wgHf5+KdoR3pEjuUFscInKP9VYHhlqdbeaEGL/HZWougiyPQVCXfRn DQjXBPLSYScxJ2VTDcyOYgTv3B/y46E1nw747XZi2smK6LzYwUaiN4No5p2MLpi9gj1B ZUFn5F5tXf+UfiCCLxnbhWXjMe1GlotaVU9BGdiHFmni/EyggPpjOzt2zpKUg+nIgRWW ntVQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:to:from :dkim-signature; bh=XMG3yQ4EhHz7n1fTiev23HEWg/+c7EuzwQ2dfmF7Rmg=; fh=p6UE9/XeFdVcez2P5EpH3VpeppOo7ov8vHzRKEaMwWo=; b=oUyk9bGjt9jO270NZU/cHc3I/ky5Fx1M2QGTPk4mSINDkjMGyIygy7uAoiFUYZ0eYk rK3j0TeTwPSFHS8nW82Lu5Pexbsam7ddJPyQfg+2KrfFgTaNpna65BoJmd34AZFKFGj3 rh7cUPb7DLO+KDCSp1Iqpx6FleiBGR1yeO8mt5OfxfJztLcL7aAEiVcWdv1SHF7UalBC Vz9XqhGkwH+YYj6WAMCV5Z8ooYBUfHay+3xUZgHG6LVl4YVW1vwg8+ZQijJeTvqiSvS3 jKFdYLGD0bzuRZTYc3NnmOoMW7b8G7F0wLl0CduAFHp9Gqq6irHFmSHn1/nUrBa7OtEs 5UlA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=XMoTufx+; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from morse.vger.email (morse.vger.email. [2620:137:e000::3:1]) by mx.google.com with ESMTPS id je22-20020a170903265600b001bdd58f685fsi9716358plb.85.2023.12.13.10.17.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Dec 2023 10:17:18 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 as permitted sender) client-ip=2620:137:e000::3:1; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=XMoTufx+; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by morse.vger.email (Postfix) with ESMTP id 1ED728099265; Wed, 13 Dec 2023 10:16:17 -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 S1442156AbjLMSQG (ORCPT <rfc822;dexuan.linux@gmail.com> + 99 others); Wed, 13 Dec 2023 13:16:06 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59454 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235444AbjLMSP5 (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Wed, 13 Dec 2023 13:15:57 -0500 Received: from mail-wr1-x431.google.com (mail-wr1-x431.google.com [IPv6:2a00:1450:4864:20::431]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C7FF2106; Wed, 13 Dec 2023 10:16:03 -0800 (PST) Received: by mail-wr1-x431.google.com with SMTP id ffacd0b85a97d-33644eeb305so63492f8f.1; Wed, 13 Dec 2023 10:16:03 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1702491362; x=1703096162; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=XMG3yQ4EhHz7n1fTiev23HEWg/+c7EuzwQ2dfmF7Rmg=; b=XMoTufx+OeIPW34gfPpeVxDpRiIxjX4vlTTolc4V28F59I2Q1lrrv/hBTLObTvOBqd rIZpBfNa8J7nA9jbuqnwSLHD3O3RIIrGGxmhWvOpyqQInIcE/ZSxAFmiYsru3miamo63 A0PmRTUB6V0rJBfAsz+beWABJ4IiUhZTwhZnU3oNfbgg0igibe+XRPW332/we0koy2Ql j72W5JG+E6YhV2HbK92xP6kb1JDAkAfR5ZlfzyeDSUP8YXhb7aAT5Zt8qjOUCVWuSbBk f0Q7IS3LVX5/Mrf7jtJ0nb7LUrA5PszIO9jXRuPFO5YOTXHmyR07DW8cknu8q/LqzyaZ x5XA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1702491362; x=1703096162; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=XMG3yQ4EhHz7n1fTiev23HEWg/+c7EuzwQ2dfmF7Rmg=; b=CfLQX9fd961rIGCAnoGkL/7VX/nQorguhp97L5xqQGDDF/JOlVVq7lU59ewPB3KHAU 4Ujqkvvit2VJ39/uNOH/psdJQw5HpY1iY5gE0cQDxY6O+inNo/mFfFyy9/o2E+84zmlY YYqKx7laSjYewT9NR/xb7rVWrJnpYENn+Ks183KTkoMjDDKtPlMaVafHbF1BLtOZMzYv imvdVQd2gVInC25W9Y12egLW5xt3rIRiszlgSaN8lcHII/0SvH72ila2DZdu5DMuFyfK FkbhqWtvRbdhVZ2amYcEQwi08Qkr6wXVLz1Ot6hbGrGiIIIytkK6/cX2X/D4M4Day4pn qYLw== X-Gm-Message-State: AOJu0YyyfNvbZlWlX+d6LyZZooDmMWrOViXwqRAGSxdKDhO1QUYbEaEh 8BXMBxjMmgbJq3TDREv2u0k= X-Received: by 2002:adf:fd49:0:b0:336:35ed:af18 with SMTP id h9-20020adffd49000000b0033635edaf18mr1385090wrs.17.1702491361917; Wed, 13 Dec 2023 10:16:01 -0800 (PST) Received: from localhost.localdomain (93-34-89-13.ip49.fastwebnet.it. [93.34.89.13]) by smtp.googlemail.com with ESMTPSA id e33-20020a5d5961000000b0033346fe9b9bsm13947762wri.83.2023.12.13.10.16.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Dec 2023 10:16:01 -0800 (PST) From: Christian Marangi <ansuelsmth@gmail.com> To: Andrew Lunn <andrew@lunn.ch>, Heiner Kallweit <hkallweit1@gmail.com>, Russell King <linux@armlinux.org.uk>, "David S. Miller" <davem@davemloft.net>, Eric Dumazet <edumazet@google.com>, Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>, Vladimir Oltean <vladimir.oltean@nxp.com>, Vincent Mailhol <mailhol.vincent@wanadoo.fr>, Kees Cook <keescook@chromium.org>, Christian Marangi <ansuelsmth@gmail.com>, Piergiorgio Beruto <piergiorgio.beruto@gmail.com>, netdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [net-next PATCH 2/2] net: phy: leds: use new define for link speed modes number Date: Wed, 13 Dec 2023 19:15:54 +0100 Message-Id: <20231213181554.4741-3-ansuelsmth@gmail.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20231213181554.4741-1-ansuelsmth@gmail.com> References: <20231213181554.4741-1-ansuelsmth@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-0.6 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, 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: <linux-kernel.vger.kernel.org> 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 10:16:17 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1785191662531924966 X-GMAIL-MSGID: 1785191662531924966 |
Series |
net: add define to describe link speed modes
|
|
Commit Message
Christian Marangi
Dec. 13, 2023, 6:15 p.m. UTC
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 <ansuelsmth@gmail.com>
---
drivers/net/phy/phy_led_triggers.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
Comments
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 <ansuelsmth@gmail.com> > --- > 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.
On Wed, Dec 13, 2023 at 08:18:38PM +0000, Russell King (Oracle) wrote: > 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 <ansuelsmth@gmail.com> > > --- > > 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); Maybe this is better to not fill the phy_speeds function with too much conditions. > > 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. > The fact that the phy_speed compose an array in descending order seems wrong to me and not following why it was done like that in the first place. Passing for example an array of 3 elements i would expect 10 100 100 speed to be put instead of 800 400 200. (just as an example) Wonder if it would be sane to do this change. (invert the produced speed array with ascending order) A kmalloc_array might be overkill for the task but declaring a random array of 50 elements is equally bad... Think I will just implement kmalloc + function to return the count of speed modes from the settings struct.
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));