Commit be716446 authored by Padmanabh Ratnakar's avatar Padmanabh Ratnakar Committed by David S. Miller

be2net: Fix smatch warnings in be_main.c

FW flashing code, even though it works correctly, makes some hidden
assumptions about buffer sizes. This is causing code analysers to
report error. Cleanup FW flashing code to remove these hidden assumptions.
Reported-by: default avatarYuanhan Liu <yuanhan.liu@intel.com>
Signed-off-by: default avatarVasundhara Volam <vasundhara.volam@emulex.com>
Signed-off-by: default avatarSathya Perla <sathya.perla@emulex.com>
Signed-off-by: default avatarPadmanabh Ratnakar <padmanabh.ratnakar@emulex.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent c80bbeae
...@@ -2160,7 +2160,7 @@ int be_cmd_get_flash_crc(struct be_adapter *adapter, u8 *flashed_crc, ...@@ -2160,7 +2160,7 @@ int be_cmd_get_flash_crc(struct be_adapter *adapter, u8 *flashed_crc,
int offset) int offset)
{ {
struct be_mcc_wrb *wrb; struct be_mcc_wrb *wrb;
struct be_cmd_write_flashrom *req; struct be_cmd_read_flash_crc *req;
int status; int status;
spin_lock_bh(&adapter->mcc_lock); spin_lock_bh(&adapter->mcc_lock);
...@@ -2173,7 +2173,8 @@ int be_cmd_get_flash_crc(struct be_adapter *adapter, u8 *flashed_crc, ...@@ -2173,7 +2173,8 @@ int be_cmd_get_flash_crc(struct be_adapter *adapter, u8 *flashed_crc,
req = embedded_payload(wrb); req = embedded_payload(wrb);
be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON, be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
OPCODE_COMMON_READ_FLASHROM, sizeof(*req)+4, wrb, NULL); OPCODE_COMMON_READ_FLASHROM, sizeof(*req),
wrb, NULL);
req->params.op_type = cpu_to_le32(OPTYPE_REDBOOT); req->params.op_type = cpu_to_le32(OPTYPE_REDBOOT);
req->params.op_code = cpu_to_le32(FLASHROM_OPER_REPORT); req->params.op_code = cpu_to_le32(FLASHROM_OPER_REPORT);
...@@ -2182,7 +2183,7 @@ int be_cmd_get_flash_crc(struct be_adapter *adapter, u8 *flashed_crc, ...@@ -2182,7 +2183,7 @@ int be_cmd_get_flash_crc(struct be_adapter *adapter, u8 *flashed_crc,
status = be_mcc_notify_wait(adapter); status = be_mcc_notify_wait(adapter);
if (!status) if (!status)
memcpy(flashed_crc, req->params.data_buf, 4); memcpy(flashed_crc, req->crc, 4);
err: err:
spin_unlock_bh(&adapter->mcc_lock); spin_unlock_bh(&adapter->mcc_lock);
......
...@@ -1156,14 +1156,22 @@ struct flashrom_params { ...@@ -1156,14 +1156,22 @@ struct flashrom_params {
u32 op_type; u32 op_type;
u32 data_buf_size; u32 data_buf_size;
u32 offset; u32 offset;
u8 data_buf[4];
}; };
struct be_cmd_write_flashrom { struct be_cmd_write_flashrom {
struct be_cmd_req_hdr hdr; struct be_cmd_req_hdr hdr;
struct flashrom_params params; struct flashrom_params params;
}; u8 data_buf[32768];
u8 rsvd[4];
} __packed;
/* cmd to read flash crc */
struct be_cmd_read_flash_crc {
struct be_cmd_req_hdr hdr;
struct flashrom_params params;
u8 crc[4];
u8 rsvd[4];
};
/**************** Lancer Firmware Flash ************/ /**************** Lancer Firmware Flash ************/
struct amap_lancer_write_obj_context { struct amap_lancer_write_obj_context {
u8 write_length[24]; u8 write_length[24];
......
...@@ -3114,7 +3114,7 @@ static int be_flash(struct be_adapter *adapter, const u8 *img, ...@@ -3114,7 +3114,7 @@ static int be_flash(struct be_adapter *adapter, const u8 *img,
flash_op = FLASHROM_OPER_SAVE; flash_op = FLASHROM_OPER_SAVE;
} }
memcpy(req->params.data_buf, img, num_bytes); memcpy(req->data_buf, img, num_bytes);
img += num_bytes; img += num_bytes;
status = be_cmd_write_flashrom(adapter, flash_cmd, optype, status = be_cmd_write_flashrom(adapter, flash_cmd, optype,
flash_op, num_bytes); flash_op, num_bytes);
...@@ -3471,7 +3471,7 @@ static int be_fw_download(struct be_adapter *adapter, const struct firmware* fw) ...@@ -3471,7 +3471,7 @@ static int be_fw_download(struct be_adapter *adapter, const struct firmware* fw)
const u8 *p; const u8 *p;
int status = 0, i = 0, num_imgs = 0, ufi_type = 0; int status = 0, i = 0, num_imgs = 0, ufi_type = 0;
flash_cmd.size = sizeof(struct be_cmd_write_flashrom) + 32*1024; flash_cmd.size = sizeof(struct be_cmd_write_flashrom);
flash_cmd.va = dma_alloc_coherent(&adapter->pdev->dev, flash_cmd.size, flash_cmd.va = dma_alloc_coherent(&adapter->pdev->dev, flash_cmd.size,
&flash_cmd.dma, GFP_KERNEL); &flash_cmd.dma, GFP_KERNEL);
if (!flash_cmd.va) { if (!flash_cmd.va) {
......
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