Commit 6a75da4a authored by Jesper Juhl's avatar Jesper Juhl Committed by David S. Miller

Madge Ambassador ATM Adapter driver: Always release_firmware() in ucode_init()...

Madge Ambassador ATM Adapter driver: Always release_firmware() in ucode_init() and don't leak memory.

Failure to call release_firmware() will result in memory leak in
drivers/atm/ambassador.c::ucode_init().
This patch makes sure we always call release_firmware() when needed,
thus removing the leak(s).

Yes, I know checkpatch complains about this patch, but it was either that
or completely mess up the existing style, so I opted to use the existing
style and live with the checkpatch related flak.
Signed-off-by: default avatarJesper Juhl <jj@chaosbits.net>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 26877c79
...@@ -1926,6 +1926,7 @@ static int __devinit ucode_init (loader_block * lb, amb_dev * dev) { ...@@ -1926,6 +1926,7 @@ static int __devinit ucode_init (loader_block * lb, amb_dev * dev) {
const struct firmware *fw; const struct firmware *fw;
unsigned long start_address; unsigned long start_address;
const struct ihex_binrec *rec; const struct ihex_binrec *rec;
const char *errmsg = 0;
int res; int res;
res = request_ihex_firmware(&fw, "atmsar11.fw", &dev->pci_dev->dev); res = request_ihex_firmware(&fw, "atmsar11.fw", &dev->pci_dev->dev);
...@@ -1937,8 +1938,8 @@ static int __devinit ucode_init (loader_block * lb, amb_dev * dev) { ...@@ -1937,8 +1938,8 @@ static int __devinit ucode_init (loader_block * lb, amb_dev * dev) {
/* First record contains just the start address */ /* First record contains just the start address */
rec = (const struct ihex_binrec *)fw->data; rec = (const struct ihex_binrec *)fw->data;
if (be16_to_cpu(rec->len) != sizeof(__be32) || be32_to_cpu(rec->addr)) { if (be16_to_cpu(rec->len) != sizeof(__be32) || be32_to_cpu(rec->addr)) {
PRINTK (KERN_ERR, "Bad microcode data (no start record)"); errmsg = "no start record";
return -EINVAL; goto fail;
} }
start_address = be32_to_cpup((__be32 *)rec->data); start_address = be32_to_cpup((__be32 *)rec->data);
...@@ -1950,12 +1951,12 @@ static int __devinit ucode_init (loader_block * lb, amb_dev * dev) { ...@@ -1950,12 +1951,12 @@ static int __devinit ucode_init (loader_block * lb, amb_dev * dev) {
PRINTD (DBG_LOAD, "starting region (%x, %u)", be32_to_cpu(rec->addr), PRINTD (DBG_LOAD, "starting region (%x, %u)", be32_to_cpu(rec->addr),
be16_to_cpu(rec->len)); be16_to_cpu(rec->len));
if (be16_to_cpu(rec->len) > 4 * MAX_TRANSFER_DATA) { if (be16_to_cpu(rec->len) > 4 * MAX_TRANSFER_DATA) {
PRINTK (KERN_ERR, "Bad microcode data (record too long)"); errmsg = "record too long";
return -EINVAL; goto fail;
} }
if (be16_to_cpu(rec->len) & 3) { if (be16_to_cpu(rec->len) & 3) {
PRINTK (KERN_ERR, "Bad microcode data (odd number of bytes)"); errmsg = "odd number of bytes";
return -EINVAL; goto fail;
} }
res = loader_write(lb, dev, rec); res = loader_write(lb, dev, rec);
if (res) if (res)
...@@ -1970,6 +1971,10 @@ static int __devinit ucode_init (loader_block * lb, amb_dev * dev) { ...@@ -1970,6 +1971,10 @@ static int __devinit ucode_init (loader_block * lb, amb_dev * dev) {
res = loader_start(lb, dev, start_address); res = loader_start(lb, dev, start_address);
return res; return res;
fail:
release_firmware(fw);
PRINTK(KERN_ERR, "Bad microcode data (%s)", errmsg);
return -EINVAL;
} }
/********** give adapter parameters **********/ /********** give adapter parameters **********/
......
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