[PATCH v2 1/1] powerpc: fix a memory leak

2023-09-14 Thread Yuanjun Gong
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 
---
 arch/powerpc/platforms/powernv/vas.c | 12 
 1 file changed, 8 insertions(+), 4 deletions(-)

diff --git a/arch/powerpc/platforms/powernv/vas.c 
b/arch/powerpc/platforms/powernv/vas.c
index b65256a63e87..40cb7a03d180 100644
--- a/arch/powerpc/platforms/powernv/vas.c
+++ b/arch/powerpc/platforms/powernv/vas.c
@@ -102,6 +102,7 @@ static int init_vas_instance(struct platform_device *pdev)
res = >resource[3];
if (res->end > 62) {
pr_err("Bad 'paste_win_id_shift' in DT, %llx\n", res->end);
+   rc = -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;
+   rc = -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;
+   rc = -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;
+   rc = -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 rc;
 
 }
 
-- 
2.37.2



[PATCH 1/1] powerpc: fix a memory leak

2023-09-14 Thread Yuanjun Gong
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 
---
 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;
 
rc = of_property_read_u32(dn, "ibm,vas-id", );
if (rc) {
@@ -102,6 +102,7 @@ static int init_vas_instance(struct platform_device *pdev)
res = >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;
 
 }
 
-- 
2.37.2



[PATCH v3 1/1] ASoC: imx-audmux: fix return value checks of clk_prepare_enable()

2023-07-24 Thread Yuanjun Gong
check the return value of clk_prepare_enable(), and if
clk_prepare_enable() gets an unexpected return value,
imx_audmux_suspend() and imx_audmux_resume() should return
the error value.

Signed-off-by: Yuanjun Gong 
---
 sound/soc/fsl/imx-audmux.c | 12 
 1 file changed, 8 insertions(+), 4 deletions(-)

diff --git a/sound/soc/fsl/imx-audmux.c b/sound/soc/fsl/imx-audmux.c
index be003a117b39..096705ec2add 100644
--- a/sound/soc/fsl/imx-audmux.c
+++ b/sound/soc/fsl/imx-audmux.c
@@ -324,9 +324,11 @@ static void imx_audmux_remove(struct platform_device *pdev)
 #ifdef CONFIG_PM_SLEEP
 static int imx_audmux_suspend(struct device *dev)
 {
-   int i;
+   int i, ret;
 
-   clk_prepare_enable(audmux_clk);
+   ret = clk_prepare_enable(audmux_clk);
+   if (ret)
+   return ret;
 
for (i = 0; i < reg_max; i++)
regcache[i] = readl(audmux_base + i * 4);
@@ -338,9 +340,11 @@ static int imx_audmux_suspend(struct device *dev)
 
 static int imx_audmux_resume(struct device *dev)
 {
-   int i;
+   int i, ret;
 
-   clk_prepare_enable(audmux_clk);
+   ret = clk_prepare_enable(audmux_clk);
+   if (ret)
+   return ret;
 
for (i = 0; i < reg_max; i++)
writel(regcache[i], audmux_base + i * 4);
-- 
2.17.1



[PATCH v2 1/1] ASoC: imx-audmux: fix return value checks of clk_prepare_enable()

2023-07-22 Thread Yuanjun Gong
check the return value of clk_prepare_enable(), and if
clk_prepare_enable() gets an unexpected return value,
imx_audmux_suspend() and imx_audmux_resume() should return
the error value.

Signed-off-by: Yuanjun Gong 
---
 sound/soc/fsl/imx-audmux.c | 10 --
 1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/sound/soc/fsl/imx-audmux.c b/sound/soc/fsl/imx-audmux.c
index be003a117b39..9791e56158ef 100644
--- a/sound/soc/fsl/imx-audmux.c
+++ b/sound/soc/fsl/imx-audmux.c
@@ -325,8 +325,11 @@ static void imx_audmux_remove(struct platform_device *pdev)
 static int imx_audmux_suspend(struct device *dev)
 {
int i;
+   ssize_t ret;
 
-   clk_prepare_enable(audmux_clk);
+   ret = clk_prepare_enable(audmux_clk);
+   if (ret)
+   return ret;
 
for (i = 0; i < reg_max; i++)
regcache[i] = readl(audmux_base + i * 4);
@@ -339,8 +342,11 @@ static int imx_audmux_suspend(struct device *dev)
 static int imx_audmux_resume(struct device *dev)
 {
int i;
+   ssize_t ret;
 
-   clk_prepare_enable(audmux_clk);
+   ret = clk_prepare_enable(audmux_clk);
+   if (ret)
+   return ret;
 
for (i = 0; i < reg_max; i++)
writel(regcache[i], audmux_base + i * 4);
-- 
2.17.1



[PATCH 1/1] sound:soc: fix return value check in imx_audmux_suspend

2023-07-17 Thread Yuanjun Gong
check the return value of clk_prepare_enable, and if
clk_prepare_enable got an unexpected return value,
imx_audmux_suspend should return the error value.

Signed-off-by: Yuanjun Gong 
---
 sound/soc/fsl/imx-audmux.c | 5 -
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/sound/soc/fsl/imx-audmux.c b/sound/soc/fsl/imx-audmux.c
index be003a117b39..962b6baf0a34 100644
--- a/sound/soc/fsl/imx-audmux.c
+++ b/sound/soc/fsl/imx-audmux.c
@@ -325,8 +325,11 @@ static void imx_audmux_remove(struct platform_device *pdev)
 static int imx_audmux_suspend(struct device *dev)
 {
int i;
+   ssize_t ret;
 
-   clk_prepare_enable(audmux_clk);
+   ret = clk_prepare_enable(audmux_clk);
+   if (ret)
+   return ret;
 
for (i = 0; i < reg_max; i++)
regcache[i] = readl(audmux_base + i * 4);
-- 
2.17.1



[PATCH 1/1] sound:soc: fix return value check in imx_audmux_resume

2023-07-17 Thread Yuanjun Gong
check the return value of clk_prepare_enable, and if
clk_prepare_enable got an unexpected return value,
imx_audmux_resume should return the error value.

Signed-off-by: Yuanjun Gong 
---
 sound/soc/fsl/imx-audmux.c | 5 -
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/sound/soc/fsl/imx-audmux.c b/sound/soc/fsl/imx-audmux.c
index be003a117b39..e8a3a1baf18d 100644
--- a/sound/soc/fsl/imx-audmux.c
+++ b/sound/soc/fsl/imx-audmux.c
@@ -339,8 +339,11 @@ static int imx_audmux_suspend(struct device *dev)
 static int imx_audmux_resume(struct device *dev)
 {
int i;
+   ssize_t ret;
 
-   clk_prepare_enable(audmux_clk);
+   ret = clk_prepare_enable(audmux_clk);
+   if (ret)
+   return ret;
 
for (i = 0; i < reg_max; i++)
writel(regcache[i], audmux_base + i * 4);
-- 
2.17.1