Skip to content

Commit 9f21316

Browse files
Joe LawrenceChristoph Hellwig
authored andcommitted
mptfusion: tweak null pointer checks
Fixes the following smatch warnings: drivers/message/fusion/mptbase.c:652 mptbase_reply() warn: variable dereferenced before check 'reply' (see line 639) [JL: No-brainer, the enclosing switch statement dereferences reply, so we can't get here unless reply is valid.] drivers/message/fusion/mptsas.c:1255 mptsas_taskmgmt_complete() error: we previously assumed 'pScsiTmReply' could be null (see line 1227) [HCH: Reading the code in mptsas_taskmgmt_complete it's pretty obvious that it can't do anything useful if mr/pScsiTmReply are NULL, so I suspect it would be best to just return at the beginning of the function. I'd love to understand if it actually could ever be zero, which I doubt. Maybe the LSI people can shed some light on that?] drivers/message/fusion/mptsas.c:3888 mptsas_not_responding_devices() error: we previously assumed 'port_info->phy_info' could be null (see line 3875) [HCH: It's pretty obvious from reading mptsas_sas_io_unit_pg0 that we never register a port_info with a NULL phy_info in the lists, so all NULL checks on it could be deleted.] drivers/message/fusion/mptscsih.c:1284 mptscsih_info() error: we previously assumed 'h' could be null (see line 1274) [HCH: shost_priv can't return NULL, so the if (h) should be removed.] drivers/message/fusion/mptscsih.c:1388 mptscsih_qcmd() error: we previously assumed 'vdevice' could be null (see line 1373) [HCH: vdevice can't ever be NULL here, it's allocated in ->slave_alloc and thus guaranteed to be around when ->queuecommand is called.] Signed-off-by: Joe Lawrence <joe.lawrence@stratus.com> Acked-by: Sreekanth Reddy <Sreekanth.Reddy@avagotech.com> Signed-off-by: Christoph Hellwig <hch@lst.de>
1 parent 3269619 commit 9f21316

3 files changed

Lines changed: 37 additions & 44 deletions

File tree

‎drivers/message/fusion/mptbase.c‎

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -649,12 +649,10 @@ mptbase_reply(MPT_ADAPTER *ioc, MPT_FRAME_HDR *req, MPT_FRAME_HDR *reply)
649649
case MPI_FUNCTION_CONFIG:
650650
case MPI_FUNCTION_SAS_IO_UNIT_CONTROL:
651651
ioc->mptbase_cmds.status |= MPT_MGMT_STATUS_COMMAND_GOOD;
652-
if (reply) {
653-
ioc->mptbase_cmds.status |= MPT_MGMT_STATUS_RF_VALID;
654-
memcpy(ioc->mptbase_cmds.reply, reply,
655-
min(MPT_DEFAULT_FRAME_SIZE,
656-
4 * reply->u.reply.MsgLength));
657-
}
652+
ioc->mptbase_cmds.status |= MPT_MGMT_STATUS_RF_VALID;
653+
memcpy(ioc->mptbase_cmds.reply, reply,
654+
min(MPT_DEFAULT_FRAME_SIZE,
655+
4 * reply->u.reply.MsgLength));
658656
if (ioc->mptbase_cmds.status & MPT_MGMT_STATUS_PENDING) {
659657
ioc->mptbase_cmds.status &= ~MPT_MGMT_STATUS_PENDING;
660658
complete(&ioc->mptbase_cmds.done);

‎drivers/message/fusion/mptsas.c‎

Lines changed: 25 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1203,27 +1203,28 @@ mptsas_taskmgmt_complete(MPT_ADAPTER *ioc, MPT_FRAME_HDR *mf, MPT_FRAME_HDR *mr)
12031203
"(mf = %p, mr = %p)\n", ioc->name, mf, mr));
12041204

