scsi: core: Improve type safety of scsi_rescan_device()
authorBart Van Assche <bvanassche@acm.org>
Tue, 22 Aug 2023 15:30:41 +0000 (08:30 -0700)
committerMartin K. Petersen <martin.petersen@oracle.com>
Fri, 25 Aug 2023 02:11:29 +0000 (22:11 -0400)
Most callers of scsi_rescan_device() have the scsi_device pointer readily
available. Pass a struct scsi_device pointer to scsi_rescan_device()
instead of a struct device pointer. This change prevents that a pointer to
another struct device would be passed accidentally to scsi_rescan_device().

Remove the scsi_rescan_device() declaration from the scsi_priv.h header
file since it duplicates the declaration in <scsi/scsi_host.h>.

Reviewed-by: Hannes Reinecke <hare@suse.de>
Reviewed-by: Damien Le Moal <damien.lemoal@opensource.wdc.com>
Reviewed-by: John Garry <john.g.garry@oracle.com>
Cc: Mike Christie <michael.christie@oracle.com>
Cc: Ming Lei <ming.lei@redhat.com>
Signed-off-by: Bart Van Assche <bvanassche@acm.org>
Link: https://lore.kernel.org/r/20230822153043.4046244-1-bvanassche@acm.org
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
drivers/ata/libata-scsi.c
drivers/scsi/aacraid/commsup.c
drivers/scsi/mvumi.c
drivers/scsi/scsi_lib.c
drivers/scsi/scsi_priv.h
drivers/scsi/scsi_scan.c
drivers/scsi/scsi_sysfs.c
drivers/scsi/smartpqi/smartpqi_init.c
drivers/scsi/storvsc_drv.c
drivers/scsi/virtio_scsi.c
include/scsi/scsi_host.h

index 370d18aca71e87653339e53002a7326812693665..f5c36c8c243a9a054fc25c27dc81e73c3c294fd5 100644 (file)
@@ -4884,7 +4884,7 @@ void ata_scsi_dev_rescan(struct work_struct *work)
                        }
 
                        spin_unlock_irqrestore(ap->lock, flags);
-                       scsi_rescan_device(&(sdev->sdev_gendev));
+                       scsi_rescan_device(sdev);
                        scsi_device_put(sdev);
                        spin_lock_irqsave(ap->lock, flags);
                }
index 3f062e4013ab6c3b9cb54e46f608bee974b5e9a1..013a9a334972ebd3b8578d83c19639627cd8b38d 100644 (file)
@@ -1451,7 +1451,7 @@ retry_next:
 #endif
                                break;
                        }
-                       scsi_rescan_device(&device->sdev_gendev);
+                       scsi_rescan_device(device);
                        break;
 
                default:
index 97f9d2fa64294e9295c7c47fdd2fd12725b1da18..d9d366ec17dc975a9890ecf6441d7c9837e226e0 100644 (file)
@@ -1500,7 +1500,7 @@ static void mvumi_rescan_devices(struct mvumi_hba *mhba, int id)
 
        sdev = scsi_device_lookup(mhba->shost, 0, id, 0);
        if (sdev) {
-               scsi_rescan_device(&sdev->sdev_gendev);
+               scsi_rescan_device(sdev);
                scsi_device_put(sdev);
        }
 }
index ad9afae49544ab66019655c424ede12471656b01..ca5eb058d5c7e69cb47b78518ab450769df3889c 100644 (file)
@@ -2458,7 +2458,7 @@ static void scsi_evt_emit(struct scsi_device *sdev, struct scsi_event *evt)
                envp[idx++] = "SDEV_MEDIA_CHANGE=1";
                break;
        case SDEV_EVT_INQUIRY_CHANGE_REPORTED:
-               scsi_rescan_device(&sdev->sdev_gendev);
+               scsi_rescan_device(sdev);
                envp[idx++] = "SDEV_UA=INQUIRY_DATA_HAS_CHANGED";
                break;
        case SDEV_EVT_CAPACITY_CHANGE_REPORTED:
index 118855576ca86348228575187def0069a0efe75b..3f0dfb97db6bd1b88755db1fb50dd6e968e385c6 100644 (file)
@@ -137,7 +137,6 @@ extern int scsi_complete_async_scans(void);
 extern int scsi_scan_host_selected(struct Scsi_Host *, unsigned int,
                                   unsigned int, u64, enum scsi_scan_mode);
 extern void scsi_forget_host(struct Scsi_Host *);
