From patchwork Wed Apr 19 21:07:39 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Marangi X-Patchwork-Id: 85546 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp667389vqo; Wed, 19 Apr 2023 14:11:18 -0700 (PDT) X-Google-Smtp-Source: AKy350YfmIBHOSrQzSrz47mfG6hS9H2KmtwfCqPsNTtWdF6fT5tk9qVYhYofSTVun3kCRJz9ajiw X-Received: by 2002:a05:6a00:1506:b0:634:4f6:86df with SMTP id q6-20020a056a00150600b0063404f686dfmr3980021pfu.1.1681938678349; Wed, 19 Apr 2023 14:11:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1681938678; cv=none; d=google.com; s=arc-20160816; b=KJMoMusqUuE98iZkkhCzk+kusOGkxGs96YlL5dkYvJVL2+T0IsFOnLzEH5gT8DQd0H k6QHmD3qtMseQ8xtPHcKtMJ333JwAi1E2zlQfnqvG8Qknn8n5N5l0u6W/Tnvwd7pftA9 GpOu3Ry3lhr7SW3ZwMMS7fjLePPGHqDZ61Y9lN2NU6dVFCpengl1L2wYhzXzn9F0tndJ WKC7k+lSyLjC5wKKypmASyTsno24hVeKrn/zSy7Qvg4kuBIfkymNMl6zZKWAqLNhrKXw ZfymxiPJ5eYYKklgrtBVDhwUxMv9OIPcH+htk2pP0+YpWaTSBAsGyw+klxvzNCYPIcZk H9jg== 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:cc:to:from :dkim-signature; bh=ehYDxVU02fn2ZkXnUcD0JtMkdqmb9th/dYG75X055ng=; b=COf72cXZ4hS/urxEsD8dWPISBd9wdbWeO27pU1fcOE+03FJo1JnTWWLL9hsO/yrGtq DlyfkuRqFjifemMw12tOWnZZAk/Y/3HBW3Ckdc0KditGUHwbq+qfSv0EdZb/pyPNuDc1 VSzce7vy2id+Zl4ktGoecProjuiGpI3T05htZ7hLEn+8vrNiE/mUi+5+9ikyWu6gmTBb y/Gh0jJuqqcFjR9NAp13LXSSl8m9J/GTO+tcosv7SaRgpeBezSAO4kqBY9U2oHtcag49 HfoouhLeJAmseKeV+OfUlFfj9jczEzBnP2TUsY6Px7aZ9OKTrVGnHdehjhyoPDCmZfbd SpdQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b=JwRafYxk; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id l7-20020a6542c7000000b00514477c4410si16587084pgp.426.2023.04.19.14.11.03; Wed, 19 Apr 2023 14:11:18 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b=JwRafYxk; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231331AbjDSVIW (ORCPT + 99 others); Wed, 19 Apr 2023 17:08:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33198 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231347AbjDSVIU (ORCPT ); Wed, 19 Apr 2023 17:08:20 -0400 Received: from mail-wm1-x334.google.com (mail-wm1-x334.google.com [IPv6:2a00:1450:4864:20::334]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 59ADE659F; Wed, 19 Apr 2023 14:08:17 -0700 (PDT) Received: by mail-wm1-x334.google.com with SMTP id m39-20020a05600c3b2700b003f170e75bd3so2606459wms.1; Wed, 19 Apr 2023 14:08:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1681938496; x=1684530496; 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=ehYDxVU02fn2ZkXnUcD0JtMkdqmb9th/dYG75X055ng=; b=JwRafYxks4ZW9UecZY4eqmo5FKHyDxwuYi5VAsPf6UWl4eR8eRczTFuc6KvqIPoc12 RbTqA4mT9JS0NlX7sCEvvhwWdGvWglMMZwc9juIZoL444AKX0vkKIXMfJ1t1YX/lmJoF 2m80rXDfg0ov2r4d2fCDUh/VwAvR0J+LQdrLvDxxn4uglHr2bMhNOpHSnDAhEWoEINAr Sburf4C1ltCzrl/J8s9aoPYt0be7fxt/tg/K5aYaLbn975xzIPn0n49Hj8LSxN0NMhtf KIqQdGQJSvt6VRD876+BSgsU6kZfxQbMQXT/9D6o9fKG7gnNtU5xUWUL1VIUpmNJJOVs YknA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1681938496; x=1684530496; 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=ehYDxVU02fn2ZkXnUcD0JtMkdqmb9th/dYG75X055ng=; b=PBSss+wZkr9w8mwhJq4z3olMdQPqQteFDJWZ6v0Dyi8XGUekaZuU95pOOaDrmKNIul TPBIZ5YAM6uipOFmttA+L/w2gsm/Y/vNsZJk0RxMcjP7zWGStXvvpds1gk3V0hYFzp8/ InH9DwBMwU3qBtfIQO3yj8csEWx8pXzfphSY+iOPkcsp4cPdQgusAmluFKUlhwDLSWCq MKoYvKhL/JzW2lEOXm/azATacUyQcSXIHWff2lJd4AcLx+Uda+DjBG9pgWvYD1iyFSwM jXpukn5NNb2eF02VwJOqDjoLKUy9VQWePYVc6fMZsSNyENPw911YG9t5eIrb0EukGq7O 68Og== X-Gm-Message-State: AAQBX9dAu0GtEHFNkb1nzHSdPm6dzNnL2Jg/TZ0HwJhYGWI5OrAFO5// wdnSq712RBOjRbLNVx6mTFs= X-Received: by 2002:a05:600c:221a:b0:3f0:a798:2757 with SMTP id z26-20020a05600c221a00b003f0a7982757mr17039715wml.25.1681938495512; Wed, 19 Apr 2023 14:08:15 -0700 (PDT) Received: from localhost.localdomain (93-34-93-173.ip49.fastwebnet.it. [93.34.93.173]) by smtp.googlemail.com with ESMTPSA id g3-20020a5d5543000000b002fe254f6c33sm81295wrw.92.2023.04.19.14.08.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 19 Apr 2023 14:08:15 -0700 (PDT) From: Christian Marangi To: Pavel Machek , Lee Jones , Christian Marangi , Martin Schiller , linux-leds@vger.kernel.org, linux-kernel@vger.kernel.org, Andrew Lunn Cc: stable@vger.kernel.org Subject: [PATCH 1/5] leds: trigger: netdev: recheck NETDEV_LED_MODE_LINKUP on dev rename Date: Wed, 19 Apr 2023 23:07:39 +0200 Message-Id: <20230419210743.3594-2-ansuelsmth@gmail.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230419210743.3594-1-ansuelsmth@gmail.com> References: <20230419210743.3594-1-ansuelsmth@gmail.com> MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1763640531733144728?= X-GMAIL-MSGID: =?utf-8?q?1763640531733144728?= Dev can be renamed also while up for supported device. We currently wrongly clear the NETDEV_LED_MODE_LINKUP flag on NETDEV_CHANGENAME event. Fix this by rechecking if the carrier is ok on NETDEV_CHANGENAME and correctly set the NETDEV_LED_MODE_LINKUP bit. Fixes: 5f820ed52371 ("leds: trigger: netdev: fix handling on interface rename") Signed-off-by: Christian Marangi Cc: stable@vger.kernel.org # v5.5+ Reviewed-by: Andrew Lunn --- drivers/leds/trigger/ledtrig-netdev.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/drivers/leds/trigger/ledtrig-netdev.c b/drivers/leds/trigger/ledtrig-netdev.c index d5e774d83021..f4d670ec30bc 100644 --- a/drivers/leds/trigger/ledtrig-netdev.c +++ b/drivers/leds/trigger/ledtrig-netdev.c @@ -318,6 +318,9 @@ static int netdev_trig_notify(struct notifier_block *nb, clear_bit(NETDEV_LED_MODE_LINKUP, &trigger_data->mode); switch (evt) { case NETDEV_CHANGENAME: + if (netif_carrier_ok(dev)) + set_bit(NETDEV_LED_MODE_LINKUP, &trigger_data->mode); + fallthrough; case NETDEV_REGISTER: if (trigger_data->net_dev) dev_put(trigger_data->net_dev); From patchwork Wed Apr 19 21:07:40 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Marangi X-Patchwork-Id: 85549 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp669029vqo; Wed, 19 Apr 2023 14:14:55 -0700 (PDT) X-Google-Smtp-Source: AKy350bHgaKWhe+OpiqiIQQqHS714YS8bfU6X0uGda07L42882KS9om6AdiAScHkEpTM813HG3tZ X-Received: by 2002:a17:902:ea05:b0:19a:a520:b203 with SMTP id s5-20020a170902ea0500b0019aa520b203mr7761173plg.25.1681938894796; Wed, 19 Apr 2023 14:14:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1681938894; cv=none; d=google.com; s=arc-20160816; b=FYVFiWHItt3ZL+azNvNG4ZPDKsx01njXyayjgs5Cnefx0rAHDzmvdqes19vm2qlUGg j6zZRBZ0s8CO46Ha7CEx9ufdQFOazEm1JKBTo+7A/ztDU2NIQUjZluepguLXaY5YwyY4 c3wOMl26OJU11V4eofNhP9gd6OdwD+EM7oBjKg9WaJIGiHVZT6FQZYZEhE5fQkDN+jnM ejkJjHkJGB6FoT5gTiew9T4fMlljp7zC+UfMG3b6FfIzqtSLO6N5YNPq9JPYlgeVLWSq AhzB3I3GgyHwquTu+Srwmbm/0mUOuDPdkK3EXTIxeI6hDzgW9FrJIzl5XfXIWSJ7E8Up C2Zw== 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=zdLjBTspN0RuBhnqah0NEHAUrMQQgvoP610DrLOri+g=; b=mNRPFnrhC5CiVWrPSwjaHaG85W2TozAF9OCImqj4va2qarxAjUewhK+w1B33IxmVzM rw5bJcHaIhEQ6+ANBBI/jfyCTKjUrS5wSUv3yZVv3wseB/Pv2E52bSv+st7/c3B+miGz 4Hg39fQUSZb1sviUHJWozz3kKq8J3v4kTbY8bXCkgdusiCM1GZjBZa8EouFEEBLsBPlr uUCYdn0PE12rfi5Djc/xEp5Kzoq+woHhxfV3APynpZsyu1rGnhOsX6ryjyN8zc37V1+8 H/dkz/4tjv9JyzVSXojxZZ9aUKdiKlaFZiyNxANq2KhWeqTVslX1vQb9WT75wZpDXTjb NCyw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b=XY52PUvu; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id iz9-20020a170902ef8900b001a51c3404e0si16979325plb.337.2023.04.19.14.14.36; Wed, 19 Apr 2023 14:14:54 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b=XY52PUvu; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231448AbjDSVI1 (ORCPT + 99 others); Wed, 19 Apr 2023 17:08:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33210 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231401AbjDSVIV (ORCPT ); Wed, 19 Apr 2023 17:08:21 -0400 Received: from mail-wm1-x332.google.com (mail-wm1-x332.google.com [IPv6:2a00:1450:4864:20::332]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 561AC5B92; Wed, 19 Apr 2023 14:08:18 -0700 (PDT) Received: by mail-wm1-x332.google.com with SMTP id 5b1f17b1804b1-3f09b9ac51dso5342585e9.0; Wed, 19 Apr 2023 14:08:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1681938497; x=1684530497; 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=zdLjBTspN0RuBhnqah0NEHAUrMQQgvoP610DrLOri+g=; b=XY52PUvumH0PTZvaEV1/fr7g1UkVMtC05AIAq5eHMV5LFD/xgcMRBNeHpY6ASPaLSZ BHtzcKU8v50KIpRELZO3PhdrKAe600n956MhFEorvW/Ce3qUWhAdc31XJ0H4TBSEf/Zd XTgCyqW58Ca9sTJ6kDJplJzF0zM8THj8gTCLB56DvpK1Pf4BxZxCUb99mzMOU64iM3X7 7l1mRXsLT7UgmfHo1W8YS8fUG91bTm8HNUDe8qzyZOcbw8kwc8vSXHO0yNhZxMWLM1eb u1+UjfBtC7JNOdZxhIkIosOO3M2b03D0Idsx/BzasRrUlyxL/toBykuONZ6Cks6X7g6e Hm6w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1681938497; x=1684530497; 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=zdLjBTspN0RuBhnqah0NEHAUrMQQgvoP610DrLOri+g=; b=Yjk5NMWESRoA2h+5uFWUDAe4B9wAoLE0p0o59mlu7o1a+NUKrgrm8jNGzhreQMKlri 131oQ0dvb4mO/YFAQYc8pTla/F2r+dGcF06q7P3NZtwHDC729+vhdY4h1fDR78iGxgLp S36RLI6Yn1LUV6IxjfS0to7fWGTIMrUu9bKZfjsxa32NdjrGP8vz3mFnuLCHpQCSMHgT fSSvZkZNzr2986htMV6mKk/BxhI8Zr7CxUkkdm2hqk2Qy1YLPSBxozawoXuQiuL7W/XU XbbprZVAvl3B7waZfGkpVcwUWLZCVIkWrBhfiAjavEMQvpIvcVZ64h4IPCDk5A+XP8lF CW9Q== X-Gm-Message-State: AAQBX9fWM+RYxf2duF8pUsm/xTuSI0q3qcWVRWq5J6/3+08B+gulUNHu Jp7oH6s/PU4VBJt8Dkpq4Xw= X-Received: by 2002:adf:ec4e:0:b0:2fd:c315:bb2c with SMTP id w14-20020adfec4e000000b002fdc315bb2cmr2673603wrn.22.1681938496496; Wed, 19 Apr 2023 14:08:16 -0700 (PDT) Received: from localhost.localdomain (93-34-93-173.ip49.fastwebnet.it. [93.34.93.173]) by smtp.googlemail.com with ESMTPSA id g3-20020a5d5543000000b002fe254f6c33sm81295wrw.92.2023.04.19.14.08.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 19 Apr 2023 14:08:16 -0700 (PDT) From: Christian Marangi To: Pavel Machek , Lee Jones , Christian Marangi , Martin Schiller , linux-leds@vger.kernel.org, linux-kernel@vger.kernel.org, Andrew Lunn Subject: [PATCH 2/5] leds: trigger: netdev: drop NETDEV_LED_MODE_LINKUP from mode Date: Wed, 19 Apr 2023 23:07:40 +0200 Message-Id: <20230419210743.3594-3-ansuelsmth@gmail.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230419210743.3594-1-ansuelsmth@gmail.com> References: <20230419210743.3594-1-ansuelsmth@gmail.com> MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1763640758088910937?= X-GMAIL-MSGID: =?utf-8?q?1763640758088910937?= Putting NETDEV_LED_MODE_LINKUP in the same list of the netdev trigger modes is wrong as it's used to set the link state of the device and not to set a blink mode as it's done by NETDEV_LED_LINK, NETDEV_LED_TX and NETDEV_LED_RX. It's also wrong to put this state in the same bitmap of the netdev trigger mode and should be external to it. Drop NETDEV_LED_MODE_LINKUP from mode list and convert to a simple bool that will be true or false based on the carrier link. No functional change intended. Signed-off-by: Christian Marangi Reviewed-by: Andrew Lunn --- drivers/leds/trigger/ledtrig-netdev.c | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/drivers/leds/trigger/ledtrig-netdev.c b/drivers/leds/trigger/ledtrig-netdev.c index f4d670ec30bc..d5c4e72b8261 100644 --- a/drivers/leds/trigger/ledtrig-netdev.c +++ b/drivers/leds/trigger/ledtrig-netdev.c @@ -50,10 +50,10 @@ struct led_netdev_data { unsigned int last_activity; unsigned long mode; + bool carrier_link_up; #define NETDEV_LED_LINK 0 #define NETDEV_LED_TX 1 #define NETDEV_LED_RX 2 -#define NETDEV_LED_MODE_LINKUP 3 }; enum netdev_led_attr { @@ -73,9 +73,9 @@ static void set_baseline_state(struct led_netdev_data *trigger_data) if (!led_cdev->blink_brightness) led_cdev->blink_brightness = led_cdev->max_brightness; - if (!test_bit(NETDEV_LED_MODE_LINKUP, &trigger_data->mode)) + if (!trigger_data->carrier_link_up) { led_set_brightness(led_cdev, LED_OFF); - else { + } else { if (test_bit(NETDEV_LED_LINK, &trigger_data->mode)) led_set_brightness(led_cdev, led_cdev->blink_brightness); @@ -131,10 +131,9 @@ static ssize_t device_name_store(struct device *dev, trigger_data->net_dev = dev_get_by_name(&init_net, trigger_data->device_name); - clear_bit(NETDEV_LED_MODE_LINKUP, &trigger_data->mode); + trigger_data->carrier_link_up = false; if (trigger_data->net_dev != NULL) - if (netif_carrier_ok(trigger_data->net_dev)) - set_bit(NETDEV_LED_MODE_LINKUP, &trigger_data->mode); + trigger_data->carrier_link_up = netif_carrier_ok(trigger_data->net_dev); trigger_data->last_activity = 0; @@ -315,11 +314,10 @@ static int netdev_trig_notify(struct notifier_block *nb, spin_lock_bh(&trigger_data->lock); - clear_bit(NETDEV_LED_MODE_LINKUP, &trigger_data->mode); + trigger_data->carrier_link_up = false; switch (evt) { case NETDEV_CHANGENAME: - if (netif_carrier_ok(dev)) - set_bit(NETDEV_LED_MODE_LINKUP, &trigger_data->mode); + trigger_data->carrier_link_up = netif_carrier_ok(dev); fallthrough; case NETDEV_REGISTER: if (trigger_data->net_dev) @@ -333,8 +331,7 @@ static int netdev_trig_notify(struct notifier_block *nb, break; case NETDEV_UP: case NETDEV_CHANGE: - if (netif_carrier_ok(dev)) - set_bit(NETDEV_LED_MODE_LINKUP, &trigger_data->mode); + trigger_data->carrier_link_up = netif_carrier_ok(dev); break; } From patchwork Wed Apr 19 21:07:41 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Marangi X-Patchwork-Id: 85548 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp668899vqo; Wed, 19 Apr 2023 14:14:36 -0700 (PDT) X-Google-Smtp-Source: AKy350bE07IXEJbkRxxtZRy2clBChmwQ+gUQDCxj6e+HkvsXhZk3wYLIAj7cvHCiMWP5ARFxg6Po X-Received: by 2002:a05:6a20:5493:b0:ef:ecaf:ff6d with SMTP id i19-20020a056a20549300b000efecafff6dmr4474262pzk.12.1681938876534; Wed, 19 Apr 2023 14:14:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1681938876; cv=none; d=google.com; s=arc-20160816; b=M7EZB4Ih2Dqt5Mdh+QUVGUYYlOj9miSDwOvASuUPy0aq8IiwAFm2AMgD7IT7LfzFZU 1l+f4YQoYHDZYdTGrLi4/z+IddeRhcdRHm1C8NWel6FUPcIqVnM5PCyTPkoKhtOT0rtj Jjb/A5HQzSFTEaCGmUDHabyXd+RYQEfKMd454wKYQnqgtHn52fU0ioRxMf/8wYpjPzr2 /0IENXEFl8gK9gYAd98lQLnKDAonvRIjwTO5Lp3D73HvnsNNvonzay4RzeDlakf3TQH/ 2EnUH1J7nWajLnafStjS/PP1BhbRbcurtN+bSa62oOp+X8l7I/IjHgNBqZBSN8dnKVq/ X5vA== 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=UWkT+7LRJWQ8bpRRwkMgFCGb6v8FL0qHRIWzFrJQLXk=; b=ZBJLPjuSq4T3EfZQk9y9qeFMCFWSzMUk82sZKykE5DUQIehY+z5RSOVQj3d6VDIUhE kfMm36EknwarynnVfOpGf4UjsfE8jU1Z8TkhJVMYHel2N6M6mCGZDiDXQCi9lycp7xqk nqLPBcg3CG1z89kAR2JOTfTsg77gQfFdbEabHcYBCwAGhIDluylcj8/f6oAYdfrSe0Vu /yLd8AMMIaOVsV/4M2bvzsk5gDonpJ7xPzQb1I08aKah9M1p7mgZFrrBFRIuLecOOTPD AUmxzXoBtbWks+MoxG/9UPkNWc24qbEoQ+wWEijBCAlY6NZcNGHFt5DyqIuTh0SzD7UE YKFA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b=SMw5Ls8S; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id x20-20020a631714000000b00519ffeb6d43si17158823pgl.188.2023.04.19.14.14.21; Wed, 19 Apr 2023 14:14:36 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b=SMw5Ls8S; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231537AbjDSVIa (ORCPT + 99 others); Wed, 19 Apr 2023 17:08:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33274 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231372AbjDSVIW (ORCPT ); Wed, 19 Apr 2023 17:08:22 -0400 Received: from mail-wr1-x430.google.com (mail-wr1-x430.google.com [IPv6:2a00:1450:4864:20::430]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 39FAE5FE9; Wed, 19 Apr 2023 14:08:19 -0700 (PDT) Received: by mail-wr1-x430.google.com with SMTP id ffacd0b85a97d-2f27a9c7970so88747f8f.2; Wed, 19 Apr 2023 14:08:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1681938497; x=1684530497; 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=UWkT+7LRJWQ8bpRRwkMgFCGb6v8FL0qHRIWzFrJQLXk=; b=SMw5Ls8SSt+Wgz/35nbwRhrr1IRC9NCsVAgHqzId2Q2Q66ZwemapLVpc9xCIplBK7D ysKvz4LpgAcmZSWHFbyUuN9iTn2fw3KdXdkdWRD2U01gPom6ExvOUv7JJL2NWbLoqbNv aCYLiTGE8l+Fw6jji/nnVFb9UnX4/QoOBazFmahiwO0QxaPoKZa+VhE7x2dCQQKtVUxd Q/tcaX7g3CD6XUAprb0YMCNcQr3mys1Cj0kYe6OVAzvTu0UnDNhFA6bCO+PbeItDE5m5 dLJT/j6+ixMW4ekAk9liEIUpQkaf1TZVdfHGu5iHAa49xXDWxg7WNa98OkfSim0yzTZz qhgQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1681938497; x=1684530497; 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=UWkT+7LRJWQ8bpRRwkMgFCGb6v8FL0qHRIWzFrJQLXk=; b=RymRrdwrRBL5OA625DLAV7cA5dikjJdKj/8sai1jA618kanN6OzKtQoyUIaBVT2u+K 1Q9PfXhmFEVb2S3WCwEdvNjoPw4TsoCyrLJtYc92VPPVXiHMTTVcoUxQD1zbMZDE6QEZ 3vSv+xF14M13bXRVXlwJGXvDmttCvziYz8qCP9UnG9bUrjby0M+b9l1zYBBhcVchccri wM6XsJHyNKP7m295DT1PhEz7cKM+PwfYJ4z8gyROfYvnd/13UT4W5z5fsicC8A5p9phw N0RqkjPNY4g8gFQU+ltbnHq32LDBNHyox2o4HMjD/FQPOcJMg+eRPa9NiVKHFDL4OzkY MvVQ== X-Gm-Message-State: AAQBX9cYTI0IGNsqwr/zSYPbRiBuqDZFYuhwGyG11Uw4cUscBPRzne7W O895dPQk8LfUVxVWQa54WTU= X-Received: by 2002:adf:f787:0:b0:2fb:db79:748e with SMTP id q7-20020adff787000000b002fbdb79748emr6076779wrp.65.1681938497523; Wed, 19 Apr 2023 14:08:17 -0700 (PDT) Received: from localhost.localdomain (93-34-93-173.ip49.fastwebnet.it. [93.34.93.173]) by smtp.googlemail.com with ESMTPSA id g3-20020a5d5543000000b002fe254f6c33sm81295wrw.92.2023.04.19.14.08.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 19 Apr 2023 14:08:17 -0700 (PDT) From: Christian Marangi To: Pavel Machek , Lee Jones , Christian Marangi , Martin Schiller , linux-leds@vger.kernel.org, linux-kernel@vger.kernel.org, Andrew Lunn Subject: [PATCH 3/5] leds: trigger: netdev: rename add namespace to netdev trigger enum modes Date: Wed, 19 Apr 2023 23:07:41 +0200 Message-Id: <20230419210743.3594-4-ansuelsmth@gmail.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230419210743.3594-1-ansuelsmth@gmail.com> References: <20230419210743.3594-1-ansuelsmth@gmail.com> MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1763640739630996475?= X-GMAIL-MSGID: =?utf-8?q?1763640739630996475?= Rename NETDEV trigger enum modes to a more symbolic name and add a namespace to them. Also add __TRIGGER_NETDEV_MAX to identify the max modes of the netdev trigger. This is a cleanup to drop the define and no behaviour change are intended. Signed-off-by: Christian Marangi Reviewed-by: Andrew Lunn --- drivers/leds/trigger/ledtrig-netdev.c | 58 ++++++++++++--------------- 1 file changed, 25 insertions(+), 33 deletions(-) diff --git a/drivers/leds/trigger/ledtrig-netdev.c b/drivers/leds/trigger/ledtrig-netdev.c index d5c4e72b8261..0d4649e7a84d 100644 --- a/drivers/leds/trigger/ledtrig-netdev.c +++ b/drivers/leds/trigger/ledtrig-netdev.c @@ -51,15 +51,15 @@ struct led_netdev_data { unsigned long mode; bool carrier_link_up; -#define NETDEV_LED_LINK 0 -#define NETDEV_LED_TX 1 -#define NETDEV_LED_RX 2 }; -enum netdev_led_attr { - NETDEV_ATTR_LINK, - NETDEV_ATTR_TX, - NETDEV_ATTR_RX +enum led_trigger_netdev_modes { + TRIGGER_NETDEV_LINK = 0, + TRIGGER_NETDEV_TX, + TRIGGER_NETDEV_RX, + + /* keep last */ + __TRIGGER_NETDEV_MAX, }; static void set_baseline_state(struct led_netdev_data *trigger_data) @@ -76,7 +76,7 @@ static void set_baseline_state(struct led_netdev_data *trigger_data) if (!trigger_data->carrier_link_up) { led_set_brightness(led_cdev, LED_OFF); } else { - if (test_bit(NETDEV_LED_LINK, &trigger_data->mode)) + if (test_bit(TRIGGER_NETDEV_LINK, &trigger_data->mode)) led_set_brightness(led_cdev, led_cdev->blink_brightness); else @@ -85,8 +85,8 @@ static void set_baseline_state(struct led_netdev_data *trigger_data) /* If we are looking for RX/TX start periodically * checking stats */ - if (test_bit(NETDEV_LED_TX, &trigger_data->mode) || - test_bit(NETDEV_LED_RX, &trigger_data->mode)) + if (test_bit(TRIGGER_NETDEV_TX, &trigger_data->mode) || + test_bit(TRIGGER_NETDEV_RX, &trigger_data->mode)) schedule_delayed_work(&trigger_data->work, 0); } } @@ -146,20 +146,16 @@ static ssize_t device_name_store(struct device *dev, static DEVICE_ATTR_RW(device_name); static ssize_t netdev_led_attr_show(struct device *dev, char *buf, - enum netdev_led_attr attr) + enum led_trigger_netdev_modes attr) { struct led_netdev_data *trigger_data = led_trigger_get_drvdata(dev); int bit; switch (attr) { - case NETDEV_ATTR_LINK: - bit = NETDEV_LED_LINK; - break; - case NETDEV_ATTR_TX: - bit = NETDEV_LED_TX; - break; - case NETDEV_ATTR_RX: - bit = NETDEV_LED_RX; + case TRIGGER_NETDEV_LINK: + case TRIGGER_NETDEV_TX: + case TRIGGER_NETDEV_RX: + bit = attr; break; default: return -EINVAL; @@ -169,7 +165,7 @@ static ssize_t netdev_led_attr_show(struct device *dev, char *buf, } static ssize_t netdev_led_attr_store(struct device *dev, const char *buf, - size_t size, enum netdev_led_attr attr) + size_t size, enum led_trigger_netdev_modes attr) { struct led_netdev_data *trigger_data = led_trigger_get_drvdata(dev); unsigned long state; @@ -181,14 +177,10 @@ static ssize_t netdev_led_attr_store(struct device *dev, const char *buf, return ret; switch (attr) { - case NETDEV_ATTR_LINK: - bit = NETDEV_LED_LINK; - break; - case NETDEV_ATTR_TX: - bit = NETDEV_LED_TX; - break; - case NETDEV_ATTR_RX: - bit = NETDEV_LED_RX; + case TRIGGER_NETDEV_LINK: + case TRIGGER_NETDEV_TX: + case TRIGGER_NETDEV_RX: + bit = attr; break; default: return -EINVAL; @@ -360,21 +352,21 @@ static void netdev_trig_work(struct work_struct *work) } /* If we are not looking for RX/TX then return */ - if (!test_bit(NETDEV_LED_TX, &trigger_data->mode) && - !test_bit(NETDEV_LED_RX, &trigger_data->mode)) + if (!test_bit(TRIGGER_NETDEV_TX, &trigger_data->mode) && + !test_bit(TRIGGER_NETDEV_RX, &trigger_data->mode)) return; dev_stats = dev_get_stats(trigger_data->net_dev, &temp); new_activity = - (test_bit(NETDEV_LED_TX, &trigger_data->mode) ? + (test_bit(TRIGGER_NETDEV_TX, &trigger_data->mode) ? dev_stats->tx_packets : 0) + - (test_bit(NETDEV_LED_RX, &trigger_data->mode) ? + (test_bit(TRIGGER_NETDEV_RX, &trigger_data->mode) ? dev_stats->rx_packets : 0); if (trigger_data->last_activity != new_activity) { led_stop_software_blink(trigger_data->led_cdev); - invert = test_bit(NETDEV_LED_LINK, &trigger_data->mode); + invert = test_bit(TRIGGER_NETDEV_LINK, &trigger_data->mode); interval = jiffies_to_msecs( atomic_read(&trigger_data->interval)); /* base state is ON (link present) */ From patchwork Wed Apr 19 21:07:42 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Marangi X-Patchwork-Id: 85550 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp669640vqo; Wed, 19 Apr 2023 14:16:09 -0700 (PDT) X-Google-Smtp-Source: AKy350YHzBTS55KMYTUzVYXZpsTiUbM+1rku4u5ju7Ugowp5+75KJsgn7+eov3KyYIMGN1BDJHCh X-Received: by 2002:a05:6a00:2289:b0:63b:5174:4784 with SMTP id f9-20020a056a00228900b0063b51744784mr6009358pfe.30.1681938969442; Wed, 19 Apr 2023 14:16:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1681938969; cv=none; d=google.com; s=arc-20160816; b=IK6Y9H9Egfa/lUo5quFcDE0E01ExBT2DruRxymPK1lpvG47PNp4CjLTSMkBzbSpX0i YUhtg0duqGzJRksWK26diO8r82VdbHnObKlmMBmjvuYRzf5di58Mq6GO4m2u7oj4xuTV zZ0KysojJaQ6ktTD5Ys3PsYIRMseBWwUi3QDCcQ9Be8fDkhO5wwYwtEKv0EoHL5bwtdi Xx4k4uoS6GicuQBnHP/WWxfkL68UA4TxkdTq230pb/0tWMEMcQEYUN7kh1JCH9CmGMAs LfAq1oUeEUalAXJeYU42I1vVoxyFINJ0h6wvr/12+FUfpl5JiY+9TjfWLbtJJNzp65FH 5Drg== 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=rnAvpgJtv8CT4PCBV0v1f+gT06nFs4wcweY9SHoaOe4=; b=OL6hfD4WskbFcoiTIbjt5nWa9VaFD+L9Oa4AYMyXyhP5zIdA9wgC4WZ15zTEM+Gx/q e67NRKtSZzS88YGE8R7afKBzF4kSHxoK+hbycQp8iQkZL66E4A6B+DbB0cfewD2S2wCZ qGh22mtWlLQHAjjDUdMeFmZ35cBh2NgjWSod3I4VUJ9bfsY1oyvFEInDwcIg1FzjHxUW pWQci1gaAVCvpUx3ZI9JB8h78zOS+I2JlQely2gVgvOr9rT2Oghn8KtqzLVbLcZlNkt5 T9Yih2yS38LCq74pOiRSWSO4Qn5zRnIPTCCYYNPNfevUAfe+EDGvUBC1tzLyE3zAyS40 ARcQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b=Gxa5hgO2; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id j67-20020a625546000000b0063473a51539si16403561pfb.398.2023.04.19.14.15.53; Wed, 19 Apr 2023 14:16:09 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b=Gxa5hgO2; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231500AbjDSVIe (ORCPT + 99 others); Wed, 19 Apr 2023 17:08:34 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33312 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231497AbjDSVI2 (ORCPT ); Wed, 19 Apr 2023 17:08:28 -0400 Received: from mail-wm1-x32b.google.com (mail-wm1-x32b.google.com [IPv6:2a00:1450:4864:20::32b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 65C1F5BB2; Wed, 19 Apr 2023 14:08:20 -0700 (PDT) Received: by mail-wm1-x32b.google.com with SMTP id 5b1f17b1804b1-3f0a80b686eso1202865e9.1; Wed, 19 Apr 2023 14:08:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1681938499; x=1684530499; 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=rnAvpgJtv8CT4PCBV0v1f+gT06nFs4wcweY9SHoaOe4=; b=Gxa5hgO2fbz+1mGgBavdX42YSG9adBCLJcXMD7lqySdsOWAigehdu2GrvA89FsztyZ fWHnK7y5Qmf1xDw5VH+PXzYWRg1SFbg83ffni13yXtOz07yM2vaCopXbgeJysOVgIuOR Sgx/hDM7Oy0ndZzQTOXUrDyrnjMlOZZKhBgu2od8189h9TZa5tTVGtydgmH+D1BZIb9A KQ9SmTaqjIT/l8UXf85hunnBzjGFUY6ZBn30r/URt/Gsr1fcwVRb2tzeOCNL+3OKEOKb ID+sYhUEDa1ZUMPQMGIKwvmsSB58+Ql/Jbd25cy6EXoEcW6FIzMVByArrRRvBv1IP25/ H4oA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1681938499; x=1684530499; 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=rnAvpgJtv8CT4PCBV0v1f+gT06nFs4wcweY9SHoaOe4=; b=l/tNdxdcahjvwm78x1j+GilU3/iw/R8KqvkCDbZzATviu2WAl8AsGrAg8HYm5q2A0Q Z9YXQLAT9YnRiIZzsXdXFOqFm3/V241pYyjhrJU4a63zr3bIt8j4cXfgsz1sb4QddqrH LnWRhoe/uD181s9C4+ArIPCWath+jMUxaDPH2Xv9LpCkz8V0EkUgYH0sCxDOIQU/eS5/ h1XsFGsfzlYlC+CetA16LjWThDu5QaT4nv0JKPu5PDMPp2tBnF6QLr32ve6QPvXT2i23 9zRhf0gFK5LJBOUNbccCQ5tZk6onIAI/CvQp2vrYEUNgF80cwI9/PykoWQlFu3sJbcBs iDWg== X-Gm-Message-State: AAQBX9cG12kyzsy8XKSdM6LRBXua/kJGLlFlqbMXHJI+fq3931C7hY+o 40UQwuEhMQ2i8lkOh0lx+q8= X-Received: by 2002:adf:e791:0:b0:2fc:7a4:839b with SMTP id n17-20020adfe791000000b002fc07a4839bmr5380969wrm.61.1681938498828; Wed, 19 Apr 2023 14:08:18 -0700 (PDT) Received: from localhost.localdomain (93-34-93-173.ip49.fastwebnet.it. [93.34.93.173]) by smtp.googlemail.com with ESMTPSA id g3-20020a5d5543000000b002fe254f6c33sm81295wrw.92.2023.04.19.14.08.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 19 Apr 2023 14:08:18 -0700 (PDT) From: Christian Marangi To: Pavel Machek , Lee Jones , Christian Marangi , Martin Schiller , linux-leds@vger.kernel.org, linux-kernel@vger.kernel.org, Andrew Lunn Subject: [PATCH 4/5] leds: trigger: netdev: convert device attr to macro Date: Wed, 19 Apr 2023 23:07:42 +0200 Message-Id: <20230419210743.3594-5-ansuelsmth@gmail.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230419210743.3594-1-ansuelsmth@gmail.com> References: <20230419210743.3594-1-ansuelsmth@gmail.com> MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1763640836686226859?= X-GMAIL-MSGID: =?utf-8?q?1763640836686226859?= Convert link tx and rx device attr to a common macro to reduce common code and in preparation for additional attr. Signed-off-by: Christian Marangi Reviewed-by: Andrew Lunn --- drivers/leds/trigger/ledtrig-netdev.c | 57 ++++++++------------------- 1 file changed, 16 insertions(+), 41 deletions(-) diff --git a/drivers/leds/trigger/ledtrig-netdev.c b/drivers/leds/trigger/ledtrig-netdev.c index 0d4649e7a84d..5a47913c813c 100644 --- a/drivers/leds/trigger/ledtrig-netdev.c +++ b/drivers/leds/trigger/ledtrig-netdev.c @@ -198,47 +198,22 @@ static ssize_t netdev_led_attr_store(struct device *dev, const char *buf, return size; } -static ssize_t link_show(struct device *dev, - struct device_attribute *attr, char *buf) -{ - return netdev_led_attr_show(dev, buf, NETDEV_ATTR_LINK); -} - -static ssize_t link_store(struct device *dev, - struct device_attribute *attr, const char *buf, size_t size) -{ - return netdev_led_attr_store(dev, buf, size, NETDEV_ATTR_LINK); -} - -static DEVICE_ATTR_RW(link); - -static ssize_t tx_show(struct device *dev, - struct device_attribute *attr, char *buf) -{ - return netdev_led_attr_show(dev, buf, NETDEV_ATTR_TX); -} - -static ssize_t tx_store(struct device *dev, - struct device_attribute *attr, const char *buf, size_t size) -{ - return netdev_led_attr_store(dev, buf, size, NETDEV_ATTR_TX); -} - -static DEVICE_ATTR_RW(tx); - -static ssize_t rx_show(struct device *dev, - struct device_attribute *attr, char *buf) -{ - return netdev_led_attr_show(dev, buf, NETDEV_ATTR_RX); -} - -static ssize_t rx_store(struct device *dev, - struct device_attribute *attr, const char *buf, size_t size) -{ - return netdev_led_attr_store(dev, buf, size, NETDEV_ATTR_RX); -} - -static DEVICE_ATTR_RW(rx); +#define DEFINE_NETDEV_TRIGGER(trigger_name, trigger) \ + static ssize_t trigger_name##_show(struct device *dev, \ + struct device_attribute *attr, char *buf) \ + { \ + return netdev_led_attr_show(dev, buf, trigger); \ + } \ + static ssize_t trigger_name##_store(struct device *dev, \ + struct device_attribute *attr, const char *buf, size_t size) \ + { \ + return netdev_led_attr_store(dev, buf, size, trigger); \ + } \ + static DEVICE_ATTR_RW(trigger_name) + +DEFINE_NETDEV_TRIGGER(link, TRIGGER_NETDEV_LINK); +DEFINE_NETDEV_TRIGGER(tx, TRIGGER_NETDEV_TX); +DEFINE_NETDEV_TRIGGER(rx, TRIGGER_NETDEV_RX); static ssize_t interval_show(struct device *dev, struct device_attribute *attr, char *buf) From patchwork Wed Apr 19 21:07:43 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Marangi X-Patchwork-Id: 85547 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp667932vqo; Wed, 19 Apr 2023 14:12:24 -0700 (PDT) X-Google-Smtp-Source: AKy350a0BRmGnrBN5jymNTn/tpJRogc2lvckJ9CXa/Ez7WC26KTUVqmXS2MAZ4W0Bz3QkxGyKXV1 X-Received: by 2002:a17:90b:4c91:b0:234:ba34:71bf with SMTP id my17-20020a17090b4c9100b00234ba3471bfmr4146867pjb.1.1681938744509; Wed, 19 Apr 2023 14:12:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1681938744; cv=none; d=google.com; s=arc-20160816; b=Pk6b/JLIvPIhZVBl1aYY8JVFzAPs1OXcBrCDmcseGiB+wogd/0fDi6E9oXfJN7dh7p B32S1MoA5Jv+rO9WxRKHc+anUZ6Sgev1ByIw7lVZyIM9n0ik7s7AyOBgcQVyg6hzJyVb Ont6nTtYVV34HI8b087APVjeG+pNQlYV4u5cv5z0Pv08LNRg+Jnv43DURB9Xqtxk1Imb NXLFr9uODXf1Xha0OPgYZVJy/R1YQ8O9mdiD/cKwqL1sjPlwp0JL0ycL8plMfueSfSVZ FwJPQhfgJhBfYYLIl5Dp63nW1RDpzqJR+Paw3gMxau81FcCuKR3D3yzJ9mxKZdPjzctP oVPA== 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=c+oYU3lOVwUqdc9f48/HeSPXnQKzJbbtYLzabFYj4Ws=; b=fegl/fYMWWg+sRNnZQ6VLh4GLEuE6bP0Ur/bb+7R2k9WkJAxZUfxsFtLACTpi4/rCS xwCC1Vl7PnBDcu1IBMhVRhrHt93e4LbD1kXVNE/KUS/K+YRw0SCcJzWs0yqBDAspvSSQ zS/BhH4DrElxl0yCSObW1/ZlRDeb1qS588mfFmb0vCDu+AVW7rWnqyVNtq7Ad+oQvG9I Tgk/Z/DpX9f5kbMZwUgOJjx79H55qjDEys6vjLQSH3+d2m6Gog+7uijOeWI+M55m/+Pw vY5MK0hpYH/kx6IMbOkzGQp1obK+ManN/ZKp7pJmtyqro9B77MYBz/I7fwdbo0qrI0I9 WZPg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b=BuDSRqMa; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id lx17-20020a17090b4b1100b00233e301c780si2702759pjb.31.2023.04.19.14.12.09; Wed, 19 Apr 2023 14:12:24 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b=BuDSRqMa; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231458AbjDSVIi (ORCPT + 99 others); Wed, 19 Apr 2023 17:08:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33470 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231509AbjDSVI3 (ORCPT ); Wed, 19 Apr 2023 17:08:29 -0400 Received: from mail-wm1-x32d.google.com (mail-wm1-x32d.google.com [IPv6:2a00:1450:4864:20::32d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A8E5A7685; Wed, 19 Apr 2023 14:08:21 -0700 (PDT) Received: by mail-wm1-x32d.google.com with SMTP id gw13so306195wmb.3; Wed, 19 Apr 2023 14:08:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1681938500; x=1684530500; 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=c+oYU3lOVwUqdc9f48/HeSPXnQKzJbbtYLzabFYj4Ws=; b=BuDSRqMaEJTl61ZYicLdsY4+v9WOMRr+MgGP9ia9GWl1BAycE7/qeanWqp+FhEhrYV PE5ksBPFnV5X/w7cJD8dd90m1ruEa0uXUzI/INH5poc3ZtuTv+wHT3K9w4TM+i0vP44r rEvaIWWBZrLTlatRkRWhe/FEOCEjNL96GDSGxom2bTr3afkXavy98r0eTpT9fZgdey8Q ktipViLPk4HDt3+pK1FZ32FM+O7jsbLfMAfjahn1nVZ87j5UNKr+evYcTbq7yhG4hmB/ BCg33CYFJ8u9OD0DmpiIui+JovZfZlpv4tWCbkLCZ5aRhW76WhFCMiOYYGzBAfyrAh/A DOwA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1681938500; x=1684530500; 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=c+oYU3lOVwUqdc9f48/HeSPXnQKzJbbtYLzabFYj4Ws=; b=hENbgPUJxmKOlmRT/Kytp7kq5Ygrb4D36Y9G9dPIXU2Y0wteKqvfYwakoY29Hmz1IU VuVOTvteMCCkPE4K2HnpEURX5WEsoTNqoYRmxWIy0ulaXEvCBgrLXhCwP+hhbBX4E4yv PNrnbIDHCFLQJ7QYiEMc+xpDQSv1f5NYCWR1UROzgM2vzqO2HExV4XjbRjinKVoccV63 nwCZBkcR+XMwDIhpBOinG6poGmIJjG6Q9e4CZfdLD5A+9eJL3q5TEmswzPOhs5xOJaZT gKMvQIeVV6Dt2C9qqOGA9ZKaGKApmoD72AD2j84bVE3TbGMabcNGgyOqPIDyabD6lIkr +Jtw== X-Gm-Message-State: AAQBX9cY004eZ0/bMWpKvGc7xHkPab1UNHlIi8/+Cp7VE+h5ND3B1Jat EedJu4Ukfy/HNrpovqg1MDQ= X-Received: by 2002:a1c:7c05:0:b0:3f1:6eb5:6e6a with SMTP id x5-20020a1c7c05000000b003f16eb56e6amr11421930wmc.28.1681938499918; Wed, 19 Apr 2023 14:08:19 -0700 (PDT) Received: from localhost.localdomain (93-34-93-173.ip49.fastwebnet.it. [93.34.93.173]) by smtp.googlemail.com with ESMTPSA id g3-20020a5d5543000000b002fe254f6c33sm81295wrw.92.2023.04.19.14.08.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 19 Apr 2023 14:08:19 -0700 (PDT) From: Christian Marangi To: Pavel Machek , Lee Jones , Christian Marangi , Martin Schiller , linux-leds@vger.kernel.org, linux-kernel@vger.kernel.org, Andrew Lunn Subject: [PATCH 5/5] leds: trigger: netdev: use mutex instead of spinlocks Date: Wed, 19 Apr 2023 23:07:43 +0200 Message-Id: <20230419210743.3594-6-ansuelsmth@gmail.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230419210743.3594-1-ansuelsmth@gmail.com> References: <20230419210743.3594-1-ansuelsmth@gmail.com> MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1763640601273641848?= X-GMAIL-MSGID: =?utf-8?q?1763640601273641848?= Some LEDs may require to sleep while doing some operation like setting brightness and other cleanup. For this reason, using a spinlock will cause a sleep under spinlock warning. It should be safe to convert this to a sleepable lock since: - sysfs read/write can sleep - netdev_trig_work is a work queue and can sleep - netdev _trig_notify can sleep The spinlock was used when brightness didn't support sleeping, but this changed and now it supported with brightness_set_blocking(). Convert to mutex lock to permit sleeping using brightness_set_blocking(). Signed-off-by: Christian Marangi Reviewed-by: Andrew Lunn --- drivers/leds/trigger/ledtrig-netdev.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/drivers/leds/trigger/ledtrig-netdev.c b/drivers/leds/trigger/ledtrig-netdev.c index 5a47913c813c..115f2bae9eee 100644 --- a/drivers/leds/trigger/ledtrig-netdev.c +++ b/drivers/leds/trigger/ledtrig-netdev.c @@ -20,7 +20,7 @@ #include #include #include -#include +#include #include #include "../leds.h" @@ -37,7 +37,7 @@ */ struct led_netdev_data { - spinlock_t lock; + struct mutex lock; struct delayed_work work; struct notifier_block notifier; @@ -97,9 +97,9 @@ static ssize_t device_name_show(struct device *dev, struct led_netdev_data *trigger_data = led_trigger_get_drvdata(dev); ssize_t len; - spin_lock_bh(&trigger_data->lock); + mutex_lock(&trigger_data->lock); len = sprintf(buf, "%s\n", trigger_data->device_name); - spin_unlock_bh(&trigger_data->lock); + mutex_unlock(&trigger_data->lock); return len; } @@ -115,7 +115,7 @@ static ssize_t device_name_store(struct device *dev, cancel_delayed_work_sync(&trigger_data->work); - spin_lock_bh(&trigger_data->lock); + mutex_lock(&trigger_data->lock); if (trigger_data->net_dev) { dev_put(trigger_data->net_dev); @@ -138,7 +138,7 @@ static ssize_t device_name_store(struct device *dev, trigger_data->last_activity = 0; set_baseline_state(trigger_data); - spin_unlock_bh(&trigger_data->lock); + mutex_unlock(&trigger_data->lock); return size; } @@ -279,7 +279,7 @@ static int netdev_trig_notify(struct notifier_block *nb, cancel_delayed_work_sync(&trigger_data->work); - spin_lock_bh(&trigger_data->lock); + mutex_lock(&trigger_data->lock); trigger_data->carrier_link_up = false; switch (evt) { @@ -304,7 +304,7 @@ static int netdev_trig_notify(struct notifier_block *nb, set_baseline_state(trigger_data); - spin_unlock_bh(&trigger_data->lock); + mutex_unlock(&trigger_data->lock); return NOTIFY_DONE; } @@ -365,7 +365,7 @@ static int netdev_trig_activate(struct led_classdev *led_cdev) if (!trigger_data) return -ENOMEM; - spin_lock_init(&trigger_data->lock); + mutex_init(&trigger_data->lock); trigger_data->notifier.notifier_call = netdev_trig_notify; trigger_data->notifier.priority = 10;