scsi: qla2xxx: Use mutex protection during qla2x00_sysfs_read_fw_dump()
authorQuinn Tran <quinn.tran@cavium.com>
Tue, 2 Apr 2019 21:24:28 +0000 (14:24 -0700)
committerMartin K. Petersen <martin.petersen@oracle.com>
Thu, 4 Apr 2019 03:45:58 +0000 (23:45 -0400)
Add mutex protection to prevent driver from freeing the FW dump buffer
while the extraction is in progress.

[mkp: commit desc]

Signed-off-by: Quinn Tran <quinn.tran@cavium.com>
Signed-off-by: Himanshu Madhani <hmadhani@marvell.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
drivers/scsi/qla2xxx/qla_attr.c
drivers/scsi/qla2xxx/qla_init.c

index b2520e49971d4729cac2868fa9d80da0cf38217a..da64fe54f59e8cc0836c76074cae9bfddf8fa0f7 100644 (file)
@@ -29,24 +29,27 @@ qla2x00_sysfs_read_fw_dump(struct file *filp, struct kobject *kobj,
        if (!(ha->fw_dump_reading || ha->mctp_dump_reading))
                return 0;
 
+       mutex_lock(&ha->optrom_mutex);
        if (IS_P3P_TYPE(ha)) {
                if (off < ha->md_template_size) {
                        rval = memory_read_from_buffer(buf, count,
                            &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;
-               rval = memory_read_from_buffer(buf, count,
-                   &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,
+       } else if (ha->mctp_dumped && ha->mctp_dump_reading) {
+               rval = memory_read_from_buffer(buf, count, &off, ha->mctp_dump,
                    MCTP_DUMP_SIZE);
-       else if (ha->fw_dump_reading)
-               return memory_read_from_buffer(buf, count, &off, ha->fw_dump,
+       } else if (ha->fw_dump_reading) {
+               rval = memory_read_from_buffer(buf, count, &off, ha->fw_dump,
                                        ha->fw_dump_len);
-       else
-               return 0;
+       } else {
+               rval = 0;
+       }
+       mutex_unlock(&ha->optrom_mutex);
+       return rval;
 }
 
 static ssize_t
index 8183de0bd626729279092aba0ce748e10fa604bb..61dddeee75a0a0de065cf5d997117568bcdc55dd 100644 (file)
@@ -3234,6 +3234,7 @@ allocate:
                            "Unable to allocate (%d KB) for firmware dump.\n",
                            dump_size / 1024);
                } else {
+                       mutex_lock(&ha->optrom_mutex);
                        if (ha->fw_dumped) {
                                memcpy(fw_dump, ha->fw_dump, ha->fw_dump_len);
                                vfree(ha->fw_dump);
@@ -3253,8 +3254,10 @@ allocate:
                                    "Allocated (%d KB) for firmware dump.\n",
                                    dump_size / 1024);
 
-                               if (IS_QLA27XX(ha) || IS_QLA28XX(ha))
+                               if (IS_QLA27XX(ha) || IS_QLA28XX(ha)) {
+                                       mutex_unlock(&ha->optrom_mutex);
                                        return;
+                               }
 
                                ha->fw_dump->signature[0] = 'Q';
                                ha->fw_dump->signature[1] = 'L';
@@ -3277,6 +3280,7 @@ allocate:
                                        htonl(offsetof
                                            (struct qla2xxx_fw_dump, isp));
                        }
+                       mutex_unlock(&ha->optrom_mutex);
                }
        }
 }