Received: by 2002:a05:6a10:1d13:0:0:0:0 with SMTP id pp19csp195343pxb; Wed, 18 Aug 2021 19:52:36 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyK9W9+KEo60OduVqnPnB1/dm/SxgIYs6b0l3KbjkuvhgIrQHL6rexVX95y7LDRbrHVRoJ+ X-Received: by 2002:a6b:610e:: with SMTP id v14mr9598221iob.70.1629341556709; Wed, 18 Aug 2021 19:52:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1629341556; cv=none; d=google.com; s=arc-20160816; b=qZst5jolq43ep4wl14LVkjtt3klHaVmy617CV60XlSIKGHIWLa9epyrTyk4T/7sHn6 rmpsbuZEFN7y0puPXP9ns9Ehve06iJN5Qol1tAiDBR30b5dAofZv4Bwz3ZjGtC9N/CNv 7wiHoduwDRpeqrnjirHNGqUCYX/MOLSrSgreIzzE7Gr9+fJYyDjSkOLOlMMZDjzJougf 3LAhVWGIwj0xhsa65fn5ZO+R4bksaQWMMTm3aP6EHD03CeILoH9ECdnXbQ281NrPMiCU GfAgSnAJqn49TRYzRytppLrA4g1Arj7yupKr20SUlml6JKMNY65doGDPs2xya2dC92Fo G8jg== 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=M/NUaTEslE7hYgIeaV8Kn3/oBWy9c6O39iYX3Cnl+Lo=; b=kLvgCZlkXZild41cJXB+ThDqoE4jLkX7gZdd5Cg7SzxmRrUXoOLw6/TVOEEAxPO/wn /VUFu77cW/k8zKbXdooYngyC6PQHntpehpIHXkeiFMPxia0Ov2FkHZPK9kKPrf+vgGE9 ovk0lCqQv5J1YehiKTccRvXoHq2HygvQSEGfB17z32a9SQfU21IuqyhFomKccDtuACAF G/8xprVvwUOdJHRuxEAvHTd7yM50WxMuH6MYPAJUCtoz3JukD4CHUg7uPdwy98SYA08a cA7OHU7jVtTkTI1Ww/wadp7PDwvVF7MDwb0BrCRBi0r+Lm/vqtuOeuT6r0i6B5jZgKRJ msxg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=FqT2S8VM; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id f18si1524941iox.32.2021.08.18.19.52.26; Wed, 18 Aug 2021 19:52:36 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=FqT2S8VM; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 S236040AbhHSCwC (ORCPT + 99 others); Wed, 18 Aug 2021 22:52:02 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51378 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235922AbhHSCvq (ORCPT ); Wed, 18 Aug 2021 22:51:46 -0400 Received: from mail-ot1-x32e.google.com (mail-ot1-x32e.google.com [IPv6:2607:f8b0:4864:20::32e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CFA1AC061764; Wed, 18 Aug 2021 19:51:10 -0700 (PDT) Received: by mail-ot1-x32e.google.com with SMTP id w22-20020a056830411600b0048bcf4c6bd9so6844474ott.8; Wed, 18 Aug 2021 19:51:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=M/NUaTEslE7hYgIeaV8Kn3/oBWy9c6O39iYX3Cnl+Lo=; b=FqT2S8VM3TK55vvDvRvBBb+HuJWK6vQOYFPfdnhPDrr0IykKsGbNrPAvPhTXgfIIcP FuzaZjlxskiilziBJgyAjUWa1YZkiBBela1eK/vlmyJH164vkghksiPpQ1e63JA0yXQ7 y5MRszITcbmp1Ig4BUr8lNXMlXtmzPNiAfepGDOlzvQW0ZDIGBSszXYn/wivjhGg1BlM DHjZo6FRR2PllWqFxd4F8nwLQTR7PvUMiaMHzcEJUYX/yyHfN9Ru5mbm+hKE07OF1wZ4 ii+bQThK1RQYAJ9TqHjBx/ooAll1VSk9sPhOqXY2alkf/3zX26LI4IOJcLxwaNulpbEw M9wQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=M/NUaTEslE7hYgIeaV8Kn3/oBWy9c6O39iYX3Cnl+Lo=; b=gl6tQxt5AUQL2YgqKurMv1v33slsvX2LHAvlU3gD+mySLItxQhRbbsJaVu68YnS0Xc /z9kZG9uwgAlAyB441Ar4O1KAweVUKLfn4lmeGmEGhIqHLTtN17G9WvaIWcImvIZhXhW Gseqsg9OYnYRZR3jFaPkhjc35SanYMhDZaC0c7t0ZGnD2k3MYLOpST4veuH4eihL/p89 OxmjYGsAMG3SD6CjsBvX7h5TQwwNoZm9pedWBPI3gpOKMyfwy8FyvXuAX2AXZMcVDzpt ca8LH6nvsLTQ3IEKxOL0z1+16gKDUwVcud6+czjLn/SmiJuFZznuBekYBDA6ZI6EPHVs 6hDw== X-Gm-Message-State: AOAM5318CenAQGURMgpv9fh9y6r6csSddlA2wuiKpq5wgXJ6cSDh01v3 QdtvWbwrVUHlFlGsA268xNqiAbrTsytwnM4n X-Received: by 2002:a9d:6505:: with SMTP id i5mr4501523otl.284.1629341470011; Wed, 18 Aug 2021 19:51:10 -0700 (PDT) Received: from ian.penurio.us ([47.184.51.90]) by smtp.gmail.com with ESMTPSA id w15sm156792oiw.19.2021.08.18.19.51.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Aug 2021 19:51:09 -0700 (PDT) From: Ian Pilcher To: linux-block@vger.kernel.org, linux-leds@vger.kernel.org Cc: axboe@kernel.dk, pavel@ucw.cz, kabel@kernel.org, linux-kernel@vger.kernel.org, kernelnewbies@kernelnewbies.org Subject: [RFC PATCH v3 08/18] ledtrig-blkdev: Add function to remove LED/device association Date: Wed, 18 Aug 2021 21:50:43 -0500 Message-Id: <20210819025053.222710-9-arequipeno@gmail.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210819025053.222710-1-arequipeno@gmail.com> References: <20210819025053.222710-1-arequipeno@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Remove symlinks in /sys/class/leds//block_devices and /sys/block//blkdev_leds Decrement reference count on /sys/block//blkdev_leds directory (removes directory when empty) Cancel delayed work when disassociating last device Signed-off-by: Ian Pilcher --- drivers/leds/trigger/ledtrig-blkdev.c | 56 +++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) diff --git a/drivers/leds/trigger/ledtrig-blkdev.c b/drivers/leds/trigger/ledtrig-blkdev.c index e9c23824c33c..447fc81ae0c5 100644 --- a/drivers/leds/trigger/ledtrig-blkdev.c +++ b/drivers/leds/trigger/ledtrig-blkdev.c @@ -225,3 +225,59 @@ static void blkdev_process(struct work_struct *const work) delay = READ_ONCE(ledtrig_blkdev_interval); WARN_ON_ONCE(!schedule_delayed_work(&ledtrig_blkdev_work, delay)); } + + +/* + * + * Disassociate a block device from an LED + * + */ + +static void blkdev_disk_del_locked(struct ledtrig_blkdev_led *const led, + struct ledtrig_blkdev_link *const link, + struct ledtrig_blkdev_disk *const disk) +{ + --ledtrig_blkdev_count; + + if (ledtrig_blkdev_count == 0) + WARN_ON(!cancel_delayed_work_sync(&ledtrig_blkdev_work)); + + sysfs_remove_link(led->dir, disk->gd->disk_name); + sysfs_remove_link(disk->dir, led->led_dev->name); + kobject_put(disk->dir); + + hlist_del(&link->led_disks_node); + hlist_del(&link->disk_leds_node); + kfree(link); + + if (hlist_empty(&disk->leds)) { + disk->gd->ledtrig = NULL; + kfree(disk); + } + + put_device(disk_to_dev(disk->gd)); +} + +static void blkdev_disk_delete(struct ledtrig_blkdev_led *const led, + const char *const disk_name, + const size_t name_len) +{ + struct ledtrig_blkdev_link *link; + + mutex_lock(&ledtrig_blkdev_mutex); + + hlist_for_each_entry(link, &led->disks, led_disks_node) { + + if (blkdev_streq(link->disk->gd->disk_name, + disk_name, name_len)) { + blkdev_disk_del_locked(led, link, link->disk); + goto exit_unlock; + } + } + + pr_info("blkdev LED: %.*s not associated with LED %s\n", + (int)name_len, disk_name, led->led_dev->name); + +exit_unlock: + mutex_unlock(&ledtrig_blkdev_mutex); +} -- 2.31.1