Message ID | 20200529134730.146573-3-hare@suse.de (mailing list archive) |
---|---|
State | Superseded |
Headers | show |
Series | scsi: use xarray for devices and targets | expand |
On 5/29/20 8:47 AM, Hannes Reinecke wrote: > Instead of walking the list of devices manually use the helper > function to return the device directly. > > Signed-off-by: Hannes Reinecke <hare@suse.de> > Reviewed-by: Johannes Thumshirn <johannes.thumshirn@wdc.com> > Reviewed-by: Bart van Assche <bvanassche@acm.org> > --- > drivers/target/target_core_pscsi.c | 8 +++----- > 1 file changed, 3 insertions(+), 5 deletions(-) > > diff --git a/drivers/target/target_core_pscsi.c b/drivers/target/target_core_pscsi.c > index c9d92b3e777d..5fb852d1281f 100644 > --- a/drivers/target/target_core_pscsi.c > +++ b/drivers/target/target_core_pscsi.c > @@ -496,11 +496,9 @@ static int pscsi_configure_device(struct se_device *dev) > } > > spin_lock_irq(sh->host_lock); > - list_for_each_entry(sd, &sh->__devices, siblings) { > - if ((pdv->pdv_channel_id != sd->channel) || > - (pdv->pdv_target_id != sd->id) || > - (pdv->pdv_lun_id != sd->lun)) > - continue; > + sd = __scsi_device_lookup(sh, pdv->pdv_channel_id, > + pdv->pdv_target_id, pdv->pdv_lun_id); > + if (sd) { > /* > * Functions will release the held struct scsi_host->host_lock > * before calling calling pscsi_add_device_to_list() to register > Do you need a check in pscsi_set_configfs_dev_params to make sure pdv_channel_id is withing the 16 value limit? If not, userspace could use pdv_channel_id = (1 << 17) and when you shift that by 16, will we end up with 0 after the cast? It's probably only going to come up in QA/testing type of setups since as you said there's never been a case with a channel_id that large.
diff --git a/drivers/target/target_core_pscsi.c b/drivers/target/target_core_pscsi.c index c9d92b3e777d..5fb852d1281f 100644 --- a/drivers/target/target_core_pscsi.c +++ b/drivers/target/target_core_pscsi.c @@ -496,11 +496,9 @@ static int pscsi_configure_device(struct se_device *dev) } spin_lock_irq(sh->host_lock); - list_for_each_entry(sd, &sh->__devices, siblings) { - if ((pdv->pdv_channel_id != sd->channel) || - (pdv->pdv_target_id != sd->id) || - (pdv->pdv_lun_id != sd->lun)) - continue; + sd = __scsi_device_lookup(sh, pdv->pdv_channel_id, + pdv->pdv_target_id, pdv->pdv_lun_id); + if (sd) { /* * Functions will release the held struct scsi_host->host_lock * before calling calling pscsi_add_device_to_list() to register