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>

authored by Hans-Christian Egtvedt and committed by Haavard Skinnemoen cbf8de16 754a00ae

+7 -4
+7 -4
arch/avr32/mach-at32ap/at32ap700x.c
··· 1345 1345 goto fail; 1346 1346 1347 1347 slave = kzalloc(sizeof(struct mci_dma_data), GFP_KERNEL); 1348 + if (!slave) 1349 + goto fail; 1348 1350 1349 1351 slave->sdata.dma_dev = &dw_dmac0_device.dev; 1350 1352 slave->sdata.reg_width = DW_DMA_SLAVE_WIDTH_32BIT; ··· 1359 1357 1360 1358 if (platform_device_add_data(pdev, data, 1361 1359 sizeof(struct mci_platform_data))) 1362 - goto fail; 1360 + goto fail_free; 1363 1361 1364 1362 /* CLK line is common to both slots */ 1365 1363 pioa_mask = 1 << 10; ··· 1383 1381 /* Slot is unused */ 1384 1382 break; 1385 1383 default: 1386 - goto fail; 1384 + goto fail_free; 1387 1385 } 1388 1386 1389 1387 select_peripheral(PIOA, pioa_mask, PERIPH_A, 0); ··· 1410 1408 break; 1411 1409 default: 1412 1410 if (!data->slot[0].bus_width) 1413 - goto fail; 1411 + goto fail_free; 1414 1412 1415 1413 data->slot[1].bus_width = 0; 1416 1414 break; ··· 1421 1419 platform_device_add(pdev); 1422 1420 return pdev; 1423 1421 1422 + fail_free: 1423 + kfree(slave); 1424 1424 fail: 1425 1425 data->dma_slave = NULL; 1426 - kfree(slave); 1427 1426 platform_device_put(pdev); 1428 1427 return NULL; 1429 1428 }