Re: [PATCH 1/5] SCSI: sd: simplify ida usage

From: Johannes Thumshirn
Date: Fri Oct 02 2015 - 06:15:14 EST


Lee Duncan <lduncan@xxxxxxxx> writes:

> Simplify ida index allocation and removal by
> using the ida_simple_* helper functions.
>
> Signed-off-by: Lee Duncan <lduncan@xxxxxxxx>
> ---
> drivers/scsi/sd.c | 22 +++++-----------------
> 1 file changed, 5 insertions(+), 17 deletions(-)
>
> diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c
> index 3b2fcb4fada0..3d77ac8f0d4c 100644
> --- a/drivers/scsi/sd.c
> +++ b/drivers/scsi/sd.c
> @@ -118,7 +118,6 @@ static void scsi_disk_release(struct device *cdev);
> static void sd_print_sense_hdr(struct scsi_disk *, struct scsi_sense_hdr *);
> static void sd_print_result(const struct scsi_disk *, const char *, int);
>
> -static DEFINE_SPINLOCK(sd_index_lock);
> static DEFINE_IDA(sd_index_ida);
>
> /* This semaphore is used to mediate the 0->1 reference get in the
> @@ -2948,19 +2947,12 @@ static int sd_probe(struct device *dev)
> if (!gd)
> goto out_free;
>
> - do {
> - if (!ida_pre_get(&sd_index_ida, GFP_KERNEL))
> - goto out_put;
> -
> - spin_lock(&sd_index_lock);
> - error = ida_get_new(&sd_index_ida, &index);
> - spin_unlock(&sd_index_lock);
> - } while (error == -EAGAIN);
> -
> - if (error) {
> + error = ida_simple_get(&sd_index_ida, 0, 0, GFP_KERNEL);
> + if (error < 0) {
> sdev_printk(KERN_WARNING, sdp, "sd_probe: memory exhausted.\n");
> goto out_put;
> }
> + index = error;
>
> error = sd_format_disk_name("sd", index, gd->disk_name, DISK_NAME_LEN);
> if (error) {
> @@ -3001,9 +2993,7 @@ static int sd_probe(struct device *dev)
> return 0;
>
> out_free_index:
> - spin_lock(&sd_index_lock);
> - ida_remove(&sd_index_ida, index);
> - spin_unlock(&sd_index_lock);
> + ida_simple_remove(&sd_index_ida, index);
> out_put:
> put_disk(gd);
> out_free:
> @@ -3064,9 +3054,7 @@ static void scsi_disk_release(struct device *dev)
> struct scsi_disk *sdkp = to_scsi_disk(dev);
> struct gendisk *disk = sdkp->disk;
>
> - spin_lock(&sd_index_lock);
> - ida_remove(&sd_index_ida, sdkp->index);
> - spin_unlock(&sd_index_lock);
> + ida_simple_remove(&sd_index_ida, sdkp->index);
>
> blk_integrity_unregister(disk);
> disk->private_data = NULL;

Reviewed-by: Johannes Thumshirn <jthumshirn@xxxxxxx>

--
Johannes Thumshirn Storage
jthumshirn@xxxxxxx +49 911 74053 689
SUSE LINUX GmbH, Maxfeldstr. 5, 90409 NÃrnberg
GF: Felix ImendÃrffer, Jane Smithard, Graham Norton
HRB 21284 (AG NÃrnberg)
Key fingerprint = EC38 9CAB C2C4 F25D 8600 D0D0 0393 969D 2D76 0850
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/