scsi: scsi_transport_fc: Use put_device() on vport setup failure
Subsystems (2)
PATCH 1/1 scsi: scsi_transport_fc: Use put_device() on vport setup failure
fc_vport_setup() initializes the embedded device with device_initialize(). After that point, the device is managed by the driver core reference counting rules. The initial reference should be dropped with put_device().
The error path currently releases dev->parent and frees the fc_vport directly. This bypasses fc_vport_dev_release(), leaving the embedded device lifetime outside the driver core release path.
Keep the existing unwind of the transport and fc_host bookkeeping, but drop the device reference with put_device(). The release callback will release the parent device reference and free the fc_vport object. This issue was found by a static analysis tool I am developing.
--- drivers/scsi/scsi_transport_fc.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/scsi/scsi_transport_fc.c +1 -2
@@ -3982,8 +3982,7 @@ fc_vport_setup(struct Scsi_Host *shost, int channel, struct device *pdev,scsi_host_put (shost);/* for fc_host->vport list */ fc_host->npiv_vports_inuse--;spin_unlock_irqrestore (shost->host_lock, flags); -put_device (dev->parent); -kfree (vport); +put_device (dev);return error; }
Signature · 1 line
2.43.0