1 From b65cfedf4560af65305bd7b3b9f26c02c6fb3660 Mon Sep 17 00:00:00 2001
2 From: Sreekanth Reddy <Sreekanth.Reddy@lsi.com>
3 Date: Sat, 29 Jun 2013 03:52:03 +0530
4 Subject: SCSI: mpt3sas: fix for kernel panic when driver loads with HBA conected to non LUN 0 configured expander
6 From: Sreekanth Reddy <Sreekanth.Reddy@lsi.com>
8 commit b65cfedf4560af65305bd7b3b9f26c02c6fb3660 upstream.
10 With some enclosures when LUN 0 is not created but LUN 1 or LUN X is created
11 then SCSI scan procedure calls target_alloc, slave_alloc call back functions
12 for LUN 0 and slave_destory() for same LUN 0.
14 In these kind of cases within slave_destroy, pointer to scsi_target in
15 _sas_device structure is set to NULL, following which when slave_alloc for LUN
16 1 is called then starget would not be set properly for this LUN. So,
17 scsi_target pointer pointing to NULL value would lead to a crash later in the
20 To solve this issue set the sas_device's scsi_target pointer to scsi_device's
21 scsi_target if it is NULL earlier in slave_alloc callback function.
23 Signed-off-by: Sreekanth Reddy <Sreekanth.Reddy@lsi.com>
24 Signed-off-by: James Bottomley <JBottomley@Parallels.com>
25 Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
28 drivers/scsi/mpt3sas/mpt3sas_scsih.c | 14 ++++++++++++++
29 1 file changed, 14 insertions(+)
31 --- a/drivers/scsi/mpt3sas/mpt3sas_scsih.c
32 +++ b/drivers/scsi/mpt3sas/mpt3sas_scsih.c
33 @@ -1273,6 +1273,7 @@ _scsih_slave_alloc(struct scsi_device *s
34 struct MPT3SAS_DEVICE *sas_device_priv_data;
35 struct scsi_target *starget;
36 struct _raid_device *raid_device;
37 + struct _sas_device *sas_device;
40 sas_device_priv_data = kzalloc(sizeof(struct scsi_device), GFP_KERNEL);
41 @@ -1301,6 +1302,19 @@ _scsih_slave_alloc(struct scsi_device *s
42 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
45 + if (!(sas_target_priv_data->flags & MPT_TARGET_FLAGS_VOLUME)) {
46 + spin_lock_irqsave(&ioc->sas_device_lock, flags);
47 + sas_device = mpt3sas_scsih_sas_device_find_by_sas_address(ioc,
48 + sas_target_priv_data->sas_address);
49 + if (sas_device && (sas_device->starget == NULL)) {
50 + sdev_printk(KERN_INFO, sdev,
51 + "%s : sas_device->starget set to starget @ %d\n",
52 + __func__, __LINE__);
53 + sas_device->starget = starget;
55 + spin_unlock_irqrestore(&ioc->sas_device_lock, flags);