Received: by 2002:a05:7412:8d10:b0:f3:1519:9f41 with SMTP id bj16csp6309582rdb; Thu, 14 Dec 2023 14:39:40 -0800 (PST) X-Google-Smtp-Source: AGHT+IGSIdkBpWMNEhmIdV1ohlwaxXxBUelBrTWzOK8Wd9rFYtBTwg4nryNwAmUvVNqmr3e4Z5Nr X-Received: by 2002:a17:906:3613:b0:a19:a1ba:8cbb with SMTP id q19-20020a170906361300b00a19a1ba8cbbmr5390890ejb.89.1702593579915; Thu, 14 Dec 2023 14:39:39 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702593579; cv=none; d=google.com; s=arc-20160816; b=VoLXaOeNy/W173LMvQ/OlPNgRpAPu33t9l7bxJQxjeyYGJLlpHVdxmY5z6aTJc6z3f l81LKBZAC/1wxXv7TWnjed+WQEZF3BbjQr+N1eRJmV+lzLpjGSX0iZG/lKO+G0YcvS5Z W71u2MY1NepJaIH4bJgJCw2GLiz8DwNmgOfOLOr2n/llgrvFiT3DgQoqLA57dMjV3H+E qfrGW73PiLnAQgBEAF1frLBcsgNQ4AlRhaPRc7FgWDp9HPYDrHY9lpnFQZct2bkfGoNJ JdNNJIibBSgGKtTe9JXZGSSbJBu6Yp+uaJSF9X55P6Yp5m7Qelb5b/58Eobm4k3M7+o1 yDGg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=tI12aCWJQCHdnL9tpy1TZqFUoLiTbzcedlrkIrXRyzo=; fh=utmrxdkgikAlLxVfQI1kldUG+rNjhrLN+3fAlOYj01s=; b=u9QhZ+kt6AupYCt7EVD3CrTG0LMIXKHlE1XbAl49WR4Bd56nhZioVQy9Zn5KC224mR AK8gySGBt9xZK4r2WDFRCGeM+cMwFBhEJkMJAOwGiB8h1cIteW5JF91fg3eqf5rRnlBm nxCszc2jfX2egGGS+8Ef1dz1cR67J1Pdq0631//dwQL5EV/LvJo6nNqZ1rlV52Tri25A ZZ41TrbnU1i7Y7xlXeCLMmMzn12lqHRKEL/HdP9psVJJsWMEW2YJ8hE5Uhk3s+2SDpYM xRpD1v1RDaBAs6r5QhyD6nhpOAlyWEdCIGbzIE6LaBI6VmyJh6M9f2y6Gvs2IS/c1hJu 8qSQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=gaM6CsDX; spf=pass (google.com: domain of linux-kernel+bounces-202-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-202-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id h13-20020a1709060f4d00b00a1b6b81b815si6763440ejj.155.2023.12.14.14.39.39 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Dec 2023 14:39:39 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-202-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=gaM6CsDX; spf=pass (google.com: domain of linux-kernel+bounces-202-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-202-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com 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 am.mirrors.kernel.org (Postfix) with ESMTPS id 4A8C61F2186D for ; Thu, 14 Dec 2023 22:39:39 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 54A576E2D0; Thu, 14 Dec 2023 22:38:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="gaM6CsDX" X-Original-To: linux-kernel@vger.kernel.org Received: from mail-wm1-f48.google.com (mail-wm1-f48.google.com [209.85.128.48]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 08DDE6A34D; Thu, 14 Dec 2023 22:38:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-wm1-f48.google.com with SMTP id 5b1f17b1804b1-40c38de1ee4so720065e9.0; Thu, 14 Dec 2023 14:38:37 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1702593516; x=1703198316; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=tI12aCWJQCHdnL9tpy1TZqFUoLiTbzcedlrkIrXRyzo=; b=gaM6CsDXN9QTmZ+6tuMHtvQBtsZyL+6jo0kQtDGBFUdLQsHYspNnvIucVWR2cYaX9q 9BMSfEKtMMhg+cBnjZBzJ/vnLiiaXoIEYOGLQVYqFo0FcWbZphwQlvnih5TjuoYFf/ZF suyMFPhZHnTwYxft20sAb2hSkEebwkhHEKW0lBdKFcoVPyw/CSCdAzwoS64KvOqESTYR 8S1Lt9AvRaUvMbNHxWfVupBFDYBKCuQT21RW6D1K3c188LSe7vr6e2STNY8DNsFRsQOS uL06OXcXIH/30wN5WXFsh6nupeBNUgraWgX+HW/4RjbALScpIJPMAEvghrYCh1s2lmgk lzcw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1702593516; x=1703198316; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=tI12aCWJQCHdnL9tpy1TZqFUoLiTbzcedlrkIrXRyzo=; b=jYCSJ5BmWj831aV+KylsBg6YH96KpPalN12AdU8BRbszXyGQuW4m/1SBUVz7IKulN4 C6wWxe4avsVJigSyaNbasgcPFhBJrrVk9G/FXVRfOboFLwb9bBPT9KqHXfTy20yEwF6J /hb5qQH400W3JVCliDFnWYke7x3sdVu/M0vTGAbJ0Gsrs5h9qfJl/JzTOfLP1lXA66zN 4NCkhYemF3GwfjSUr2u9SyQlNlVioOSXv7b8u6LAZfyQuOx/QfiS7mvpXXk2VF4QvQa8 lRUHS7+eays/zpagMfFZTcnd7i/2wG+mpxAx9YbcLv/Zc7ZK+t+udolOeC4o70dBm6bd Jb3g== X-Gm-Message-State: AOJu0YyEch4sL7Z7Ynd2rEm5tagj16eKR3L+VlIpY7vBmmd8Qq7IYTZ6 JxMhGMpVaPa8snRhcTzgxD4MTFlbGOE= X-Received: by 2002:a05:600c:1f1a:b0:40c:31f1:145c with SMTP id bd26-20020a05600c1f1a00b0040c31f1145cmr5011868wmb.169.1702593515923; Thu, 14 Dec 2023 14:38:35 -0800 (PST) Received: from localhost.localdomain (93-34-89-13.ip49.fastwebnet.it. [93.34.89.13]) by smtp.googlemail.com with ESMTPSA id n41-20020a05600c3ba900b0040c61ee0816sm54746wms.0.2023.12.14.14.38.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Dec 2023 14:38:35 -0800 (PST) From: Christian Marangi To: Andrew Lunn , Heiner Kallweit , Russell King , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , netdev@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Christian Marangi Subject: [net-next PATCH v2 3/3] net: phy: led: dynamically allocate speed modes array Date: Thu, 14 Dec 2023 16:49:06 +0100 Message-Id: <20231214154906.29436-4-ansuelsmth@gmail.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20231214154906.29436-1-ansuelsmth@gmail.com> References: <20231214154906.29436-1-ansuelsmth@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Instead of defining a big enough array for speed modes use the newly introduced API to get the actual number of supported speed modes and dynamically allocate them. Allocated space is freed at the end of the LED register loop. Signed-off-by: Christian Marangi --- drivers/net/phy/phy_led_triggers.c | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/drivers/net/phy/phy_led_triggers.c b/drivers/net/phy/phy_led_triggers.c index f550576eb9da..2e41d10e323c 100644 --- a/drivers/net/phy/phy_led_triggers.c +++ b/drivers/net/phy/phy_led_triggers.c @@ -83,14 +83,21 @@ static void phy_led_trigger_unregister(struct phy_led_trigger *plt) int phy_led_triggers_register(struct phy_device *phy) { + unsigned int *speeds; int i, err; - unsigned int speeds[50]; - phy->phy_num_led_triggers = phy_supported_speeds(phy, speeds, - ARRAY_SIZE(speeds)); + phy->phy_num_led_triggers = phy_supported_speeds_num(phy); if (!phy->phy_num_led_triggers) return 0; + speeds = kmalloc_array(phy->phy_num_led_triggers, sizeof(*speeds), + GFP_KERNEL); + if (!speeds) + return -ENOMEM; + + /* Presence of speed modes already checked up */ + phy_supported_speeds(phy, speeds, phy->phy_num_led_triggers); + phy->led_link_trigger = devm_kzalloc(&phy->mdio.dev, sizeof(*phy->led_link_trigger), GFP_KERNEL); @@ -123,6 +130,8 @@ int phy_led_triggers_register(struct phy_device *phy) phy->last_triggered = NULL; phy_led_trigger_change_speed(phy); + free(speeds); + return 0; out_unreg: while (i--) @@ -134,6 +143,7 @@ int phy_led_triggers_register(struct phy_device *phy) devm_kfree(&phy->mdio.dev, phy->led_link_trigger); phy->led_link_trigger = NULL; out_clear: + free(speeds); phy->phy_num_led_triggers = 0; return err; } -- 2.40.1