Skip to content

Commit

Permalink
mfd: reduce stack usage in mfd-core.c
Browse files Browse the repository at this point in the history
This patch moves the allocation of the resources off the stack in
mfd_add_device().

Signed-off-by: Ian Molton <spyro@f2s.com>
Signed-off-by: Samuel Ortiz <sameo@openedhand.com>
  • Loading branch information
Ian Molton authored and Samuel Ortiz committed Oct 19, 2008
1 parent 0cfd810 commit a87903f
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions drivers/mfd/mfd-core.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ static int mfd_add_device(struct device *parent, int id,
struct resource *mem_base,
int irq_base)
{
struct resource res[cell->num_resources];
struct resource *res;
struct platform_device *pdev;
int ret = -ENOMEM;
int r;
Expand All @@ -29,14 +29,17 @@ static int mfd_add_device(struct device *parent, int id,
if (!pdev)
goto fail_alloc;

res = kzalloc(sizeof(*res) * cell->num_resources, GFP_KERNEL);
if (!res)
goto fail_device;

pdev->dev.parent = parent;

ret = platform_device_add_data(pdev,
cell->platform_data, cell->data_size);
if (ret)
goto fail_device;
goto fail_res;

memset(res, 0, sizeof(res));
for (r = 0; r < cell->num_resources; r++) {
res[r].name = cell->resources[r].name;
res[r].flags = cell->resources[r].flags;
Expand Down Expand Up @@ -64,11 +67,15 @@ static int mfd_add_device(struct device *parent, int id,

ret = platform_device_add(pdev);
if (ret)
goto fail_device;
goto fail_res;

kfree(res);

return 0;

/* platform_device_del(pdev); */
fail_res:
kfree(res);
fail_device:
platform_device_put(pdev);
fail_alloc:
Expand Down

0 comments on commit a87903f

Please sign in to comment.