From patchwork Tue Jun 10 11:40:19 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tobias Junghans X-Patchwork-Id: 895434 Received: from mo4-p00-ob.smtp.rzone.de (mo4-p00-ob.smtp.rzone.de [81.169.146.216]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D35351FC11F; Tue, 10 Jun 2025 11:43:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=pass smtp.client-ip=81.169.146.216 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749555837; cv=pass; b=DvO4zxcPfxEPjf3onA12CeklPF9YBgcNkz+OUYMrfsBgwqCvR2+d7zWSz2AX72E4XRACkEAIYwhPICc0SxBbfwVHFgyAp3F+e51TabjhERhoIWt//IURkz6tsxDqCZL1nblaxKT2KYdbvOoaUMiZmydZRg/ny0nmDYpmqlyyoew= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749555837; c=relaxed/simple; bh=3pfg9+NOL9Z6C2kDRxwBlHKPTOUuNHjM2OTYR6PYrc4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=AyxKR/8VJFlKjZD7XvwY3slpkNLXlVrMUWd108SEtZntkVVG7wTJY8kx/JY8e3Za73vApG41nE32SgTJhocpp8fCsok6jgGrJiGANkURhugFWQFWenEUVj2pSg0f1LU96HXaAxTchzfQiPrRdiMud5ziCqLxv2UImms7ru/ic7U= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=inhub.de; spf=pass smtp.mailfrom=inhub.de; arc=pass smtp.client-ip=81.169.146.216 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=inhub.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=inhub.de ARC-Seal: i=1; a=rsa-sha256; t=1749555649; cv=none; d=strato.com; s=strato-dkim-0002; b=YZ1EHzYIf1PKdQpDhOk2uvvSFpXrEsS5zufu0eS6zLG9yNP5ql7+kspHG2IsrYQZcP aF9L3VYqOLZt+lHBciBend1iBpi2fQJZ7yA8x1tCP/L07+XSSHvE+XGplFLj7wtsnKb7 lw+lEpf4AjUJ79MrtyQzNUWtLVz55Yir9fGDWTxmWsUsancZ+xB4Rp6OafOHhIcNwTBn A5n47cy+g3gMIfVTrZiuYxmDDhutMY1boMFxwrUm3xZZZidEPcLWWjvhX7iA0okdvodz GSI+p+oXsqlWvU9XuSEsht/0SAuGABBMD4KkeicpcagprbcGRJ4iBlq5Id7/Yj9lzkUq HteA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; t=1749555649; s=strato-dkim-0002; d=strato.com; h=References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From:Cc:Date: From:Subject:Sender; bh=+USfT8fUhTO+Fl9hwpSWxcPLWELa5gF0F9SDLGkBSXY=; b=fgErK5PCwl+DMS5EJxYMqvaLjMWy57x0Gfpjh4Yt/Pk5UpmcTE3e65Wizal1LILL4p MMFE33lOQOlc9RiLW67jR49EjMWhHXDC3yGwKbspE4HRwVYeliiu0khAo2Q2jL+Lrjkq OolT8xc72aGBqDT4eKHuOZkd8bKUI591VZYPkX0RzHumAOKjh4/j9bqVO3XzYMvGa9iV n3z1+1C2xxTDcyOienba1z1FVJQGqz1BbM3ZfVRgAlkoC/5UvjIBveZdqaXCjIwzoQ1s cj1XI+EVR26QnROkPUoF8O4lygu39hSGEAX36hZ0bEUMjqmfCfAxvItP072BG+D3CVgz 25uQ== ARC-Authentication-Results: i=1; strato.com; arc=none; dkim=none X-RZG-CLASS-ID: mo00 X-RZG-AUTH: ":OGMGfEG7NfU1WQAxQKSndOy9b62IXRUXP1G+n0e9SfNgaKe3jg5kqErvsv7wxhn7R+CZYOGugK8=" Received: from crypto.lan.inhub.de by smtp.strato.de (RZmta 51.3.0 AUTH) with ESMTPSA id J569d715ABen5ya (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256 bits)) (Client did not present a certificate); Tue, 10 Jun 2025 13:40:49 +0200 (CEST) From: Tobias Junghans To: Lee Jones , Andrew Lunn , linux-leds@vger.kernel.org, netdev@vger.kernel.org Cc: Tobias Junghans Subject: [PATCH 1/2] leds: trigger: netdev: separate event checks Date: Tue, 10 Jun 2025 13:40:19 +0200 Message-ID: <20250610114029.268938-2-tobias.junghans@inhub.de> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250610114029.268938-1-tobias.junghans@inhub.de> References: <20250610114029.268938-1-tobias.junghans@inhub.de> Precedence: bulk X-Mailing-List: linux-leds@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Move event handling checks into a separate function to ease subsequent refactorings of the actual logic. Signed-off-by: Tobias Junghans --- drivers/leds/trigger/ledtrig-netdev.c | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/drivers/leds/trigger/ledtrig-netdev.c b/drivers/leds/trigger/ledtrig-netdev.c index 4e048e08c4fd..6e16619719fe 100644 --- a/drivers/leds/trigger/ledtrig-netdev.c +++ b/drivers/leds/trigger/ledtrig-netdev.c @@ -575,6 +575,22 @@ static const struct attribute_group *netdev_trig_groups[] = { NULL, }; +static bool netdev_event_requires_handling(unsigned long evt, struct net_device *dev, + struct led_netdev_data *trigger_data) +{ + if (evt != NETDEV_UP && evt != NETDEV_DOWN && evt != NETDEV_CHANGE + && evt != NETDEV_REGISTER && evt != NETDEV_UNREGISTER + && evt != NETDEV_CHANGENAME) + return false; + + if (!(dev == trigger_data->net_dev || + (evt == NETDEV_CHANGENAME && !strcmp(dev->name, trigger_data->device_name)) || + (evt == NETDEV_REGISTER && !strcmp(dev->name, trigger_data->device_name)))) + return false; + + return true; +} + static int netdev_trig_notify(struct notifier_block *nb, unsigned long evt, void *dv) { @@ -584,14 +600,7 @@ static int netdev_trig_notify(struct notifier_block *nb, container_of(nb, struct led_netdev_data, notifier); struct led_classdev *led_cdev = trigger_data->led_cdev; - if (evt != NETDEV_UP && evt != NETDEV_DOWN && evt != NETDEV_CHANGE - && evt != NETDEV_REGISTER && evt != NETDEV_UNREGISTER - && evt != NETDEV_CHANGENAME) - return NOTIFY_DONE; - - if (!(dev == trigger_data->net_dev || - (evt == NETDEV_CHANGENAME && !strcmp(dev->name, trigger_data->device_name)) || - (evt == NETDEV_REGISTER && !strcmp(dev->name, trigger_data->device_name)))) + if (!netdev_event_requires_handling(evt, dev, trigger_data)) return NOTIFY_DONE; cancel_delayed_work_sync(&trigger_data->work); From patchwork Tue Jun 10 11:40:20 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tobias Junghans X-Patchwork-Id: 895800 Received: from mo4-p00-ob.smtp.rzone.de (mo4-p00-ob.smtp.rzone.de [81.169.146.217]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0219421B9F7; Tue, 10 Jun 2025 11:46:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=pass smtp.client-ip=81.169.146.217 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749556013; cv=pass; b=BZhbwsRKm3MoD74JbvnZWO4DVPew9GehrvcsK8k7i4GF2u5AJLa+B9STTz6/Vo6iFvlYCB90oy4SKJzcIjgvMjCBBhnK++5iNCYGzcG2BKowNEYu7PvBFoIrRuctBdcdMwr7dyJjDzCUniuDfcUWl3pkYJ/nv2gP9g16KgRljqQ= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749556013; c=relaxed/simple; bh=uHJX0DxWeFqVosoMPeKr16q7fAhmSfsN6OaFvUHtD08=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=nc1bOQ4dLGKlRTkxp33yvYvVh4oEZv33soE4q0tymsrJLa9NKK/MtVykXHHY05sv4HYqmU4nDDhR1Pllzkq7mbJrMtAiBiV2Tfvi3F+7VFJvXQCcJ+Pxzm3nFT/o3sLiU5MRRlt9BH2YM0QgRn2A1WYtxWCSQPpc7nkX9jGlS1Q= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=inhub.de; spf=pass smtp.mailfrom=inhub.de; arc=pass smtp.client-ip=81.169.146.217 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=inhub.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=inhub.de ARC-Seal: i=1; a=rsa-sha256; t=1749555649; cv=none; d=strato.com; s=strato-dkim-0002; b=Evh0aWvulWGMvk/ec2Ra1bRNhjCgyglFzo9ECK+/MjvM7bn0quUl30F8Jgy4kI6iMy RW3KTtvbIoehlVfEVhGj5785lCszP6c7BGOSN5NJ2lV2tUHrOb3tn/A3WoNeGobxcy3y 0T58BI23nxCdOCxOi43jZgtikCDZpA3j3C3kPIucDZL+6nEePO1D96ySVE9kQ1dRWXg7 WXlRKXGzFdqyOtJV0O2cQRBgR+bPRdXLJpSJnqFSdZ28CFaSobEpY6Ayl6SUDTg6NyEt o/a/dNNbU+Bvq7GCYBJSDHwuqtORqhkwlTUKGAkPF/fcMrFeOZJaH1rmR7eOl6NLDyD8 li9Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; t=1749555649; s=strato-dkim-0002; d=strato.com; h=References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From:Cc:Date: From:Subject:Sender; bh=eIpbhmNUjy3O7tv0PtPRwrwhNYwNcqRDWPgwFL0PBm8=; b=qWfkXyo+oyR1rIg1fH4gzCzAMnWmP+gkQ9Fl50Vzx73Lv9Hnp7jwglD+d3GCyPjj1c OG/8lkhZf8l50wudwqKBPwPpBi0M7esL1WbvuaX9rl5+hUxJLNzPD2Gut87A5Ig9wzoO naaqZhN6fc5ULK13l740wR0UsQkg3rhfjNoXzSKj3RfldkfMSqU7ao7DB9A6Oei0T28o mAVM9nT61YlTZjNcmd24gAXCU5uHV+No5ITa/72AFIA7X/vyZ1zieIi2LB0mEj6SPnIZ bLegrHMoP2ytLczhfdUV5zlMpaktcL1SoBACX43oQpnQm35BkUpfFSdCrkM2sToR2xp/ /tyw== ARC-Authentication-Results: i=1; strato.com; arc=none; dkim=none X-RZG-CLASS-ID: mo00 X-RZG-AUTH: ":OGMGfEG7NfU1WQAxQKSndOy9b62IXRUXP1G+n0e9SfNgaKe3jg5kqErvsv7wxhn7R+CZYOGugK8=" Received: from crypto.lan.inhub.de by smtp.strato.de (RZmta 51.3.0 AUTH) with ESMTPSA id J569d715ABen5yb (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256 bits)) (Client did not present a certificate); Tue, 10 Jun 2025 13:40:49 +0200 (CEST) From: Tobias Junghans To: Lee Jones , Andrew Lunn , linux-leds@vger.kernel.org, netdev@vger.kernel.org Cc: Tobias Junghans Subject: [PATCH 2/2] leds: trigger: netdev: refactor netdev_event_requires_handling() Date: Tue, 10 Jun 2025 13:40:20 +0200 Message-ID: <20250610114029.268938-3-tobias.junghans@inhub.de> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250610114029.268938-1-tobias.junghans@inhub.de> References: <20250610114029.268938-1-tobias.junghans@inhub.de> Precedence: bulk X-Mailing-List: linux-leds@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 If there are network devices with the same name in different namespaces, ledtrig-netdev gets confused easily and switches between these devices whenever there are NETDEV_CHANGENAME/NETDEV_REGISTER notifications. This happens since ledtrig-netdev only checks for device name equality regardless of previous associations with another network device with the same name. Real world example: eth0 is the primary physical network interface and ledltrig-netdev is associated with that interface. If now Docker creates a virtual Ethernet interface (vethXXXX), moves it to the container's net namespace and renames it to eth0, ledtrig-netdev switches to this device and the LED no longer blinks for the original (physical) network device. Fix this by refactoring the conditions under which to handle netdev events: - For processing NETDEV_REGISTER events, the device name has to match and no association with a net_dev must exist. - For processing NETDEV_CHANGENAME events, the associated and notified network device have to match. Alternatively the device name has to match and no association with a net_dev must exist. - For all other events, the associated and notified network device have to match. Signed-off-by: Tobias Junghans --- drivers/leds/trigger/ledtrig-netdev.c | 29 +++++++++++++++++++-------- 1 file changed, 21 insertions(+), 8 deletions(-) diff --git a/drivers/leds/trigger/ledtrig-netdev.c b/drivers/leds/trigger/ledtrig-netdev.c index 6e16619719fe..a3f30e6f74b4 100644 --- a/drivers/leds/trigger/ledtrig-netdev.c +++ b/drivers/leds/trigger/ledtrig-netdev.c @@ -578,15 +578,28 @@ static const struct attribute_group *netdev_trig_groups[] = { static bool netdev_event_requires_handling(unsigned long evt, struct net_device *dev, struct led_netdev_data *trigger_data) { - if (evt != NETDEV_UP && evt != NETDEV_DOWN && evt != NETDEV_CHANGE - && evt != NETDEV_REGISTER && evt != NETDEV_UNREGISTER - && evt != NETDEV_CHANGENAME) - return false; - - if (!(dev == trigger_data->net_dev || - (evt == NETDEV_CHANGENAME && !strcmp(dev->name, trigger_data->device_name)) || - (evt == NETDEV_REGISTER && !strcmp(dev->name, trigger_data->device_name)))) + switch (evt) { + case NETDEV_REGISTER: + if (trigger_data->net_dev || + strcmp(dev->name, trigger_data->device_name)) + return false; + break; + case NETDEV_CHANGENAME: + if (trigger_data->net_dev != dev && + (trigger_data->net_dev || + strcmp(dev->name, trigger_data->device_name))) + return false; + break; + case NETDEV_UNREGISTER: + case NETDEV_UP: + case NETDEV_DOWN: + case NETDEV_CHANGE: + if (trigger_data->net_dev != dev) + return false; + break; + default: return false; + } return true; }