scsi_scan() removes existing SCSI block devices before rescanning, which can invalidate existing references and requires callers to avoid redundant scans.
Add scsi_scan_new() to scan only controllers without bound block devices, making repeated scans safe and eliminating the need for scan guards at individual call sites. Signed-off-by: Aswin Murugan <[email protected]> --- drivers/scsi/scsi.c | 27 +++++++++++++++++++++++++++ include/scsi.h | 8 ++++++++ 2 files changed, 35 insertions(+) diff --git a/drivers/scsi/scsi.c b/drivers/scsi/scsi.c index 50e7d749921..736dccfcbff 100644 --- a/drivers/scsi/scsi.c +++ b/drivers/scsi/scsi.c @@ -673,6 +673,33 @@ int scsi_scan(bool verbose) return 0; } +int scsi_scan_new(bool verbose) +{ + struct uclass *uc; + struct udevice *dev; + int ret; + + if (verbose) + printf("scanning bus for devices...\n"); + + ret = uclass_get(UCLASS_SCSI, &uc); + if (ret) + return ret; + + uclass_foreach_dev(dev, uc) { + struct udevice *blk; + + if (device_find_first_child_by_uclass(dev, UCLASS_BLK, &blk) == 0) + continue; + + ret = scsi_scan_dev(dev, verbose); + if (ret) + return ret; + } + + return 0; +} + static const struct blk_ops scsi_blk_ops = { .read = scsi_read, .write = scsi_write, diff --git a/include/scsi.h b/include/scsi.h index 2520a8b8fe6..a7770029c6b 100644 --- a/include/scsi.h +++ b/include/scsi.h @@ -344,6 +344,14 @@ int scsi_bus_reset(struct udevice *dev); */ int scsi_scan(bool verbose); +/** + * scsi_scan_new() - Scan all SCSI controllers for new devices + * + * @verbose: true to show information about each device found + * Return: 0 if OK, -ve on error + */ +int scsi_scan_new(bool verbose); + /** * scsi_scan_dev() - scan a SCSI bus and create devices * -- 2.34.1
