When evaluating the target port group state we might race with device removal, causing the code to iterate over sdevs which have been removed. This situation doesn't warrant a BUG_ON() statement as we can easily recover from here. So replace the BUG_ON() with a simple 'if' condition. Reported-by: Brian Bunker <brian@xxxxxxxxxxxxxxx> Signed-off-by: Hannes Reinecke <hare@xxxxxxx> --- drivers/scsi/device_handler/scsi_dh_alua.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/drivers/scsi/device_handler/scsi_dh_alua.c b/drivers/scsi/device_handler/scsi_dh_alua.c index f32da0ca529e..e97b1d1ea123 100644 --- a/drivers/scsi/device_handler/scsi_dh_alua.c +++ b/drivers/scsi/device_handler/scsi_dh_alua.c @@ -659,7 +659,8 @@ static int alua_rtpg(struct scsi_device *sdev, struct alua_port_group *pg) list_for_each_entry_rcu(h, &tmp_pg->dh_list, node) { /* h->sdev should always be valid */ - BUG_ON(!h->sdev); + if (!h->sdev) + continue; h->sdev->access_state = desc[0]; } rcu_read_unlock(); @@ -705,7 +706,8 @@ static int alua_rtpg(struct scsi_device *sdev, struct alua_port_group *pg) pg->expiry = 0; rcu_read_lock(); list_for_each_entry_rcu(h, &pg->dh_list, node) { - BUG_ON(!h->sdev); + if (!h->sdev) + continue; h->sdev->access_state = (pg->state & SCSI_ACCESS_STATE_MASK); if (pg->pref) -- 2.26.2