-extern void scsi_rescan_device(struct device *);
 
 /* scsi_sysctl.c */
 #ifdef CONFIG_SYSCTL
index aa13feb17c62605a15379cae725514acf2a8a09c..52014b2d39e1c5d41dc3be4e491f4280bf2f7f2a 100644 (file)
@@ -1619,9 +1619,9 @@ int scsi_add_device(struct Scsi_Host *host, uint channel,
 }
 EXPORT_SYMBOL(scsi_add_device);
 
-void scsi_rescan_device(struct device *dev)
+void scsi_rescan_device(struct scsi_device *sdev)
 {
-       struct scsi_device *sdev = to_scsi_device(dev);
+       struct device *dev = &sdev->sdev_gendev;
 
        device_lock(dev);
 
index 60317676e45f19bf7328d84422cb7f5f079bcb13..24f6eefb68030d39869934e6fbefc9fce11d640b 100644 (file)
@@ -747,7 +747,7 @@ static ssize_t
 store_rescan_field (struct device *dev, struct device_attribute *attr,
                    const char *buf, size_t count)
 {
-       scsi_rescan_device(dev);
+       scsi_rescan_device(to_scsi_device(dev));
        return count;
 }
 static DEVICE_ATTR(rescan, S_IWUSR, NULL, store_rescan_field);
@@ -840,7 +840,7 @@ store_state_field(struct device *dev, struct device_attribute *attr,
                 * waiting for pending I/O to finish.
                 */
                blk_mq_run_hw_queues(sdev->request_queue, true);
-               scsi_rescan_device(dev);
+               scsi_rescan_device(sdev);
        }
 
        return ret == 0 ? count : -EINVAL;
index 6aaaa7ebca377bf4f1fb50b4bdd8f0d3e8924b34..ed694d93996486d3966628198520b56aa6c5025c 100644 (file)
@@ -2257,7 +2257,7 @@ static void pqi_update_device_list(struct pqi_ctrl_info *ctrl_info,
                        device->advertised_queue_depth = device->queue_depth;
                        scsi_change_queue_depth(device->sdev, device->advertised_queue_depth);
                        if (device->rescan) {
-                               scsi_rescan_device(&device->sdev->sdev_gendev);
+                               scsi_rescan_device(device->sdev);
                                device->rescan = false;
                        }
                }
index 659196a2f63ad33d3f16e9cb0e26449e78ef46a9..6bfd88495edb7092d034e75d0ee23f9f96f5687d 100644 (file)
@@ -470,7 +470,7 @@ static void storvsc_device_scan(struct work_struct *work)
        sdev = scsi_device_lookup(wrk->host, 0, wrk->tgt_id, wrk->lun);
        if (!sdev)
                goto done;
-       scsi_rescan_device(&sdev->sdev_gendev);
+       scsi_rescan_device(sdev);
        scsi_device_put(sdev);
 
 done:
index bd5633667d01567cd408475f3f9c3c27a98a197e..9d1bdcdc13312988b2ee052c3736bb548f21ffba 100644 (file)
@@ -325,7 +325,7 @@ static void virtscsi_handle_param_change(struct virtio_scsi *vscsi,
        /* Handle "Parameters changed", "Mode parameters changed", and
           "Capacity data has changed".  */
        if (asc == 0x2a && (ascq == 0x00 || ascq == 0x01 || ascq == 0x09))
-               scsi_rescan_device(&sdev->sdev_gendev);
+               scsi_rescan_device(sdev);
 
        scsi_device_put(sdev);
 }
index a2b8d30c4c8032160751bac3239a98dcd77aadb1..49f768d0ff370b3f7aa67666b1f75444e55f1ee3 100644 (file)
@@ -764,7 +764,7 @@ scsi_template_proc_dir(const struct scsi_host_template *sht);
 #define scsi_template_proc_dir(sht) NULL
 #endif
 extern void scsi_scan_host(struct Scsi_Host *);
-extern void scsi_rescan_device(struct device *);
+extern void scsi_rescan_device(struct scsi_device *);
 extern void scsi_remove_host(struct Scsi_Host *);
 extern struct Scsi_Host *scsi_host_get(struct Scsi_Host *);
 extern int scsi_host_busy(struct Scsi_Host *shost);