Linux kernel and device drivers for NXP i.MX platforms
 help / color / mirror / Atom feed
* [PATCH 1/1] Add check to ida_alloc()
@ 2025-05-13 12:37 Yuanjun Gong
  2025-05-16  3:59 ` Peng Fan
  0 siblings, 1 reply; 5+ messages in thread
From: Yuanjun Gong @ 2025-05-13 12:37 UTC (permalink / raw)
  To: Will Deacon, Mark Rutland, Shawn Guo, imx; +Cc: Yuanjun Gong

Check the return value of ida_alloc() in case it fails.
This is found by a static checker.

Signed-off-by: Yuanjun Gong <ruc_gongyuanjun@163.com>
---
 drivers/perf/fsl_imx9_ddr_perf.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/drivers/perf/fsl_imx9_ddr_perf.c b/drivers/perf/fsl_imx9_ddr_perf.c
index 843f163e6c33..86da027405cf 100644
--- a/drivers/perf/fsl_imx9_ddr_perf.c
+++ b/drivers/perf/fsl_imx9_ddr_perf.c
@@ -790,6 +790,9 @@ static int ddr_perf_probe(struct platform_device *pdev)
 	platform_set_drvdata(pdev, pmu);
 
 	pmu->id = ida_alloc(&ddr_ida, GFP_KERNEL);
+	if (pmu->id < 0)
+		return -ENOMEM;
+
 	name = devm_kasprintf(&pdev->dev, GFP_KERNEL, DDR_PERF_DEV_NAME "%d", pmu->id);
 	if (!name) {
 		ret = -ENOMEM;
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH 1/1] Add check to ida_alloc()
  2025-05-13 12:37 [PATCH 1/1] Add check to ida_alloc() Yuanjun Gong
@ 2025-05-16  3:59 ` Peng Fan
  2025-05-16  7:33   ` [PATCH v2 " Yuanjun Gong
  0 siblings, 1 reply; 5+ messages in thread
From: Peng Fan @ 2025-05-16  3:59 UTC (permalink / raw)
  To: Yuanjun Gong; +Cc: Will Deacon, Mark Rutland, Shawn Guo, imx

On Tue, May 13, 2025 at 08:37:05PM +0800, Yuanjun Gong wrote:
>Check the return value of ida_alloc() in case it fails.
>This is found by a static checker.
>
>Signed-off-by: Yuanjun Gong <ruc_gongyuanjun@163.com>
>---
> drivers/perf/fsl_imx9_ddr_perf.c | 3 +++
> 1 file changed, 3 insertions(+)
>
>diff --git a/drivers/perf/fsl_imx9_ddr_perf.c b/drivers/perf/fsl_imx9_ddr_perf.c
>index 843f163e6c33..86da027405cf 100644
>--- a/drivers/perf/fsl_imx9_ddr_perf.c
>+++ b/drivers/perf/fsl_imx9_ddr_perf.c
>@@ -790,6 +790,9 @@ static int ddr_perf_probe(struct platform_device *pdev)
> 	platform_set_drvdata(pdev, pmu);
> 
> 	pmu->id = ida_alloc(&ddr_ida, GFP_KERNEL);
>+	if (pmu->id < 0)
>+		return -ENOMEM;

I would write this as:
ret = ida_alloc(&ddr_ida, GFP_KERNEL);
if (ret < 0)
    return ret;

pmu->id = ret;

Regards,
Peng

>+
> 	name = devm_kasprintf(&pdev->dev, GFP_KERNEL, DDR_PERF_DEV_NAME "%d", pmu->id);
> 	if (!name) {
> 		ret = -ENOMEM;
>-- 
>2.25.1
>

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH v2 1/1] Add check to ida_alloc()
  2025-05-16  3:59 ` Peng Fan
@ 2025-05-16  7:33   ` Yuanjun Gong
  2025-05-16  8:42     ` Daniel Baluta
  0 siblings, 1 reply; 5+ messages in thread
From: Yuanjun Gong @ 2025-05-16  7:33 UTC (permalink / raw)
  To: imx; +Cc: Peng Fan, Will Deacon, Mark Rutland, Shawn Guo, Yuanjun Gong

Check the return value of ida_alloc() in case it fails.
This is found by a static checker.
---
 drivers/perf/fsl_imx9_ddr_perf.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/drivers/perf/fsl_imx9_ddr_perf.c b/drivers/perf/fsl_imx9_ddr_perf.c
index 843f163e6c33..226d5d13063f 100644
--- a/drivers/perf/fsl_imx9_ddr_perf.c
+++ b/drivers/perf/fsl_imx9_ddr_perf.c
@@ -789,7 +789,11 @@ static int ddr_perf_probe(struct platform_device *pdev)
 
 	platform_set_drvdata(pdev, pmu);
 
-	pmu->id = ida_alloc(&ddr_ida, GFP_KERNEL);
+	ret = ida_alloc(&ddr_ida, GFP_KERNEL);
+	if (ret < 0)
+		return ret;
+	pmu->id = ret;
+
 	name = devm_kasprintf(&pdev->dev, GFP_KERNEL, DDR_PERF_DEV_NAME "%d", pmu->id);
 	if (!name) {
 		ret = -ENOMEM;
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH v2 1/1] Add check to ida_alloc()
  2025-05-16  7:33   ` [PATCH v2 " Yuanjun Gong
@ 2025-05-16  8:42     ` Daniel Baluta
  2025-05-19 12:40       ` Will Deacon
  0 siblings, 1 reply; 5+ messages in thread
From: Daniel Baluta @ 2025-05-16  8:42 UTC (permalink / raw)
  To: Yuanjun Gong; +Cc: imx, Peng Fan, Will Deacon, Mark Rutland, Shawn Guo

On Fri, May 16, 2025 at 10:33 AM Yuanjun Gong <ruc_gongyuanjun@163.com> wrote:
>
> Check the return value of ida_alloc() in case it fails.
> This is found by a static checker.

Is it just me or I can't see the Signed-off-by tag here?

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH v2 1/1] Add check to ida_alloc()
  2025-05-16  8:42     ` Daniel Baluta
@ 2025-05-19 12:40       ` Will Deacon
  0 siblings, 0 replies; 5+ messages in thread
From: Will Deacon @ 2025-05-19 12:40 UTC (permalink / raw)
  To: Daniel Baluta; +Cc: Yuanjun Gong, imx, Peng Fan, Mark Rutland, Shawn Guo

On Fri, May 16, 2025 at 11:42:32AM +0300, Daniel Baluta wrote:
> On Fri, May 16, 2025 at 10:33 AM Yuanjun Gong <ruc_gongyuanjun@163.com> wrote:
> >
> > Check the return value of ida_alloc() in case it fails.
> > This is found by a static checker.
> 
> Is it just me or I can't see the Signed-off-by tag here?

Yuanjun -- please send a v3 with your SoB line added back.

Thanks,

Will

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2025-05-19 12:40 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-05-13 12:37 [PATCH 1/1] Add check to ida_alloc() Yuanjun Gong
2025-05-16  3:59 ` Peng Fan
2025-05-16  7:33   ` [PATCH v2 " Yuanjun Gong
2025-05-16  8:42     ` Daniel Baluta
2025-05-19 12:40       ` Will Deacon

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox