[SCSI] scsi_dh: fix reference counting in scsi_dh_activate error path

Commit db422318cbca55168cf965f655471dbf8be82433 ([SCSI] scsi_dh:
propagate SCSI device deletion) introduced a regression where the device
reference is not dropped prior to scsi_dh_activate's early return from
the error path.

Signed-off-by: Mike Snitzer <snitzer@redhat.com>
Cc: stable@kernel.org # 2.6.38
Reviewed-by: Mike Christie <michaelc@cs.wisc.edu>
Signed-off-by: James Bottomley <James.Bottomley@suse.de>

authored by Mike Snitzer and committed by James Bottomley 0b839357 a1f74ae8

+6 -3
+6 -3
drivers/scsi/device_handler/scsi_dh.c
··· 394 unsigned long flags; 395 struct scsi_device *sdev; 396 struct scsi_device_handler *scsi_dh = NULL; 397 398 spin_lock_irqsave(q->queue_lock, flags); 399 sdev = q->queuedata; 400 if (sdev && sdev->scsi_dh_data) 401 scsi_dh = sdev->scsi_dh_data->scsi_dh; 402 - if (!scsi_dh || !get_device(&sdev->sdev_gendev) || 403 sdev->sdev_state == SDEV_CANCEL || 404 sdev->sdev_state == SDEV_DEL) 405 err = SCSI_DH_NOSYS; ··· 412 if (err) { 413 if (fn) 414 fn(data, err); 415 - return err; 416 } 417 418 if (scsi_dh->activate) 419 err = scsi_dh->activate(sdev, fn, data); 420 - put_device(&sdev->sdev_gendev); 421 return err; 422 } 423 EXPORT_SYMBOL_GPL(scsi_dh_activate);
··· 394 unsigned long flags; 395 struct scsi_device *sdev; 396 struct scsi_device_handler *scsi_dh = NULL; 397 + struct device *dev = NULL; 398 399 spin_lock_irqsave(q->queue_lock, flags); 400 sdev = q->queuedata; 401 if (sdev && sdev->scsi_dh_data) 402 scsi_dh = sdev->scsi_dh_data->scsi_dh; 403 + dev = get_device(&sdev->sdev_gendev); 404 + if (!scsi_dh || !dev || 405 sdev->sdev_state == SDEV_CANCEL || 406 sdev->sdev_state == SDEV_DEL) 407 err = SCSI_DH_NOSYS; ··· 410 if (err) { 411 if (fn) 412 fn(data, err); 413 + goto out; 414 } 415 416 if (scsi_dh->activate) 417 err = scsi_dh->activate(sdev, fn, data); 418 + out: 419 + put_device(dev); 420 return err; 421 } 422 EXPORT_SYMBOL_GPL(scsi_dh_activate);