diff options
author | Hans-Christian Egtvedt <hans-christian.egtvedt@atmel.com> | 2009-12-28 06:22:06 -0500 |
---|---|---|
committer | Haavard Skinnemoen <haavard.skinnemoen@atmel.com> | 2009-12-28 06:33:00 -0500 |
commit | cbf8de1620cdb1abb5b0618ff561004f816064fc (patch) | |
tree | 827fcc026734b805b546f02016e47089acbeb960 /arch/avr32/mach-at32ap/at32ap700x.c | |
parent | 754a00aeb26bcc8bf82897538a078bc84a6d95c7 (diff) |
avr32: clean up memory allocation in at32_add_device_mci
This patch will check if the kzalloc for the MCI DMA struct actually
returns a valid address, and also clean up properly if it fails or the
function fails at a later stage.
This also silences a compiler warning about using the slave variable
uninitialized.
Signed-off-by: Hans-Christian Egtvedt <hans-christian.egtvedt@atmel.com>
Signed-off-by: Haavard Skinnemoen <haavard.skinnemoen@atmel.com>
Diffstat (limited to 'arch/avr32/mach-at32ap/at32ap700x.c')
-rw-r--r-- | arch/avr32/mach-at32ap/at32ap700x.c | 11 |
1 files changed, 7 insertions, 4 deletions
diff --git a/arch/avr32/mach-at32ap/at32ap700x.c b/arch/avr32/mach-at32ap/at32ap700x.c index 7d4ed4291985..b13d1879e51b 100644 --- a/arch/avr32/mach-at32ap/at32ap700x.c +++ b/arch/avr32/mach-at32ap/at32ap700x.c | |||
@@ -1345,6 +1345,8 @@ at32_add_device_mci(unsigned int id, struct mci_platform_data *data) | |||
1345 | goto fail; | 1345 | goto fail; |
1346 | 1346 | ||
1347 | slave = kzalloc(sizeof(struct mci_dma_data), GFP_KERNEL); | 1347 | slave = kzalloc(sizeof(struct mci_dma_data), GFP_KERNEL); |
1348 | if (!slave) | ||
1349 | goto fail; | ||
1348 | 1350 | ||
1349 | slave->sdata.dma_dev = &dw_dmac0_device.dev; | 1351 | slave->sdata.dma_dev = &dw_dmac0_device.dev; |
1350 | slave->sdata.reg_width = DW_DMA_SLAVE_WIDTH_32BIT; | 1352 | slave->sdata.reg_width = DW_DMA_SLAVE_WIDTH_32BIT; |
@@ -1357,7 +1359,7 @@ at32_add_device_mci(unsigned int id, struct mci_platform_data *data) | |||
1357 | 1359 | ||
1358 | if (platform_device_add_data(pdev, data, | 1360 | if (platform_device_add_data(pdev, data, |
1359 | sizeof(struct mci_platform_data))) | 1361 | sizeof(struct mci_platform_data))) |
1360 | goto fail; | 1362 | goto fail_free; |
1361 | 1363 | ||
1362 | /* CLK line is common to both slots */ | 1364 | /* CLK line is common to both slots */ |
1363 | pioa_mask = 1 << 10; | 1365 | pioa_mask = 1 << 10; |
@@ -1381,7 +1383,7 @@ at32_add_device_mci(unsigned int id, struct mci_platform_data *data) | |||
1381 | /* Slot is unused */ | 1383 | /* Slot is unused */ |
1382 | break; | 1384 | break; |
1383 | default: | 1385 | default: |
1384 | goto fail; | 1386 | goto fail_free; |
1385 | } | 1387 | } |
1386 | 1388 | ||
1387 | select_peripheral(PIOA, pioa_mask, PERIPH_A, 0); | 1389 | select_peripheral(PIOA, pioa_mask, PERIPH_A, 0); |
@@ -1408,7 +1410,7 @@ at32_add_device_mci(unsigned int id, struct mci_platform_data *data) | |||
1408 | break; | 1410 | break; |
1409 | default: | 1411 | default: |
1410 | if (!data->slot[0].bus_width) | 1412 | if (!data->slot[0].bus_width) |
1411 | goto fail; | 1413 | goto fail_free; |
1412 | 1414 | ||
1413 | data->slot[1].bus_width = 0; | 1415 | data->slot[1].bus_width = 0; |
1414 | break; | 1416 | break; |
@@ -1419,9 +1421,10 @@ at32_add_device_mci(unsigned int id, struct mci_platform_data *data) | |||
1419 | platform_device_add(pdev); | 1421 | platform_device_add(pdev); |
1420 | return pdev; | 1422 | return pdev; |
1421 | 1423 | ||
1424 | fail_free: | ||
1425 | kfree(slave); | ||
1422 | fail: | 1426 | fail: |
1423 | data->dma_slave = NULL; | 1427 | data->dma_slave = NULL; |
1424 | kfree(slave); | ||
1425 | platform_device_put(pdev); | 1428 | platform_device_put(pdev); |
1426 | return NULL; | 1429 | return NULL; |
1427 | } | 1430 | } |