Commit a6b95d1c authored by Quinn Tran's avatar Quinn Tran Committed by Martin K. Petersen

scsi: qla2xxx: Use mutex protection during qla2x00_sysfs_read_fw_dump()

Add mutex protection to prevent driver from freeing the FW dump buffer
while the extraction is in progress.

[mkp: commit desc]
Signed-off-by: default avatarQuinn Tran <quinn.tran@cavium.com>
Signed-off-by: default avatarHimanshu Madhani <hmadhani@marvell.com>
Signed-off-by: default avatarMartin K. Petersen <martin.petersen@oracle.com>
parent a4226ec3
...@@ -29,24 +29,27 @@ qla2x00_sysfs_read_fw_dump(struct file *filp, struct kobject *kobj, ...@@ -29,24 +29,27 @@ qla2x00_sysfs_read_fw_dump(struct file *filp, struct kobject *kobj,
if (!(ha->fw_dump_reading || ha->mctp_dump_reading)) if (!(ha->fw_dump_reading || ha->mctp_dump_reading))
return 0; return 0;
mutex_lock(&ha->optrom_mutex);
if (IS_P3P_TYPE(ha)) { if (IS_P3P_TYPE(ha)) {
if (off < ha->md_template_size) { if (off < ha->md_template_size) {
rval = memory_read_from_buffer(buf, count, rval = memory_read_from_buffer(buf, count,
&off, ha->md_tmplt_hdr, ha->md_template_size); &off, ha->md_tmplt_hdr, ha->md_template_size);
return rval; } else {
off -= ha->md_template_size;
rval = memory_read_from_buffer(buf, count,
&off, ha->md_dump, ha->md_dump_size);
} }
off -= ha->md_template_size; } else if (ha->mctp_dumped && ha->mctp_dump_reading) {
rval = memory_read_from_buffer(buf, count, rval = memory_read_from_buffer(buf, count, &off, ha->mctp_dump,
&off, ha->md_dump, ha->md_dump_size);
return rval;
} else if (ha->mctp_dumped && ha->mctp_dump_reading)
return memory_read_from_buffer(buf, count, &off, ha->mctp_dump,
MCTP_DUMP_SIZE); MCTP_DUMP_SIZE);
else if (ha->fw_dump_reading) } else if (ha->fw_dump_reading) {
return memory_read_from_buffer(buf, count, &off, ha->fw_dump, rval = memory_read_from_buffer(buf, count, &off, ha->fw_dump,
ha->fw_dump_len); ha->fw_dump_len);
else } else {
return 0; rval = 0;
}
mutex_unlock(&ha->optrom_mutex);
return rval;
} }
static ssize_t static ssize_t
......
...@@ -3234,6 +3234,7 @@ qla2x00_alloc_fw_dump(scsi_qla_host_t *vha) ...@@ -3234,6 +3234,7 @@ qla2x00_alloc_fw_dump(scsi_qla_host_t *vha)
"Unable to allocate (%d KB) for firmware dump.\n", "Unable to allocate (%d KB) for firmware dump.\n",
dump_size / 1024); dump_size / 1024);
} else { } else {
mutex_lock(&ha->optrom_mutex);
if (ha->fw_dumped) { if (ha->fw_dumped) {
memcpy(fw_dump, ha->fw_dump, ha->fw_dump_len); memcpy(fw_dump, ha->fw_dump, ha->fw_dump_len);
vfree(ha->fw_dump); vfree(ha->fw_dump);
...@@ -3253,8 +3254,10 @@ qla2x00_alloc_fw_dump(scsi_qla_host_t *vha) ...@@ -3253,8 +3254,10 @@ qla2x00_alloc_fw_dump(scsi_qla_host_t *vha)
"Allocated (%d KB) for firmware dump.\n", "Allocated (%d KB) for firmware dump.\n",
dump_size / 1024); dump_size / 1024);
if (IS_QLA27XX(ha) || IS_QLA28XX(ha)) if (IS_QLA27XX(ha) || IS_QLA28XX(ha)) {
mutex_unlock(&ha->optrom_mutex);
return; return;
}
ha->fw_dump->signature[0] = 'Q'; ha->fw_dump->signature[0] = 'Q';
ha->fw_dump->signature[1] = 'L'; ha->fw_dump->signature[1] = 'L';
...@@ -3277,6 +3280,7 @@ qla2x00_alloc_fw_dump(scsi_qla_host_t *vha) ...@@ -3277,6 +3280,7 @@ qla2x00_alloc_fw_dump(scsi_qla_host_t *vha)
htonl(offsetof htonl(offsetof
(struct qla2xxx_fw_dump, isp)); (struct qla2xxx_fw_dump, isp));
} }
mutex_unlock(&ha->optrom_mutex);
} }
} }
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment