From patchwork Sat May 27 11:28:50 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Marangi X-Patchwork-Id: 687580 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 48D0BC7EE32 for ; Sat, 27 May 2023 11:29:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232376AbjE0L3d (ORCPT ); Sat, 27 May 2023 07:29:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56478 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232452AbjE0L33 (ORCPT ); Sat, 27 May 2023 07:29:29 -0400 Received: from mail-wm1-x32f.google.com (mail-wm1-x32f.google.com [IPv6:2a00:1450:4864:20::32f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BBEB0134; Sat, 27 May 2023 04:29:26 -0700 (PDT) Received: by mail-wm1-x32f.google.com with SMTP id 5b1f17b1804b1-3f603ff9c02so10975905e9.2; Sat, 27 May 2023 04:29:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1685186965; x=1687778965; 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=bzjSHLcSLKuyYbnB5oKrxVcxoSmgJOggg+ZfYlmNaGM=; b=QvdxWdjS+hkm5YxMe4Xjwx6raCsHbgdApVs96yBMFyu4JBQGn7WL9PTQjAf0MFsLhx ukBY+kIwoOZ1VW+GZt6vKfZ0XaRj/Xv4v0sukbM71DPI9aaxDYGow3jSnMGmvhqkjKCE J/keKNKvgB/O7f4DHcfj4Qh9iHIyz1cQW+XV1QBUy8zX3cvcq4/w+BTwDMjWmykuHmYo yQ2QNooQIEOuCLCS/Xo9FW75yFAzhqkU9ggDFFB3Injx28fVaYJgETUw9Yc7XgkMobgd J7p+68EqlpkZLPGF4yVngmqm+k5XmVPOEmbXhigcpaRkskDj5zyg9wWhOTmqpBSAtE3a 1jgw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1685186965; x=1687778965; 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=bzjSHLcSLKuyYbnB5oKrxVcxoSmgJOggg+ZfYlmNaGM=; b=FhhBqoscuIs8qVhecoqhUa416htFYCS1bKOy4yKl4dTu2kWZrlnujSLFl/cWvaG9pd R54RXP6NCYmQKUj8fgOTCbVwflFmzxkEA4C24OOgjo8fESwIrPOu2s1geuQozWmLP8Lo NMswDrZm5fIrwdakOAnibbiXnvxDJ0Srd6Dj/lEq9ACF2Hhs+WlNQ/f7/2fLwsIfzyvk wNt2Zu2z19no59bdL2edPwGtGRuWbzw32rEhcb0XbGDO4Fv/kh8vizFR+T0TB7attcO8 skM1JS6adV638Wdrit7cnf+UDvL35PPPLt9Hy65J83I7L+19J7+hSaYsLim4klVugWGG 1XwA== X-Gm-Message-State: AC+VfDzDq2hqSUTr8pbxzObNiJwwnsM/ZS/J6UuPvdt4pyyoNW/xGJV0 oJg+k3tNAA13eRsBYFx+Fh4= X-Google-Smtp-Source: ACHHUZ6y9k7RyQ4acYi1QtYqybdqeTHG7B+8XEu2DH1j+5XI68i03hl312Mm/633WgXOLA6wjaYI3g== X-Received: by 2002:a1c:f70e:0:b0:3f5:1728:bde9 with SMTP id v14-20020a1cf70e000000b003f51728bde9mr3682830wmh.2.1685186965133; Sat, 27 May 2023 04:29:25 -0700 (PDT) Received: from localhost.localdomain (93-34-93-173.ip49.fastwebnet.it. [93.34.93.173]) by smtp.googlemail.com with ESMTPSA id q13-20020a7bce8d000000b003f43f82001asm11711000wmj.31.2023.05.27.04.29.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 27 May 2023 04:29:24 -0700 (PDT) From: Christian Marangi To: Pavel Machek , Lee Jones , Jonathan Corbet , Andrew Lunn , Florian Fainelli , Vladimir Oltean , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Christian Marangi , linux-leds@vger.kernel.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, netdev@vger.kernel.org Subject: [net-next PATCH v3 09/13] leds: trigger: netdev: validate configured netdev Date: Sat, 27 May 2023 13:28:50 +0200 Message-Id: <20230527112854.2366-10-ansuelsmth@gmail.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230527112854.2366-1-ansuelsmth@gmail.com> References: <20230527112854.2366-1-ansuelsmth@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-leds@vger.kernel.org From: Andrew Lunn The netdev which the LED should blink for is configurable in /sys/class/led/foo/device_name. Ensure when offloading that the configured netdev is the same as the netdev the LED is associated with. If it is not, only perform software blinking. Signed-off-by: Andrew Lunn Signed-off-by: Christian Marangi --- drivers/leds/trigger/ledtrig-netdev.c | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/drivers/leds/trigger/ledtrig-netdev.c b/drivers/leds/trigger/ledtrig-netdev.c index 8d6381415208..5b59441fc415 100644 --- a/drivers/leds/trigger/ledtrig-netdev.c +++ b/drivers/leds/trigger/ledtrig-netdev.c @@ -108,6 +108,24 @@ static bool supports_hw_control(struct led_classdev *led_cdev) return !strcmp(led_cdev->hw_control_trigger, led_cdev->trigger->name); } +/* + * Validate the configured netdev is the same as the one associated with + * the LED driver in hw control. + */ +static bool validate_net_dev(struct led_classdev *led_cdev, + struct net_device *net_dev) +{ + struct device *dev = led_cdev->hw_control_get_device(led_cdev); + struct net_device *ndev; + + if (!dev) + return false; + + ndev = to_net_dev(dev); + + return ndev == net_dev; +} + static bool can_hw_control(struct led_netdev_data *trigger_data) { unsigned int interval = atomic_read(&trigger_data->interval); @@ -129,9 +147,11 @@ static bool can_hw_control(struct led_netdev_data *trigger_data) /* * net_dev must be set with hw control, otherwise no * blinking can be happening and there is nothing to - * offloaded. + * offloaded. Additionally, for hw control to be + * valid, the configured netdev must be the same as + * netdev associated to the LED. */ - if (!trigger_data->net_dev) + if (!validate_net_dev(led_cdev, trigger_data->net_dev)) return false; /* Check if the requested mode is supported */