Commit dc6d6d34 authored by Bart Van Assche's avatar Bart Van Assche Committed by Martin K. Petersen

scsi: qla2xxx: Check the PCI info string output buffer size

Pass the output buffer size to the code that generates a PCI info string
and check the output buffer size while generating a PCI info string.

Cc: Himanshu Madhani <hmadhani@marvell.com>
Signed-off-by: default avatarBart Van Assche <bvanassche@acm.org>
Tested-by: default avatarHimanshu Madhani <hmadhani@marvell.com>
Reviewed-by: default avatarHimanshu Madhani <hmadhani@marvell.com>
Signed-off-by: default avatarMartin K. Petersen <martin.petersen@oracle.com>
parent fcef0893
...@@ -1125,7 +1125,8 @@ qla2x00_pci_info_show(struct device *dev, struct device_attribute *attr, ...@@ -1125,7 +1125,8 @@ qla2x00_pci_info_show(struct device *dev, struct device_attribute *attr,
char pci_info[30]; char pci_info[30];
return scnprintf(buf, PAGE_SIZE, "%s\n", return scnprintf(buf, PAGE_SIZE, "%s\n",
vha->hw->isp_ops->pci_info_str(vha, pci_info)); vha->hw->isp_ops->pci_info_str(vha, pci_info,
sizeof(pci_info)));
} }
static ssize_t static ssize_t
......
...@@ -3112,7 +3112,7 @@ struct isp_operations { ...@@ -3112,7 +3112,7 @@ struct isp_operations {
void (*update_fw_options) (struct scsi_qla_host *); void (*update_fw_options) (struct scsi_qla_host *);
int (*load_risc) (struct scsi_qla_host *, uint32_t *); int (*load_risc) (struct scsi_qla_host *, uint32_t *);
char * (*pci_info_str) (struct scsi_qla_host *, char *); char * (*pci_info_str)(struct scsi_qla_host *, char *, size_t);
char * (*fw_version_str)(struct scsi_qla_host *, char *, size_t); char * (*fw_version_str)(struct scsi_qla_host *, char *, size_t);
irq_handler_t intr_handler; irq_handler_t intr_handler;
......
...@@ -732,7 +732,7 @@ extern int qlafx00_initialize_adapter(struct scsi_qla_host *); ...@@ -732,7 +732,7 @@ extern int qlafx00_initialize_adapter(struct scsi_qla_host *);
extern int qlafx00_soft_reset(scsi_qla_host_t *); extern int qlafx00_soft_reset(scsi_qla_host_t *);
extern int qlafx00_chip_diag(scsi_qla_host_t *); extern int qlafx00_chip_diag(scsi_qla_host_t *);
extern void qlafx00_config_rings(struct scsi_qla_host *); extern void qlafx00_config_rings(struct scsi_qla_host *);
extern char *qlafx00_pci_info_str(struct scsi_qla_host *, char *); extern char *qlafx00_pci_info_str(struct scsi_qla_host *, char *, size_t);
extern char *qlafx00_fw_version_str(struct scsi_qla_host *, char *, size_t); extern char *qlafx00_fw_version_str(struct scsi_qla_host *, char *, size_t);
extern irqreturn_t qlafx00_intr_handler(int, void *); extern irqreturn_t qlafx00_intr_handler(int, void *);
extern void qlafx00_enable_intrs(struct qla_hw_data *); extern void qlafx00_enable_intrs(struct qla_hw_data *);
......
...@@ -688,14 +688,12 @@ qlafx00_config_rings(struct scsi_qla_host *vha) ...@@ -688,14 +688,12 @@ qlafx00_config_rings(struct scsi_qla_host *vha)
} }
char * char *
qlafx00_pci_info_str(struct scsi_qla_host *vha, char *str) qlafx00_pci_info_str(struct scsi_qla_host *vha, char *str, size_t str_len)
{ {
struct qla_hw_data *ha = vha->hw; struct qla_hw_data *ha = vha->hw;
if (pci_is_pcie(ha->pdev)) { if (pci_is_pcie(ha->pdev))
strcpy(str, "PCIe iSA"); strlcpy(str, "PCIe iSA", str_len);
return str;
}
return str; return str;
} }
......
...@@ -536,80 +536,70 @@ static void qla2x00_free_queues(struct qla_hw_data *ha) ...@@ -536,80 +536,70 @@ static void qla2x00_free_queues(struct qla_hw_data *ha)
} }
static char * static char *
qla2x00_pci_info_str(struct scsi_qla_host *vha, char *str) qla2x00_pci_info_str(struct scsi_qla_host *vha, char *str, size_t str_len)
{ {
struct qla_hw_data *ha = vha->hw; struct qla_hw_data *ha = vha->hw;
static char *pci_bus_modes[] = { static const char *const pci_bus_modes[] = {
"33", "66", "100", "133", "33", "66", "100", "133",
}; };
uint16_t pci_bus; uint16_t pci_bus;
strcpy(str, "PCI");
pci_bus = (ha->pci_attr & (BIT_9 | BIT_10)) >> 9; pci_bus = (ha->pci_attr & (BIT_9 | BIT_10)) >> 9;
if (pci_bus) { if (pci_bus) {
strcat(str, "-X ("); snprintf(str, str_len, "PCI-X (%s MHz)",
strcat(str, pci_bus_modes[pci_bus]); pci_bus_modes[pci_bus]);
} else { } else {
pci_bus = (ha->pci_attr & BIT_8) >> 8; pci_bus = (ha->pci_attr & BIT_8) >> 8;
strcat(str, " ("); snprintf(str, str_len, "PCI (%s MHz)", pci_bus_modes[pci_bus]);
strcat(str, pci_bus_modes[pci_bus]);
} }
strcat(str, " MHz)");
return (str); return str;
} }
static char * static char *
qla24xx_pci_info_str(struct scsi_qla_host *vha, char *str) qla24xx_pci_info_str(struct scsi_qla_host *vha, char *str, size_t str_len)
{ {
static char *pci_bus_modes[] = { "33", "66", "100", "133", }; static const char *const pci_bus_modes[] = {
"33", "66", "100", "133",
};
struct qla_hw_data *ha = vha->hw; struct qla_hw_data *ha = vha->hw;
uint32_t pci_bus; uint32_t pci_bus;
if (pci_is_pcie(ha->pdev)) { if (pci_is_pcie(ha->pdev)) {
char lwstr[6];
uint32_t lstat, lspeed, lwidth; uint32_t lstat, lspeed, lwidth;
const char *speed_str;
pcie_capability_read_dword(ha->pdev, PCI_EXP_LNKCAP, &lstat); pcie_capability_read_dword(ha->pdev, PCI_EXP_LNKCAP, &lstat);
lspeed = lstat & PCI_EXP_LNKCAP_SLS; lspeed = lstat & PCI_EXP_LNKCAP_SLS;
lwidth = (lstat & PCI_EXP_LNKCAP_MLW) >> 4; lwidth = (lstat & PCI_EXP_LNKCAP_MLW) >> 4;
strcpy(str, "PCIe (");
switch (lspeed) { switch (lspeed) {
case 1: case 1:
strcat(str, "2.5GT/s "); speed_str = "2.5GT/s";
break; break;
case 2: case 2:
strcat(str, "5.0GT/s "); speed_str = "5.0GT/s";
break; break;
case 3: case 3:
strcat(str, "8.0GT/s "); speed_str = "8.0GT/s";
break; break;
default: default:
strcat(str, "<unknown> "); speed_str = "<unknown>";
break; break;
} }
snprintf(lwstr, sizeof(lwstr), "x%d)", lwidth); snprintf(str, str_len, "PCIe (%s x%d)", speed_str, lwidth);
strcat(str, lwstr);
return str; return str;
} }
strcpy(str, "PCI");
pci_bus = (ha->pci_attr & CSRX_PCIX_BUS_MODE_MASK) >> 8; pci_bus = (ha->pci_attr & CSRX_PCIX_BUS_MODE_MASK) >> 8;
if (pci_bus == 0 || pci_bus == 8) { if (pci_bus == 0 || pci_bus == 8)
strcat(str, " ("); snprintf(str, str_len, "PCI (%s MHz)",
strcat(str, pci_bus_modes[pci_bus >> 3]); pci_bus_modes[pci_bus >> 3]);
} else { else
strcat(str, "-X "); snprintf(str, str_len, "PCI-X Mode %d (%s MHz)",
if (pci_bus & BIT_2) pci_bus & 4 ? 2 : 1,
strcat(str, "Mode 2"); pci_bus_modes[pci_bus & 3]);
else
strcat(str, "Mode 1");
strcat(str, " (");
strcat(str, pci_bus_modes[pci_bus & ~BIT_2]);
}
strcat(str, " MHz)");
return str; return str;
} }
...@@ -3460,7 +3450,8 @@ qla2x00_probe_one(struct pci_dev *pdev, const struct pci_device_id *id) ...@@ -3460,7 +3450,8 @@ qla2x00_probe_one(struct pci_dev *pdev, const struct pci_device_id *id)
"QLogic %s - %s.\n", ha->model_number, ha->model_desc); "QLogic %s - %s.\n", ha->model_number, ha->model_desc);
ql_log(ql_log_info, base_vha, 0x00fc, ql_log(ql_log_info, base_vha, 0x00fc,
"ISP%04X: %s @ %s hdma%c host#=%ld fw=%s.\n", "ISP%04X: %s @ %s hdma%c host#=%ld fw=%s.\n",
pdev->device, ha->isp_ops->pci_info_str(base_vha, pci_info), pdev->device, ha->isp_ops->pci_info_str(base_vha, pci_info,
sizeof(pci_info)),
pci_name(pdev), ha->flags.enable_64bit_addressing ? '+' : '-', pci_name(pdev), ha->flags.enable_64bit_addressing ? '+' : '-',
base_vha->host_no, base_vha->host_no,
ha->isp_ops->fw_version_str(base_vha, fw_str, sizeof(fw_str))); ha->isp_ops->fw_version_str(base_vha, fw_str, sizeof(fw_str)));
......
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