Commit 11bec9cb authored by Lin Yujun's avatar Lin Yujun Committed by Thomas Bogendoerfer

MIPS: SGI-IP27: Fix platform-device leak in bridge_platform_create()

In error case in bridge_platform_create after calling
platform_device_add()/platform_device_add_data()/
platform_device_add_resources(), release the failed
'pdev' or it will be leak, call platform_device_put()
to fix this problem.

Besides, 'pdev' is divided into 'pdev_wd' and 'pdev_bd',
use platform_device_unregister() to release sgi_w1
resources when xtalk-bridge registration fails.

Fixes: 5dc76a96 ("MIPS: PCI: use information from 1-wire PROM for IOC3 detection")
Signed-off-by: default avatarLin Yujun <linyujun809@huawei.com>
Signed-off-by: default avatarThomas Bogendoerfer <tsbogend@alpha.franken.de>
parent 1e6d11fe
...@@ -27,15 +27,18 @@ static void bridge_platform_create(nasid_t nasid, int widget, int masterwid) ...@@ -27,15 +27,18 @@ static void bridge_platform_create(nasid_t nasid, int widget, int masterwid)
{ {
struct xtalk_bridge_platform_data *bd; struct xtalk_bridge_platform_data *bd;
struct sgi_w1_platform_data *wd; struct sgi_w1_platform_data *wd;
struct platform_device *pdev; struct platform_device *pdev_wd;
struct platform_device *pdev_bd;
struct resource w1_res; struct resource w1_res;
unsigned long offset; unsigned long offset;
offset = NODE_OFFSET(nasid); offset = NODE_OFFSET(nasid);
wd = kzalloc(sizeof(*wd), GFP_KERNEL); wd = kzalloc(sizeof(*wd), GFP_KERNEL);
if (!wd) if (!wd) {
goto no_mem; pr_warn("xtalk:n%d/%x bridge create out of memory\n", nasid, widget);
return;
}
snprintf(wd->dev_id, sizeof(wd->dev_id), "bridge-%012lx", snprintf(wd->dev_id, sizeof(wd->dev_id), "bridge-%012lx",
offset + (widget << SWIN_SIZE_BITS)); offset + (widget << SWIN_SIZE_BITS));
...@@ -46,24 +49,35 @@ static void bridge_platform_create(nasid_t nasid, int widget, int masterwid) ...@@ -46,24 +49,35 @@ static void bridge_platform_create(nasid_t nasid, int widget, int masterwid)
w1_res.end = w1_res.start + 3; w1_res.end = w1_res.start + 3;
w1_res.flags = IORESOURCE_MEM; w1_res.flags = IORESOURCE_MEM;
pdev = platform_device_alloc("sgi_w1", PLATFORM_DEVID_AUTO); pdev_wd = platform_device_alloc("sgi_w1", PLATFORM_DEVID_AUTO);
if (!pdev) { if (!pdev_wd) {
kfree(wd); pr_warn("xtalk:n%d/%x bridge create out of memory\n", nasid, widget);
goto no_mem; goto err_kfree_wd;
}
if (platform_device_add_resources(pdev_wd, &w1_res, 1)) {
pr_warn("xtalk:n%d/%x bridge failed to add platform resources.\n", nasid, widget);
goto err_put_pdev_wd;
}
if (platform_device_add_data(pdev_wd, wd, sizeof(*wd))) {
pr_warn("xtalk:n%d/%x bridge failed to add platform data.\n", nasid, widget);
goto err_put_pdev_wd;
}
if (platform_device_add(pdev_wd)) {
pr_warn("xtalk:n%d/%x bridge failed to add platform device.\n", nasid, widget);
goto err_put_pdev_wd;
} }
platform_device_add_resources(pdev, &w1_res, 1);
platform_device_add_data(pdev, wd, sizeof(*wd));
/* platform_device_add_data() duplicates the data */ /* platform_device_add_data() duplicates the data */
kfree(wd); kfree(wd);
platform_device_add(pdev);
bd = kzalloc(sizeof(*bd), GFP_KERNEL); bd = kzalloc(sizeof(*bd), GFP_KERNEL);
if (!bd) if (!bd) {
goto no_mem; pr_warn("xtalk:n%d/%x bridge create out of memory\n", nasid, widget);
pdev = platform_device_alloc("xtalk-bridge", PLATFORM_DEVID_AUTO); goto err_unregister_pdev_wd;
if (!pdev) { }
kfree(bd); pdev_bd = platform_device_alloc("xtalk-bridge", PLATFORM_DEVID_AUTO);
goto no_mem; if (!pdev_bd) {
pr_warn("xtalk:n%d/%x bridge create out of memory\n", nasid, widget);
goto err_kfree_bd;
} }
...@@ -84,15 +98,31 @@ static void bridge_platform_create(nasid_t nasid, int widget, int masterwid) ...@@ -84,15 +98,31 @@ static void bridge_platform_create(nasid_t nasid, int widget, int masterwid)
bd->io.flags = IORESOURCE_IO; bd->io.flags = IORESOURCE_IO;
bd->io_offset = offset; bd->io_offset = offset;
platform_device_add_data(pdev, bd, sizeof(*bd)); if (platform_device_add_data(pdev_bd, bd, sizeof(*bd))) {
pr_warn("xtalk:n%d/%x bridge failed to add platform data.\n", nasid, widget);
goto err_put_pdev_bd;
}
if (platform_device_add(pdev_bd)) {
pr_warn("xtalk:n%d/%x bridge failed to add platform device.\n", nasid, widget);
goto err_put_pdev_bd;
}
/* platform_device_add_data() duplicates the data */ /* platform_device_add_data() duplicates the data */
kfree(bd); kfree(bd);
platform_device_add(pdev);
pr_info("xtalk:n%d/%x bridge widget\n", nasid, widget); pr_info("xtalk:n%d/%x bridge widget\n", nasid, widget);
return; return;
no_mem: err_put_pdev_bd:
pr_warn("xtalk:n%d/%x bridge create out of memory\n", nasid, widget); platform_device_put(pdev_bd);
err_kfree_bd:
kfree(bd);
err_unregister_pdev_wd:
platform_device_unregister(pdev_wd);
return;
err_put_pdev_wd:
platform_device_put(pdev_wd);
err_kfree_wd:
kfree(wd);
return;
} }
static int probe_one_port(nasid_t nasid, int widget, int masterwid) static int probe_one_port(nasid_t nasid, int widget, int masterwid)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment