From: Paolo Bonzini Date: Sat, 18 Oct 2025 08:13:45 +0000 (+0200) Subject: scsi: make SCSIRequest refcount atomic X-Git-Tag: v10.2.0-rc1~40^2~5 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=7e7df2072466de7c0e503857b1530b5459aadfca;p=thirdparty%2Fqemu.git scsi: make SCSIRequest refcount atomic Signed-off-by: Paolo Bonzini --- diff --git a/hw/scsi/scsi-bus.c b/hw/scsi/scsi-bus.c index 9b12ee7f1c..b9b115deed 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); } }