Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1225438
| From | Lee Duncan <lduncan@suse.com> |
|---|---|
| Newsgroups | linux.kernel |
| Subject | [PATCH 04/17] Update the ch driver to use idr helper functions. |
| Date | 2015-09-15 19:00 +0200 |
| Message-ID | <q91Kk-2gb-29@gated-at.bofh.it> (permalink) |
| References | <q91AC-24K-5@gated-at.bofh.it> |
| Organization | linux.* mail to news gateway |
Note: when allocating an index, in the error case,
where the just-allocated index has to be released,
the required locking around the index removal was
not present, so this conversion has the side effect
of adding locking for that error condition. This
should close a possible race condition that could
have resulted in duplicate index allocation.
Signed-off-by: Lee Duncan <lduncan@suse.com>
---
drivers/scsi/ch.c | 14 ++++----------
1 file changed, 4 insertions(+), 10 deletions(-)
diff --git a/drivers/scsi/ch.c b/drivers/scsi/ch.c
index dad959fcf6d8..2edf1f8883f9 100644
--- a/drivers/scsi/ch.c
+++ b/drivers/scsi/ch.c
@@ -909,12 +909,8 @@ static int ch_probe(struct device *dev)
if (NULL == ch)
return -ENOMEM;
- idr_preload(GFP_KERNEL);
- spin_lock(&ch_index_lock);
- ret = idr_alloc(&ch_index_idr, ch, 0, CH_MAX_DEVS + 1, GFP_NOWAIT);
- spin_unlock(&ch_index_lock);
- idr_preload_end();
-
+ ret = idr_get_index_in_range(&ch_index_idr, &ch_index_lock, ch,
+ 0, CH_MAX_DEVS + 1);
if (ret < 0) {
if (ret == -ENOSPC)
ret = -ENODEV;
@@ -945,7 +941,7 @@ static int ch_probe(struct device *dev)
return 0;
remove_idr:
- idr_remove(&ch_index_idr, ch->minor);
+ idr_put_index(&ch_index_idr, &ch_index_lock, ch->minor);
free_ch:
kfree(ch);
return ret;
@@ -955,9 +951,7 @@ static int ch_remove(struct device *dev)
{
scsi_changer *ch = dev_get_drvdata(dev);
- spin_lock(&ch_index_lock);
- idr_remove(&ch_index_idr, ch->minor);
- spin_unlock(&ch_index_lock);
+ idr_put_index(&ch_index_idr, &ch_index_lock, ch->minor);
device_destroy(ch_sysfs_class, MKDEV(SCSI_CHANGER_MAJOR,ch->minor));
kfree(ch->dt);
--
2.1.4
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Back to linux.kernel | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
[PATCH 00/17] Create and use ida and idr helper routines Lee Duncan <lduncan@suse.com> - 2015-09-15 19:00 +0200
[PATCH 04/17] Update the ch driver to use idr helper functions. Lee Duncan <lduncan@suse.com> - 2015-09-15 19:00 +0200
[PATCH 11/17] Update the rtsx multifunction driver to use idr helper functions. Lee Duncan <lduncan@suse.com> - 2015-09-15 19:00 +0200
[PATCH 12/17] Update the TI Flash Media driver to use idr helper functions. Lee Duncan <lduncan@suse.com> - 2015-09-15 19:00 +0200
[PATCH 02/17] Update scsi hosts to use idr for host number mgmt Lee Duncan <lduncan@suse.com> - 2015-09-15 19:00 +0200
[PATCH 01/17] Add ida and idr helper routines. Lee Duncan <lduncan@suse.com> - 2015-09-15 19:00 +0200
Re: [PATCH 01/17] Add ida and idr helper routines. James Bottomley <James.Bottomley@HansenPartnership.com> - 2015-09-15 20:30 +0200
Re: [PATCH 01/17] Add ida and idr helper routines. Tejun Heo <tj@kernel.org> - 2015-09-15 20:30 +0200
Re: [PATCH 01/17] Add ida and idr helper routines. James Bottomley <James.Bottomley@HansenPartnership.com> - 2015-09-15 20:40 +0200
Re: [PATCH 01/17] Add ida and idr helper routines. Tejun Heo <tj@kernel.org> - 2015-09-15 20:50 +0200
Re: [PATCH 01/17] Add ida and idr helper routines. Tejun Heo <tj@kernel.org> - 2015-09-18 17:50 +0200
Re: [PATCH 01/17] Add ida and idr helper routines. Lee Duncan <lduncan@suse.com> - 2015-09-18 17:50 +0200
[PATCH 03/17] Update the st driver to use idr helper functions. Lee Duncan <lduncan@suse.com> - 2015-09-15 19:00 +0200
[PATCH 10/17] Update the DCA DMA driver to use idr helper functions. Lee Duncan <lduncan@suse.com> - 2015-09-15 19:00 +0200
csiph-web