Since scsi_target_block() can fail, return a value that indicates whether
or not this function succeeded.

Cc: Christoph Hellwig <[email protected]>
Cc: Hannes Reinecke <[email protected]>
Cc: Johannes Thumshirn <[email protected]>
Cc: Ming Lei <[email protected]>
Signed-off-by: Bart Van Assche <[email protected]>
---
 drivers/scsi/scsi_lib.c    | 24 +++++++++++++++++-------
 include/scsi/scsi_device.h |  2 +-
 2 files changed, 18 insertions(+), 8 deletions(-)

diff --git a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c
index 497cd4799e0a..bbed72eff9c9 100644
--- a/drivers/scsi/scsi_lib.c
+++ b/drivers/scsi/scsi_lib.c
@@ -2741,26 +2741,36 @@ static int scsi_internal_device_unblock(struct 
scsi_device *sdev,
 static void
 device_block(struct scsi_device *sdev, void *data)
 {
-       scsi_internal_device_block(sdev);
+       int ret, *retp = data;
+
+       ret = scsi_internal_device_block(sdev);
+       if (*retp == 0 && ret != 0)
+               *retp = ret;
 }
 
 static int
 target_block(struct device *dev, void *data)
 {
+       int *retp = data;
+
        if (scsi_is_target_device(dev))
-               starget_for_each_device(to_scsi_target(dev), NULL,
+               starget_for_each_device(to_scsi_target(dev), data,
                                        device_block);
-       return 0;
+
+       return *retp;
 }
 
-void
-scsi_target_block(struct device *dev)
+int scsi_target_block(struct device *dev)
 {
+       int ret = 0;
+
        if (scsi_is_target_device(dev))
-               starget_for_each_device(to_scsi_target(dev), NULL,
+               starget_for_each_device(to_scsi_target(dev), &ret,
                                        device_block);
        else
-               device_for_each_child(dev, NULL, target_block);
+               device_for_each_child(dev, &ret, target_block);
+
+       return ret;
 }
 EXPORT_SYMBOL_GPL(scsi_target_block);
 
diff --git a/include/scsi/scsi_device.h b/include/scsi/scsi_device.h
index 202f4d6a4342..e5d24abd292d 100644
--- a/include/scsi/scsi_device.h
+++ b/include/scsi/scsi_device.h
@@ -421,7 +421,7 @@ extern void scsi_scan_target(struct device *parent, 
unsigned int channel,
                             unsigned int id, u64 lun,
                             enum scsi_scan_mode rescan);
 extern void scsi_target_reap(struct scsi_target *);
-extern void scsi_target_block(struct device *);
+extern int scsi_target_block(struct device *);
 extern void scsi_target_unblock(struct device *, enum scsi_device_state);
 extern void scsi_remove_target(struct device *);
 extern const char *scsi_device_state_name(enum scsi_device_state);
-- 
2.22.0.709.g102302147b-goog

Reply via email to