Skip to content

Commit

Permalink
octeon_ep: fix potential memory leak in octep_device_setup()
Browse files Browse the repository at this point in the history
When occur unsupported_dev and mbox init errors, it did not free oct->conf
and iounmap() oct->mmio[i].hw_addr. That would trigger memory leak problem.
Add kfree() for oct->conf and iounmap() for oct->mmio[i].hw_addr under
unsupported_dev and mbox init errors to fix the problem.

Fixes: 862cd65 ("octeon_ep: Add driver framework and device initialization")
Signed-off-by: Ziyang Xuan <william.xuanziyang@huawei.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
  • Loading branch information
Ziyang Xuan authored and David S. Miller committed Nov 14, 2022
1 parent 9d3ff71 commit e4041be
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion drivers/net/ethernet/marvell/octeon_ep/octep_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -956,7 +956,7 @@ int octep_device_setup(struct octep_device *oct)
ret = octep_ctrl_mbox_init(ctrl_mbox);
if (ret) {
dev_err(&pdev->dev, "Failed to initialize control mbox\n");
return -1;
goto unsupported_dev;
}
oct->ctrl_mbox_ifstats_offset = OCTEP_CTRL_MBOX_SZ(ctrl_mbox->h2fq.elem_sz,
ctrl_mbox->h2fq.elem_cnt,
Expand All @@ -966,6 +966,10 @@ int octep_device_setup(struct octep_device *oct)
return 0;

unsupported_dev:
for (i = 0; i < OCTEP_MMIO_REGIONS; i++)
iounmap(oct->mmio[i].hw_addr);

kfree(oct->conf);
return -1;
}

Expand Down

0 comments on commit e4041be

Please sign in to comment.