12051205
pScsiTmReply = (SCSITaskMgmtReply_t *)mr;
1206-
if (pScsiTmReply) {
1207-
dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT
1208-
"\tTaskMgmt completed: fw_channel = %d, fw_id = %d,\n"
1209-
"\ttask_type = 0x%02X, iocstatus = 0x%04X "
1210-
"loginfo = 0x%08X,\n\tresponse_code = 0x%02X, "
1211-
"term_cmnds = %d\n", ioc->name,
1212-
pScsiTmReply->Bus, pScsiTmReply->TargetID,
1213-
pScsiTmReply->TaskType,
1214-
le16_to_cpu(pScsiTmReply->IOCStatus),
1215-
le32_to_cpu(pScsiTmReply->IOCLogInfo),
1216-
pScsiTmReply->ResponseCode,
1217-
le32_to_cpu(pScsiTmReply->TerminationCount)));
1218-
1219-
if (pScsiTmReply->ResponseCode)
1220-
mptscsih_taskmgmt_response_code(ioc,
1221-
pScsiTmReply->ResponseCode);
1222-
}
1223-
1224-
if (pScsiTmReply && (pScsiTmReply->TaskType ==
1206+
if (!pScsiTmReply)
1207+
return 0;
1208+
1209+
dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT
1210+
"\tTaskMgmt completed: fw_channel = %d, fw_id = %d,\n"
1211+
"\ttask_type = 0x%02X, iocstatus = 0x%04X "
1212+
"loginfo = 0x%08X,\n\tresponse_code = 0x%02X, "
1213+
"term_cmnds = %d\n", ioc->name,
1214+
pScsiTmReply->Bus, pScsiTmReply->TargetID,
1215+
pScsiTmReply->TaskType,
1216+
le16_to_cpu(pScsiTmReply->IOCStatus),
1217+
le32_to_cpu(pScsiTmReply->IOCLogInfo),
1218+
pScsiTmReply->ResponseCode,
1219+
le32_to_cpu(pScsiTmReply->TerminationCount)));
1220+
1221+
if (pScsiTmReply->ResponseCode)
1222+
mptscsih_taskmgmt_response_code(ioc,
1223+
pScsiTmReply->ResponseCode);
1224+
1225+
if (pScsiTmReply->TaskType ==
12251226
MPI_SCSITASKMGMT_TASKTYPE_QUERY_TASK || pScsiTmReply->TaskType ==
1226-
MPI_SCSITASKMGMT_TASKTYPE_ABRT_TASK_SET)) {
1227+
MPI_SCSITASKMGMT_TASKTYPE_ABRT_TASK_SET) {
12271228
ioc->taskmgmt_cmds.status |= MPT_MGMT_STATUS_COMMAND_GOOD;
12281229
ioc->taskmgmt_cmds.status |= MPT_MGMT_STATUS_RF_VALID;
12291230
memcpy(ioc->taskmgmt_cmds.reply, mr,
@@ -3853,10 +3854,8 @@ mptsas_not_responding_devices(MPT_ADAPTER *ioc)
38533854
phy_info = mptsas_find_phyinfo_by_sas_address(ioc,
38543855
sas_info->sas_address);
38553856

3856-
if (phy_info) {
3857-
mptsas_del_end_device(ioc, phy_info);
3858-
goto redo_device_scan;
3859-
}
3857+
mptsas_del_end_device(ioc, phy_info);
3858+
goto redo_device_scan;
38603859
} else
38613860
mptsas_volume_delete(ioc, sas_info->fw.id);
38623861
}
@@ -3867,9 +3866,8 @@ mptsas_not_responding_devices(MPT_ADAPTER *ioc)
38673866
redo_expander_scan:
38683867
list_for_each_entry(port_info, &ioc->sas_topology, list) {
38693868

3870-
if (port_info->phy_info &&
3871-
(!(port_info->phy_info[0].identify.device_info &
3872-
MPI_SAS_DEVICE_INFO_SMP_TARGET)))
3869+
if (!(port_info->phy_info[0].identify.device_info &
3870+
MPI_SAS_DEVICE_INFO_SMP_TARGET))
38733871
continue;
38743872
found_expander = 0;
38753873
handle = 0xFFFF;

‎drivers/message/fusion/mptscsih.c‎

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1271,15 +1271,13 @@ mptscsih_info(struct Scsi_Host *SChost)
12711271

12721272
h = shost_priv(SChost);
12731273

1274-
if (h) {
1275-
if (h->info_kbuf == NULL)
1276-
if ((h->info_kbuf = kmalloc(0x1000 /* 4Kb */, GFP_KERNEL)) == NULL)
1277-
return h->info_kbuf;
1278-
h->info_kbuf[0] = '\0';
1279-
1280-
mpt_print_ioc_summary(h->ioc, h->info_kbuf, &size, 0, 0);
1281-
h->info_kbuf[size-1] = '\0';
1282-
}
1274+
if (h->info_kbuf == NULL)
1275+
if ((h->info_kbuf = kmalloc(0x1000 /* 4Kb */, GFP_KERNEL)) == NULL)
1276+
return h->info_kbuf;
1277+
h->info_kbuf[0] = '\0';
1278+
1279+
mpt_print_ioc_summary(h->ioc, h->info_kbuf, &size, 0, 0);
1280+
h->info_kbuf[size-1] = '\0';
12831281

12841282
return h->info_kbuf;
12851283
}
@@ -1368,8 +1366,7 @@ mptscsih_qcmd(struct scsi_cmnd *SCpnt)
13681366
/* Default to untagged. Once a target structure has been allocated,
13691367
* use the Inquiry data to determine if device supports tagged.
13701368
*/
1371-
if (vdevice
1372-
&& (vdevice->vtarget->tflags & MPT_TARGET_FLAGS_Q_YES)
1369+
if ((vdevice->vtarget->tflags & MPT_TARGET_FLAGS_Q_YES)
13731370
&& (SCpnt->device->tagged_supported)) {
13741371
scsictl = scsidir | MPI_SCSIIO_CONTROL_SIMPLEQ;
13751372
if (SCpnt->request && SCpnt->request->ioprio) {

0 commit comments

Comments
 (0)