From: Ben Hutchings <ben@decadent.org.uk>
To: "James E.J. Bottomley" <James.Bottomley@HansenPartnership.com>
Cc: linux-scsi@vger.kernel.org
Subject: [PATCH 1/2] qla1280: Unify common code in qla1280_load_firmware_{dma,pio}()
Date: Sun, 23 Aug 2009 16:34:42 +0100 [thread overview]
Message-ID: <1251041682.16001.247.camel@localhost> (raw)
The verification and copying of metadata from the firmware is
identical in the two functions, and can be done in their caller.
As a side-effect, this fixes a leak when DUMP_IT_BACK is defined and
request_firmware() fails.
Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
---
drivers/scsi/qla1280.c | 78 ++++++++++++++++++------------------------------
1 files changed, 29 insertions(+), 49 deletions(-)
diff --git a/drivers/scsi/qla1280.c b/drivers/scsi/qla1280.c
index 8371d91..4951344 100644
--- a/drivers/scsi/qla1280.c
+++ b/drivers/scsi/qla1280.c
@@ -1632,33 +1632,13 @@ qla1280_chip_diag(struct scsi_qla_host *ha)
}
static int
-qla1280_load_firmware_pio(struct scsi_qla_host *ha)
+qla1280_load_firmware_pio(struct scsi_qla_host *ha, const struct firmware *fw)
{
- const struct firmware *fw;
const __le16 *fw_data;
uint16_t risc_address, risc_code_size;
uint16_t mb[MAILBOX_REGISTER_COUNT], i;
int err;
- err = request_firmware(&fw, ql1280_board_tbl[ha->devnum].fwname,
- &ha->pdev->dev);
- if (err) {
- printk(KERN_ERR "Failed to load image \"%s\" err %d\n",
- ql1280_board_tbl[ha->devnum].fwname, err);
- return err;
- }
- if ((fw->size % 2) || (fw->size < 6)) {
- printk(KERN_ERR "Bogus length %zu in image \"%s\"\n",
- fw->size, ql1280_board_tbl[ha->devnum].fwname);
- err = -EINVAL;
- goto out;
- }
- ha->fwver1 = fw->data[0];
- ha->fwver2 = fw->data[1];
- ha->fwver3 = fw->data[2];
- fw_data = (const __le16 *)&fw->data[0];
- ha->fwstart = __le16_to_cpu(fw_data[2]);
-
/* Load RISC code. */
risc_address = ha->fwstart;
fw_data = (const __le16 *)&fw->data[6];
@@ -1673,19 +1653,16 @@ qla1280_load_firmware_pio(struct scsi_qla_host *ha)
if (err) {
printk(KERN_ERR "scsi(%li): Failed to load firmware\n",
ha->host_no);
- goto out;
+ return err;
}
}
-out:
- release_firmware(fw);
- return err;
+ return 0;
}
#define DUMP_IT_BACK 0 /* for debug of RISC loading */
static int
-qla1280_load_firmware_dma(struct scsi_qla_host *ha)
+qla1280_load_firmware_dma(struct scsi_qla_host *ha, const struct firmware *fw)
{
- const struct firmware *fw;
const __le16 *fw_data;
uint16_t risc_address, risc_code_size;
uint16_t mb[MAILBOX_REGISTER_COUNT], cnt;
@@ -1699,25 +1676,6 @@ qla1280_load_firmware_dma(struct scsi_qla_host *ha)
return -ENOMEM;
#endif
- err = request_firmware(&fw, ql1280_board_tbl[ha->devnum].fwname,
- &ha->pdev->dev);
- if (err) {
- printk(KERN_ERR "Failed to load image \"%s\" err %d\n",
- ql1280_board_tbl[ha->devnum].fwname, err);
- return err;
- }
- if ((fw->size % 2) || (fw->size < 6)) {
- printk(KERN_ERR "Bogus length %zu in image \"%s\"\n",
- fw->size, ql1280_board_tbl[ha->devnum].fwname);
- err = -EINVAL;
- goto out;
- }
- ha->fwver1 = fw->data[0];
- ha->fwver2 = fw->data[1];
- ha->fwver3 = fw->data[2];
- fw_data = (const __le16 *)&fw->data[0];
- ha->fwstart = __le16_to_cpu(fw_data[2]);
-
/* Load RISC code. */
risc_address = ha->fwstart;
fw_data = (const __le16 *)&fw->data[6];
@@ -1799,7 +1757,6 @@ qla1280_load_firmware_dma(struct scsi_qla_host *ha)
#if DUMP_IT_BACK
pci_free_consistent(ha->pdev, 8000, tbuf, p_tbuf);
#endif
- release_firmware(fw);
return err;
}
@@ -1838,19 +1795,42 @@ qla1280_start_firmware(struct scsi_qla_host *ha)
static int
qla1280_load_firmware(struct scsi_qla_host *ha)
{
+ const struct firmware *fw;
+ const __le16 *fw_data;
int err;
err = qla1280_chip_diag(ha);
if (err)
+ return err;
+
+ err = request_firmware(&fw, ql1280_board_tbl[ha->devnum].fwname,
+ &ha->pdev->dev);
+ if (err) {
+ printk(KERN_ERR "Failed to load image \"%s\" err %d\n",
+ ql1280_board_tbl[ha->devnum].fwname, err);
+ return err;
+ }
+ if ((fw->size % 2) || (fw->size < 6)) {
+ printk(KERN_ERR "Bogus length %zu in image \"%s\"\n",
+ fw->size, ql1280_board_tbl[ha->devnum].fwname);
+ err = -EINVAL;
goto out;
+ }
+ ha->fwver1 = fw->data[0];
+ ha->fwver2 = fw->data[1];
+ ha->fwver3 = fw->data[2];
+ fw_data = (const __le16 *)&fw->data[0];
+ ha->fwstart = __le16_to_cpu(fw_data[2]);
+
if (IS_ISP1040(ha))
- err = qla1280_load_firmware_pio(ha);
+ err = qla1280_load_firmware_pio(ha, fw);
else
- err = qla1280_load_firmware_dma(ha);
+ err = qla1280_load_firmware_dma(ha, fw);
if (err)
goto out;
err = qla1280_start_firmware(ha);
out:
+ release_firmware(fw);
return err;
}
--
1.6.3.3
reply other threads:[~2009-08-23 15:34 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1251041682.16001.247.camel@localhost \
--to=ben@decadent.org.uk \
--cc=James.Bottomley@HansenPartnership.com \
--cc=linux-scsi@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox