提交 f9e8894a 编写于 作者: A Alan Stern 提交者: James Bottomley

[SCSI] fix race in scsi_target_reap

This patch (as1357) fixes a race in SCSI target allocation and
release.  Putting a target in the STARGET_DEL state isn't protected by
the host lock, so an old target structure could be reused by a new
device even though it's about to be deleted.  The cure is to change
the state while still holding the host lock.
Signed-off-by: NAlan Stern <stern@rowland.harvard.edu>
Signed-off-by: NJames Bottomley <James.Bottomley@suse.de>
上级 8a52da63
...@@ -492,19 +492,20 @@ void scsi_target_reap(struct scsi_target *starget) ...@@ -492,19 +492,20 @@ void scsi_target_reap(struct scsi_target *starget)
struct Scsi_Host *shost = dev_to_shost(starget->dev.parent); struct Scsi_Host *shost = dev_to_shost(starget->dev.parent);
unsigned long flags; unsigned long flags;
enum scsi_target_state state; enum scsi_target_state state;
int empty; int empty = 0;
spin_lock_irqsave(shost->host_lock, flags); spin_lock_irqsave(shost->host_lock, flags);
state = starget->state; state = starget->state;
empty = --starget->reap_ref == 0 && if (--starget->reap_ref == 0 && list_empty(&starget->devices)) {
list_empty(&starget->devices) ? 1 : 0; empty = 1;
starget->state = STARGET_DEL;
}
spin_unlock_irqrestore(shost->host_lock, flags); spin_unlock_irqrestore(shost->host_lock, flags);
if (!empty) if (!empty)
return; return;
BUG_ON(state == STARGET_DEL); BUG_ON(state == STARGET_DEL);
starget->state = STARGET_DEL;
if (state == STARGET_CREATED) if (state == STARGET_CREATED)
scsi_target_destroy(starget); scsi_target_destroy(starget);
else else
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册