Re: [PATCH] scsi: core: Fix missing lock when read async_scan in Scsi_Host
From: Bart Van Assche
Date: Mon Mar 02 2026 - 09:40:04 EST
On 3/2/26 4:13 AM, Chaohai Chen wrote:
+static bool scsi_test_async_scan(struct Scsi_Host *shost)
+{
+ bool async;
+ unsigned long flags;
+
+ lockdep_assert_not_held(shost->host_lock);
+
+ spin_lock_irqsave(shost->host_lock, flags);
+ async = shost->async_scan;
+ spin_unlock_irqrestore(shost->host_lock, flags);
+
+ return async;
+}
Please use scoped_guard(), e.g. as follows:
static bool scsi_scan_async(struct Scsi_Host *shost)
{
scoped_guard(spinlock_irqsave, shost->host_lock)
return shost->async_scan;
}
+static void scsi_set_async_scan(struct Scsi_Host *shost)Please drop the scsi_set_async_scan() and scsi_clear_async_scan()
+{
+ unsigned long flags;
+
+ lockdep_assert_not_held(shost->host_lock);
+
+ spin_lock_irqsave(shost->host_lock, flags);
+ shost->async_scan = 1;
+ spin_unlock_irqrestore(shost->host_lock, flags);
+}
+
+static void scsi_clear_async_scan(struct Scsi_Host *shost)
+{
+ unsigned long flags;
+
+ lockdep_assert_not_held(shost->host_lock);
+
+ spin_lock_irqsave(shost->host_lock, flags);
+ shost->async_scan = 0;
+ spin_unlock_irqrestore(shost->host_lock, flags);
+}
functions since these only have one caller.
Thanks,
Bart.