Skip to content

Commit e455d75

Browse files
cp890582gregkh
authored andcommitted
scsi: megaraid_sas: Target with invalid LUN ID is deleted during scan
[ Upstream commit 56495f2 ] The megaraid_sas driver supports single LUN for RAID devices. That is LUN 0. All other LUNs are unsupported. When a device scan on a logical target with invalid LUN number is invoked through sysfs, that target ends up getting removed. Add LUN ID validation in the slave destroy function to avoid the target deletion. Link: https://lore.kernel.org/r/20220324094711.48833-1-chandrakanth.patil@broadcom.com Signed-off-by: Chandrakanth patil <chandrakanth.patil@broadcom.com> Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com> Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent f1933d9 commit e455d75

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

drivers/scsi/megaraid/megaraid_sas.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2558,6 +2558,9 @@ struct megasas_instance_template {
25582558
#define MEGASAS_IS_LOGICAL(sdev) \
25592559
((sdev->channel < MEGASAS_MAX_PD_CHANNELS) ? 0 : 1)
25602560

2561+
#define MEGASAS_IS_LUN_VALID(sdev) \
2562+
(((sdev)->lun == 0) ? 1 : 0)
2563+
25612564
#define MEGASAS_DEV_INDEX(scp) \
25622565
(((scp->device->channel % 2) * MEGASAS_MAX_DEV_PER_CHANNEL) + \
25632566
scp->device->id)

drivers/scsi/megaraid/megaraid_sas_base.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2126,6 +2126,9 @@ static int megasas_slave_alloc(struct scsi_device *sdev)
21262126
goto scan_target;
21272127
}
21282128
return -ENXIO;
2129+
} else if (!MEGASAS_IS_LUN_VALID(sdev)) {
2130+
sdev_printk(KERN_INFO, sdev, "%s: invalid LUN\n", __func__);
2131+
return -ENXIO;
21292132
}
21302133

21312134
scan_target:
@@ -2156,6 +2159,10 @@ static void megasas_slave_destroy(struct scsi_device *sdev)
21562159
instance = megasas_lookup_instance(sdev->host->host_no);
21572160

21582161
if (MEGASAS_IS_LOGICAL(sdev)) {
2162+
if (!MEGASAS_IS_LUN_VALID(sdev)) {
2163+
sdev_printk(KERN_INFO, sdev, "%s: invalid LUN\n", __func__);
2164+
return;
2165+
}
21592166
ld_tgt_id = MEGASAS_TARGET_ID(sdev);
21602167
instance->ld_tgtid_status[ld_tgt_id] = LD_TARGET_ID_DELETED;
21612168
if (megasas_dbg_lvl & LD_PD_DEBUG)

0 commit comments

Comments
 (0)