Received: by 2002:a05:6a10:eb17:0:0:0:0 with SMTP id hx23csp1197195pxb; Thu, 9 Sep 2021 23:49:55 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw9Bjl5806vMgcKNpA0MHML/Y4kIMobg+OU/5ShH96FTbhMQfj1h+Eokfn6NMGv3TB4vr5Z X-Received: by 2002:a6b:3b8c:: with SMTP id i134mr5598674ioa.29.1631256595487; Thu, 09 Sep 2021 23:49:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1631256595; cv=none; d=google.com; s=arc-20160816; b=Fi+Jp6m1HrqVrNCGZNeZU+FAQhZxGdhTQbKQtbyczk279qWmmetQIDLAW1qzoxGBwy NYrPIkOHAK/Nnoo5W9LogRp7Az2ModlechW7jDrG/X94/XkldeTACwBhXCpipxBSjvVz 5wc8x0/zabMYW0NlPo7o3FXMxqkL4Y4jX6SnhrfIeKrOtQD74fkfmShGW58Gqpxma1XZ NOkLdNEMKVUCm71ptEQ/A9WFwi/zKXqJidfZfJmaDjZWKQws+R/3E2xzEQ0+kXKg0RE5 WlFmygAmua1hr5ZVUtSNevp0087LvcCD8U+1l3lUvNfvFaSlQ0msoivyZ4j30uHsHIrd FFBw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=gM/EdgXubvahzFxFqSwrBur5vPekdicBn/R1YXIsYpk=; b=DBcQgH8sp/nWcJs+7cOaP2H038jmYcNinov0z66U2ll+uOvZquwRUSNCKhOTHEjj/S OsEShPtQ/RVjjMDBZfdkxL5M3FAwib98odWoFvtUhtneCK57JLzmClcILdQeuPWMp432 lBamoDLv24RTUbnjx37H3b9PLRMQwW2qpbvaU4b1vhos5r0iZ41mh3w+b7OzGtJrS/Hv qJYkldmy34PPC7Uyn2jqbttW98wrLwqpPjT9DMnJpMSFB/GvEOYfIPx9Q++2QizNa0+E 2/xBAtgUpa8iIzi/IVolizSACPQzcWfw4o4MglR6X6JozI3N2GKCufXa70Pmp/KXqFvZ qaBA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="g3/0iqK+"; 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=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id b11si4347207ilj.16.2021.09.09.23.49.43; Thu, 09 Sep 2021 23:49:55 -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=@linuxfoundation.org header.s=korg header.b="g3/0iqK+"; 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=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231237AbhIJGuL (ORCPT + 99 others); Fri, 10 Sep 2021 02:50:11 -0400 Received: from mail.kernel.org ([198.145.29.99]:38756 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231223AbhIJGuK (ORCPT ); Fri, 10 Sep 2021 02:50:10 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 9FA6960F9C; Fri, 10 Sep 2021 06:48:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1631256540; bh=vXJAXbhhRVXEIInC57PKl2Etg+1VL0ZTnPPtyJWXfQE=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=g3/0iqK+l0/n6VvnkF0pXW7nCoy+Qy8uqoRX55nHBcMT0rP5IStNe5aBlGnE1+QwB kLAu3CKJ2LXdPiiA5s3jmDP6SeIBhDT57NHkAj562QrzcJhJlra+qy7kSITaDZ16MC ITYahQcfTmvsQqQ49FxBdevomUXLMuf14NIXAujo= Date: Fri, 10 Sep 2021 08:48:57 +0200 From: Greg KH To: Ian Pilcher Cc: axboe@kernel.dk, pavel@ucw.cz, linux-leds@vger.kernel.org, linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, kabel@kernel.org Subject: Re: [PATCH v2 11/15] leds: trigger: blkdev: Enable linking block devices to LEDs Message-ID: References: <20210909222513.2184795-1-arequipeno@gmail.com> <20210909222513.2184795-12-arequipeno@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20210909222513.2184795-12-arequipeno@gmail.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Sep 09, 2021 at 05:25:09PM -0500, Ian Pilcher wrote: > Add /sys/class/leds//link_device sysfs attribute > > If this is the first LED associated with the device, create the > /sys/block//blkdev_leds directory. Otherwise, increment its > reference count. > > Create symlinks in /sys/class/leds//block_devices and > /sys/block//blkdev_leds > > If this the first device associated with *any* LED, schedule delayed work > to periodically check associated devices and blink LEDs > > Signed-off-by: Ian Pilcher > --- > drivers/leds/trigger/ledtrig-blkdev.c | 160 ++++++++++++++++++++++++++ > 1 file changed, 160 insertions(+) > > diff --git a/drivers/leds/trigger/ledtrig-blkdev.c b/drivers/leds/trigger/ledtrig-blkdev.c > index 6f78a9515976..26509837f037 100644 > --- a/drivers/leds/trigger/ledtrig-blkdev.c > +++ b/drivers/leds/trigger/ledtrig-blkdev.c > @@ -71,6 +71,9 @@ static unsigned int ledtrig_blkdev_interval; > static void blkdev_process(struct work_struct *const work); > static DECLARE_DELAYED_WORK(ledtrig_blkdev_work, blkdev_process); > > +/* Total number of device-to-LED associations */ > +static unsigned int ledtrig_blkdev_count; > + > > /* > * > @@ -220,6 +223,162 @@ static int blkdev_activate(struct led_classdev *const led_dev) > } > > > +/* > + * > + * link_device sysfs attribute - assocate a block device with this LED > + * > + */ > + > +/* Gets or allocs & initializes the blkdev disk for a gendisk */ > +static int blkdev_get_disk(struct gendisk *const gd) > +{ > + struct ledtrig_blkdev_disk *disk; > + struct kobject *dir; > + > + if (gd->ledtrig != NULL) { > + kobject_get(gd->ledtrig->dir); When do you decrement this kobject? > + return 0; > + } > + > + disk = kmalloc(sizeof(*disk), GFP_KERNEL); > + if (disk == NULL) > + return -ENOMEM; > + > + dir = kobject_create_and_add("linked_leds", &disk_to_dev(gd)->kobj); > + if (dir == NULL) { > + kfree(disk); > + return -ENOMEM; > + } > + > + INIT_HLIST_HEAD(&disk->leds); > + disk->gd = gd; > + disk->dir = dir; > + disk->read_ios = 0; > + disk->write_ios = 0; > + > + gd->ledtrig = disk; > + > + return 0; > +} > + > +static void blkdev_put_disk(struct ledtrig_blkdev_disk *const disk) > +{ > + kobject_put(disk->dir); > + > + if (hlist_empty(&disk->leds)) { > + disk->gd->ledtrig = NULL; > + kfree(disk); This should happen in the kobject release function, not here, right? Did you try this out with removable block devices yet? thanks, greg k-h