Signed-off-by: Paolo Bonzini <[email protected]>
---
hw/scsi/scsi-bus.c | 13 ++++---------
1 file changed, 4 insertions(+), 9 deletions(-)
diff --git a/hw/scsi/scsi-bus.c b/hw/scsi/scsi-bus.c
index 9b12ee7f1c6..b9b115deedd 100644
--- a/hw/scsi/scsi-bus.c
+++ b/hw/scsi/scsi-bus.c
@@ -823,7 +823,6 @@ SCSIRequest *scsi_req_alloc(const SCSIReqOps *reqops,
SCSIDevice *d,
{
SCSIRequest *req;
SCSIBus *bus = scsi_bus_from_device(d);
- BusState *qbus = BUS(bus);
const int memset_off = offsetof(SCSIRequest, sense)
+ sizeof(req->sense);
@@ -838,8 +837,6 @@ SCSIRequest *scsi_req_alloc(const SCSIReqOps *reqops,
SCSIDevice *d,
req->status = -1;
req->host_status = -1;
req->ops = reqops;
- object_ref(OBJECT(d));
- object_ref(OBJECT(qbus->parent));
notifier_list_init(&req->cancel_notifiers);
if (reqops->init_req) {
@@ -1496,15 +1493,15 @@ void scsi_device_report_change(SCSIDevice *dev,
SCSISense sense)
SCSIRequest *scsi_req_ref(SCSIRequest *req)
{
- assert(req->refcount > 0);
- req->refcount++;
+ assert(qatomic_read(&req->refcount) > 0);
+ qatomic_inc(&req->refcount);
return req;
}
void scsi_req_unref(SCSIRequest *req)
{
- assert(req->refcount > 0);
- if (--req->refcount == 0) {
+ assert(qatomic_read(&req->refcount) > 0);
+ if (qatomic_fetch_dec(&req->refcount) == 1) {
BusState *qbus = req->dev->qdev.parent_bus;
SCSIBus *bus = DO_UPCAST(SCSIBus, qbus, qbus);
@@ -1514,8 +1511,6 @@ void scsi_req_unref(SCSIRequest *req)
if (req->ops->free_req) {
req->ops->free_req(req);
}
- object_unref(OBJECT(req->dev));
- object_unref(OBJECT(qbus->parent));
g_free(req);
}
}
--
2.51.1