scsi: zfcp: Move the position of put_device()
authorQinglang Miao <miaoqinglang@huawei.com>
Wed, 14 Apr 2021 17:08:03 +0000 (19:08 +0200)
committerMartin K. Petersen <martin.petersen@oracle.com>
Fri, 16 Apr 2021 02:19:40 +0000 (22:19 -0400)
Place the put_device() call after device_unregister() in both
zfcp_unit_remove() and zfcp_sysfs_port_remove_store() to make it more
natural. put_device() ought to be the last time we touch the object in both
functions.

Add comments after put_device() to make code clearer.

Link: https://lore.kernel.org/r/0a568c7733ba0f1dde28b0c663b90270d44dd540.1618417667.git.bblock@linux.ibm.com
Suggested-by: Steffen Maier <maier@linux.ibm.com>
Suggested-by: Benjamin Block <bblock@linux.ibm.com>
Signed-off-by: Qinglang Miao <miaoqinglang@huawei.com>
Signed-off-by: Benjamin Block <bblock@linux.ibm.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
drivers/s390/scsi/zfcp_sysfs.c
drivers/s390/scsi/zfcp_unit.c

index f76946dcbd59e685241446c9b8fd394d513fa2f7..544efd4c42f0220dac9800ddf1517e899556203f 100644 (file)
@@ -327,10 +327,10 @@ static ssize_t zfcp_sysfs_port_remove_store(struct device *dev,
        list_del(&port->list);
        write_unlock_irq(&adapter->port_list_lock);
 
-       put_device(&port->dev);
-
        zfcp_erp_port_shutdown(port, 0, "syprs_1");
        device_unregister(&port->dev);
+
+       put_device(&port->dev); /* undo zfcp_get_port_by_wwpn() */
  out:
        zfcp_ccw_adapter_put(adapter);
        return retval ? retval : (ssize_t) count;
index e67bf7388cae82d5b533e9e6ff12f271754fdf32..59333f0257a8913dc8a20d6120aea8d82d8feaed 100644 (file)
@@ -255,9 +255,9 @@ int zfcp_unit_remove(struct zfcp_port *port, u64 fcp_lun)
                scsi_device_put(sdev);
        }
 
-       put_device(&unit->dev);
-
        device_unregister(&unit->dev);
 
+       put_device(&unit->dev); /* undo _zfcp_unit_find() */
+
        return 0;
 }