Re: [PATCH v2 06/15] leds: trigger: blkdev: Add function to get gendisk by name

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxx>
> ---
>  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



[Index of Archives]     [Linux ARM Kernel]     [Linux ARM]     [Linux Omap]     [Fedora ARM]     [IETF Annouce]     [Security]     [Bugtraq]     [Linux OMAP]     [Linux MIPS]     [ECOS]     [Asterisk Internet PBX]     [Linux API]

  Powered by Linux