diff options
author | Jesper Juhl <jj@chaosbits.net> | 2011-01-09 06:32:38 -0500 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2011-01-09 18:45:48 -0500 |
commit | 6a75da4a1a1d220fc3e32b816e83c258617505c5 (patch) | |
tree | c7cc5931f5f5637e19892635cdf30ad2bcd8d622 /drivers/atm | |
parent | 26877c794407855f65c056d7914b2e72ae9b93b8 (diff) |
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: Jesper Juhl <jj@chaosbits.net>
Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'drivers/atm')
-rw-r--r-- | drivers/atm/ambassador.c | 19 |
1 files changed, 12 insertions, 7 deletions
diff --git a/drivers/atm/ambassador.c b/drivers/atm/ambassador.c index ffe9b655292e..9f47e8625266 100644 --- a/drivers/atm/ambassador.c +++ b/drivers/atm/ambassador.c | |||
@@ -1926,8 +1926,9 @@ static int __devinit ucode_init (loader_block * lb, amb_dev * dev) { | |||
1926 | const struct firmware *fw; | 1926 | const struct firmware *fw; |
1927 | unsigned long start_address; | 1927 | unsigned long start_address; |
1928 | const struct ihex_binrec *rec; | 1928 | const struct ihex_binrec *rec; |
1929 | const char *errmsg = 0; | ||
1929 | int res; | 1930 | int res; |
1930 | 1931 | ||
1931 | res = request_ihex_firmware(&fw, "atmsar11.fw", &dev->pci_dev->dev); | 1932 | res = request_ihex_firmware(&fw, "atmsar11.fw", &dev->pci_dev->dev); |
1932 | if (res) { | 1933 | if (res) { |
1933 | PRINTK (KERN_ERR, "Cannot load microcode data"); | 1934 | PRINTK (KERN_ERR, "Cannot load microcode data"); |
@@ -1937,8 +1938,8 @@ static int __devinit ucode_init (loader_block * lb, amb_dev * dev) { | |||
1937 | /* First record contains just the start address */ | 1938 | /* First record contains just the start address */ |
1938 | rec = (const struct ihex_binrec *)fw->data; | 1939 | rec = (const struct ihex_binrec *)fw->data; |
1939 | if (be16_to_cpu(rec->len) != sizeof(__be32) || be32_to_cpu(rec->addr)) { | 1940 | if (be16_to_cpu(rec->len) != sizeof(__be32) || be32_to_cpu(rec->addr)) { |
1940 | PRINTK (KERN_ERR, "Bad microcode data (no start record)"); | 1941 | errmsg = "no start record"; |
1941 | return -EINVAL; | 1942 | goto fail; |
1942 | } | 1943 | } |
1943 | start_address = be32_to_cpup((__be32 *)rec->data); | 1944 | start_address = be32_to_cpup((__be32 *)rec->data); |
1944 | 1945 | ||
@@ -1950,12 +1951,12 @@ static int __devinit ucode_init (loader_block * lb, amb_dev * dev) { | |||
1950 | PRINTD (DBG_LOAD, "starting region (%x, %u)", be32_to_cpu(rec->addr), | 1951 | PRINTD (DBG_LOAD, "starting region (%x, %u)", be32_to_cpu(rec->addr), |
1951 | be16_to_cpu(rec->len)); | 1952 | be16_to_cpu(rec->len)); |
1952 | if (be16_to_cpu(rec->len) > 4 * MAX_TRANSFER_DATA) { | 1953 | if (be16_to_cpu(rec->len) > 4 * MAX_TRANSFER_DATA) { |
1953 | PRINTK (KERN_ERR, "Bad microcode data (record too long)"); | 1954 | errmsg = "record too long"; |
1954 | return -EINVAL; | 1955 | goto fail; |
1955 | } | 1956 | } |
1956 | if (be16_to_cpu(rec->len) & 3) { | 1957 | if (be16_to_cpu(rec->len) & 3) { |
1957 | PRINTK (KERN_ERR, "Bad microcode data (odd number of bytes)"); | 1958 | errmsg = "odd number of bytes"; |
1958 | return -EINVAL; | 1959 | goto fail; |
1959 | } | 1960 | } |
1960 | res = loader_write(lb, dev, rec); | 1961 | res = loader_write(lb, dev, rec); |
1961 | if (res) | 1962 | if (res) |
@@ -1970,6 +1971,10 @@ static int __devinit ucode_init (loader_block * lb, amb_dev * dev) { | |||
1970 | res = loader_start(lb, dev, start_address); | 1971 | res = loader_start(lb, dev, start_address); |
1971 | 1972 | ||
1972 | return res; | 1973 | return res; |
1974 | fail: | ||
1975 | release_firmware(fw); | ||
1976 | PRINTK(KERN_ERR, "Bad microcode data (%s)", errmsg); | ||
1977 | return -EINVAL; | ||
1973 | } | 1978 | } |
1974 | 1979 | ||
1975 | /********** give adapter parameters **********/ | 1980 | /********** give adapter parameters **********/ |