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;