Message ID | 20220914032659.96388-1-linyujun809@huawei.com (mailing list archive) |
---|---|
State | New |
Headers | show |
Series | [-next] powerpc: Avoid platform device Leak in the event of platform_device_add() fails | expand |
Context | Check | Description |
---|---|---|
snowpatch_ozlabs/github-powerpc_selftests | success | Successfully ran 10 jobs. |
snowpatch_ozlabs/github-powerpc_ppctests | success | Successfully ran 10 jobs. |
snowpatch_ozlabs/github-powerpc_sparse | success | Successfully ran 4 jobs. |
snowpatch_ozlabs/github-powerpc_clang | success | Successfully ran 6 jobs. |
snowpatch_ozlabs/github-powerpc_kernel_qemu | success | Successfully ran 23 jobs. |
kindly ping 在 2022/9/14 11:26, Lin Yujun 写道: > Use platform_device_put() to free the platform device and return > directly in the event platform_device_add() fails. > > Fixes: a28d3af2a26c ("[PATCH] 2/5 powerpc: Rework PowerMac i2c part 2") > Signed-off-by: Lin Yujun <linyujun809@huawei.com> > --- > arch/powerpc/platforms/powermac/low_i2c.c | 7 ++++++- > 1 file changed, 6 insertions(+), 1 deletion(-) > > diff --git a/arch/powerpc/platforms/powermac/low_i2c.c b/arch/powerpc/platforms/powermac/low_i2c.c > index c1c430c66dc9..5171635c3450 100644 > --- a/arch/powerpc/platforms/powermac/low_i2c.c > +++ b/arch/powerpc/platforms/powermac/low_i2c.c > @@ -1487,6 +1487,7 @@ static int __init pmac_i2c_create_platform_devices(void) > { > struct pmac_i2c_bus *bus; > int i = 0; > + int ret; > > /* In the case where we are initialized from smp_init(), we must > * not use the timer (and thus the irq). It's safe from now on > @@ -1502,7 +1503,11 @@ static int __init pmac_i2c_create_platform_devices(void) > return -ENOMEM; > bus->platform_dev->dev.platform_data = bus; > bus->platform_dev->dev.of_node = bus->busnode; > - platform_device_add(bus->platform_dev); > + ret = platform_device_add(bus->platform_dev); > + if (ret) { > + platform_device_put(bus->platform_dev); > + return ret; > + } > } > > /* Now call platform "init" functions */
diff --git a/arch/powerpc/platforms/powermac/low_i2c.c b/arch/powerpc/platforms/powermac/low_i2c.c index c1c430c66dc9..5171635c3450 100644 --- a/arch/powerpc/platforms/powermac/low_i2c.c +++ b/arch/powerpc/platforms/powermac/low_i2c.c @@ -1487,6 +1487,7 @@ static int __init pmac_i2c_create_platform_devices(void) { struct pmac_i2c_bus *bus; int i = 0; + int ret; /* In the case where we are initialized from smp_init(), we must * not use the timer (and thus the irq). It's safe from now on @@ -1502,7 +1503,11 @@ static int __init pmac_i2c_create_platform_devices(void) return -ENOMEM; bus->platform_dev->dev.platform_data = bus; bus->platform_dev->dev.of_node = bus->busnode; - platform_device_add(bus->platform_dev); + ret = platform_device_add(bus->platform_dev); + if (ret) { + platform_device_put(bus->platform_dev); + return ret; + } } /* Now call platform "init" functions */
Use platform_device_put() to free the platform device and return directly in the event platform_device_add() fails. Fixes: a28d3af2a26c ("[PATCH] 2/5 powerpc: Rework PowerMac i2c part 2") Signed-off-by: Lin Yujun <linyujun809@huawei.com> --- arch/powerpc/platforms/powermac/low_i2c.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)