[PATCH] scsi: hpsa: Fix pointer dereferenced before checking

From: Haowen Bai
Date: Mon May 30 2022 - 04:26:50 EST


The dev->raid_map is dereferencing before null checking, so move
it after checking.

Signed-off-by: Haowen Bai <baihaowen@xxxxxxxxx>
---
drivers/scsi/hpsa.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/scsi/hpsa.c b/drivers/scsi/hpsa.c
index a47bcce3c9c7..fa785f60b1e6 100644
--- a/drivers/scsi/hpsa.c
+++ b/drivers/scsi/hpsa.c
@@ -5104,7 +5104,7 @@ static int hpsa_scsi_ioaccel_raid_map(struct ctlr_info *h,
{
struct scsi_cmnd *cmd = c->scsi_cmd;
struct hpsa_scsi_dev_t *dev = cmd->device->hostdata;
- struct raid_map_data *map = &dev->raid_map;
+ struct raid_map_data *map;
struct raid_map_disk_data *dd = &map->data[0];
int is_write = 0;
u32 map_index;
@@ -5137,6 +5137,8 @@ static int hpsa_scsi_ioaccel_raid_map(struct ctlr_info *h,
if (!dev)
return -1;

+ map = &dev->raid_map;
+
if (dev->in_reset)
return -1;

--
2.7.4