[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <YTr+8h12z7kMLlV/@kroah.com>
Date: Fri, 10 Sep 2021 08:45:06 +0200
From: Greg KH <gregkh@...uxfoundation.org>
To: Ian Pilcher <arequipeno@...il.com>
Cc: axboe@...nel.dk, pavel@....cz, linux-leds@...r.kernel.org,
linux-block@...r.kernel.org, linux-kernel@...r.kernel.org,
kabel@...nel.org
Subject: Re: [PATCH v2 06/15] leds: trigger: blkdev: Add function to get
gendisk by name
On Thu, Sep 09, 2021 at 05:25:04PM -0500, Ian Pilcher wrote:
> Add ledtrig_blkdev_get_disk() to find block device by name and increment
> its reference count. (Caller must call put_disk().) Must be built-in to
> access block_class and disk_type symbols.
>
> Signed-off-by: Ian Pilcher <arequipeno@...il.com>
> ---
> drivers/leds/trigger/ledtrig-blkdev-core.c | 20 ++++++++++++++++++++
> drivers/leds/trigger/ledtrig-blkdev.h | 3 +++
> 2 files changed, 23 insertions(+)
>
> diff --git a/drivers/leds/trigger/ledtrig-blkdev-core.c b/drivers/leds/trigger/ledtrig-blkdev-core.c
> index d7b02e760b06..5fd741aa14a6 100644
> --- a/drivers/leds/trigger/ledtrig-blkdev-core.c
> +++ b/drivers/leds/trigger/ledtrig-blkdev-core.c
> @@ -33,3 +33,23 @@ void ledtrig_blkdev_disk_cleanup(struct gendisk *const gd)
>
> mutex_unlock(&ledtrig_blkdev_mutex);
> }
> +
> +/* class_find_device() callback. Must be built-in to access disk_type. */
> +static int blkdev_match_name(struct device *const dev, const void *const name)
> +{
> + return dev->type == &disk_type
> + && sysfs_streq(dev_to_disk(dev)->disk_name, name);
> +}
> +
> +/* Must be built-in to access block_class */
> +struct gendisk *ledtrig_blkdev_get_disk(const char *const name)
> +{
> + struct device *dev;
> +
> + dev = class_find_device(&block_class, NULL, name, blkdev_match_name);
> + if (dev == NULL)
> + return NULL;
You now have bumped the reference count on this structure. Where do you
decrement it when you are finished with it?
thanks,
greg k-h
Powered by blists - more mailing lists