Jörn Engel <joern@xxxxxxxxx> writes: > diff --git a/drivers/scsi/mpt2sas/mpt2sas_scsih.c b/drivers/scsi/mpt2sas/mpt2sas_scsih.c > index c6bdc92..43b3a98 100644 > --- a/drivers/scsi/mpt2sas/mpt2sas_scsih.c > +++ b/drivers/scsi/mpt2sas/mpt2sas_scsih.c > @@ -570,6 +570,18 @@ _scsih_sas_device_find_by_handle(struct MPT2SAS_ADAPTER *ioc, u16 handle) > return NULL; > } > > +static void free_sas_device(struct kref *kref) > +{ > + struct _sas_device *sas_device = container_of(kref, struct _sas_device, > + kref); > + kfree(sas_device); > +} > + > +static void put_sas_device(struct _sas_device *sas_device) > +{ > + kref_put(&sas_device->kref, free_sas_device); > +} > + > /** > * _scsih_sas_device_remove - remove sas_device from list. > * @ioc: per adapter object > @@ -583,14 +595,19 @@ _scsih_sas_device_remove(struct MPT2SAS_ADAPTER *ioc, > struct _sas_device *sas_device) > { > unsigned long flags; > + int was_on_list = 0; > > if (!sas_device) > return; > > spin_lock_irqsave(&ioc->sas_device_lock, flags); > - list_del(&sas_device->list); > - kfree(sas_device); > + if (!list_empty(&sas_device->list)) { > + list_del_init(&sas_device->list); > + was_on_list = 1; > + } > spin_unlock_irqrestore(&ioc->sas_device_lock, flags); > + if (was_on_list) > + put_sas_device(sas_device); > } > How about the copy of this code in drivers/scsi/mpt3sas/mpt3sas_scsih.c? Is that safe, or does it need fixing as well? Bjørn -- To unsubscribe from this list: send the line "unsubscribe linux-scsi" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html