Message ID | 20230914094620.3379729-1-ruc_gongyuanjun@163.com (mailing list archive) |
---|---|
State | Handled Elsewhere, archived |
Headers | show |
Series | [1/1] powerpc: fix a memory leak | expand |
Context | Check | Description |
---|---|---|
snowpatch_ozlabs/github-powerpc_selftests | success | Successfully ran 8 jobs. |
snowpatch_ozlabs/github-powerpc_sparse | fail | sparse (ppc64le, ppc64le, fedora-37) failed at step Build. |
snowpatch_ozlabs/github-powerpc_kernel_qemu | fail | kernel (ppc64_defconfig, korg-5.5.0) failed at step Build. |
snowpatch_ozlabs/github-powerpc_ppctests | success | Successfully ran 8 jobs. |
snowpatch_ozlabs/github-powerpc_clang | fail | 2 of 6 jobs failed. |
On 9/14/23 02:46, Yuanjun Gong wrote: > When one of the methods xive_native_alloc_irq_on_chip, irq_create_mapping > or irq_get_handler_data fails, the function will directly return without > disposing vinst->name and vinst. Fix it. > > Fixes: c20e1e299d93 ("powerpc/vas: Alloc and setup IRQ and trigger port address") > Signed-off-by: Yuanjun Gong <ruc_gongyuanjun@163.com> > --- > arch/powerpc/platforms/powernv/vas.c | 14 +++++++++----- > 1 file changed, 9 insertions(+), 5 deletions(-) > > diff --git a/arch/powerpc/platforms/powernv/vas.c b/arch/powerpc/platforms/powernv/vas.c > index b65256a63e87..780740b478f0 100644 > --- a/arch/powerpc/platforms/powernv/vas.c > +++ b/arch/powerpc/platforms/powernv/vas.c > @@ -54,7 +54,7 @@ static int init_vas_instance(struct platform_device *pdev) > struct xive_irq_data *xd; > uint32_t chipid, hwirq; > struct resource *res; > - int rc, cpu, vasid; > + int rc, cpu, vasid, ret; You can you reuse rc for the return value in the error path instead of introducing a new ret variable. -Tyrel > > rc = of_property_read_u32(dn, "ibm,vas-id", &vasid); > if (rc) { > @@ -102,6 +102,7 @@ static int init_vas_instance(struct platform_device *pdev) > res = &pdev->resource[3]; > if (res->end > 62) { > pr_err("Bad 'paste_win_id_shift' in DT, %llx\n", res->end); > + ret = -ENODEV > goto free_vinst; > } > > @@ -111,21 +112,24 @@ static int init_vas_instance(struct platform_device *pdev) > if (!hwirq) { > pr_err("Inst%d: Unable to allocate global irq for chip %d\n", > vinst->vas_id, chipid); > - return -ENOENT; > + ret = -ENOENT; > + goto free_vinst; > } > > vinst->virq = irq_create_mapping(NULL, hwirq); > if (!vinst->virq) { > pr_err("Inst%d: Unable to map global irq %d\n", > vinst->vas_id, hwirq); > - return -EINVAL; > + ret = -EINVAL; > + goto free_vinst; > } > > xd = irq_get_handler_data(vinst->virq); > if (!xd) { > pr_err("Inst%d: Invalid virq %d\n", > vinst->vas_id, vinst->virq); > - return -EINVAL; > + ret = -EINVAL; > + goto free_vinst; > } > > vinst->irq_port = xd->trig_page; > @@ -168,7 +172,7 @@ static int init_vas_instance(struct platform_device *pdev) > free_vinst: > kfree(vinst->name); > kfree(vinst); > - return -ENODEV; > + return ret; > > } >
Tyrel Datwyler <tyreld@linux.ibm.com> writes: > On 9/14/23 02:46, Yuanjun Gong wrote: >> When one of the methods xive_native_alloc_irq_on_chip, irq_create_mapping >> or irq_get_handler_data fails, the function will directly return without >> disposing vinst->name and vinst. Fix it. >> >> Fixes: c20e1e299d93 ("powerpc/vas: Alloc and setup IRQ and trigger port address") >> Signed-off-by: Yuanjun Gong <ruc_gongyuanjun@163.com> >> --- >> arch/powerpc/platforms/powernv/vas.c | 14 +++++++++----- >> 1 file changed, 9 insertions(+), 5 deletions(-) >> >> diff --git a/arch/powerpc/platforms/powernv/vas.c b/arch/powerpc/platforms/powernv/vas.c >> index b65256a63e87..780740b478f0 100644 >> --- a/arch/powerpc/platforms/powernv/vas.c >> +++ b/arch/powerpc/platforms/powernv/vas.c >> @@ -54,7 +54,7 @@ static int init_vas_instance(struct platform_device *pdev) >> struct xive_irq_data *xd; >> uint32_t chipid, hwirq; >> struct resource *res; >> - int rc, cpu, vasid; >> + int rc, cpu, vasid, ret; > > You can you reuse rc for the return value in the error path instead of > introducing a new ret variable. Yep, please send a v2. cheers
diff --git a/arch/powerpc/platforms/powernv/vas.c b/arch/powerpc/platforms/powernv/vas.c index b65256a63e87..780740b478f0 100644 --- a/arch/powerpc/platforms/powernv/vas.c +++ b/arch/powerpc/platforms/powernv/vas.c @@ -54,7 +54,7 @@ static int init_vas_instance(struct platform_device *pdev) struct xive_irq_data *xd; uint32_t chipid, hwirq; struct resource *res; - int rc, cpu, vasid; + int rc, cpu, vasid, ret; rc = of_property_read_u32(dn, "ibm,vas-id", &vasid); if (rc) { @@ -102,6 +102,7 @@ static int init_vas_instance(struct platform_device *pdev) res = &pdev->resource[3]; if (res->end > 62) { pr_err("Bad 'paste_win_id_shift' in DT, %llx\n", res->end); + ret = -ENODEV goto free_vinst; } @@ -111,21 +112,24 @@ static int init_vas_instance(struct platform_device *pdev) if (!hwirq) { pr_err("Inst%d: Unable to allocate global irq for chip %d\n", vinst->vas_id, chipid); - return -ENOENT; + ret = -ENOENT; + goto free_vinst; } vinst->virq = irq_create_mapping(NULL, hwirq); if (!vinst->virq) { pr_err("Inst%d: Unable to map global irq %d\n", vinst->vas_id, hwirq); - return -EINVAL; + ret = -EINVAL; + goto free_vinst; } xd = irq_get_handler_data(vinst->virq); if (!xd) { pr_err("Inst%d: Invalid virq %d\n", vinst->vas_id, vinst->virq); - return -EINVAL; + ret = -EINVAL; + goto free_vinst; } vinst->irq_port = xd->trig_page; @@ -168,7 +172,7 @@ static int init_vas_instance(struct platform_device *pdev) free_vinst: kfree(vinst->name); kfree(vinst); - return -ENODEV; + return ret; }
When one of the methods xive_native_alloc_irq_on_chip, irq_create_mapping or irq_get_handler_data fails, the function will directly return without disposing vinst->name and vinst. Fix it. Fixes: c20e1e299d93 ("powerpc/vas: Alloc and setup IRQ and trigger port address") Signed-off-by: Yuanjun Gong <ruc_gongyuanjun@163.com> --- arch/powerpc/platforms/powernv/vas.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-)