Skip to contentSkip to conversation

media: chips-media: wave5: Fix possible ERR_PTR deference

PATCH In review Alper Ak 4 participants 9 messages Feb 7 – Oct 21 1 message not in the archive

Subsystems (2)
lore
Share & tools
lore

Alper Ak

author
#0 lore raw

PATCH 1/1 media: chips-media: wave5: Fix possible ERR_PTR deference

The kthread_run() function returns either a valid task_struct pointer or ERR_PTR() on failure. The return value was not checked and in the error cleanup path, the code verifies if dev->irq_thread is non NULL before calling kthread_stop(). Since ERR_PTR() values are non NULL, this would result in passing an error pointer to kthread_stop(), causing a kernel panic.

Add proper IS_ERR() check after kthread_run(), log the error, set dev->irq_thread to NULL and fail the probe to prevent the driver from operating in a broken state.

Fixes e66ff2b08e4e ("media: chips-media: wave5: Fix Null reference while testing fluster")
---
 drivers/media/platform/chips-media/wave5/wave5-vpu.c | 6 ++++++
 1 file changed, 6 insertions(+)
drivers/media/platform/chips-media/wave5/wave5-vpu.c +6 -0
index 76d57c6b636a..bebe2bd6893b 100644
@@ -340,6 +340,12 @@ static int wave5_vpu_probe(struct platform_device *pdev)
 		dev_err(&pdev->dev, "failed to get irq resource, falling back to polling\n");
 		sema_init(&dev->irq_sem, 1);
 		dev->irq_thread = kthread_run(irq_thread, dev, "irq thread");
+		if (IS_ERR(dev->irq_thread)) {
+			dev_err(&pdev->dev, "failed to create vpu irq thread\n");
+			ret = PTR_ERR(dev->irq_thread);
+			dev->irq_thread = NULL;
+			goto err_vdi_release;
+		}
 		hrtimer_setup(&dev->hrtimer, &wave5_vpu_timer_callback, CLOCK_MONOTONIC,
 			      HRTIMER_MODE_REL_PINNED);
 		dev->worker = kthread_run_worker(0, "vpu_irq_thread");
Signature · 1 line
2.43.0
maintainer Acked-by on v1 1/1
#1 lore raw

Hi, Alper.

Thanks for the patch.

Quoted 37 lines

-----Original Message-----
From: Alper Ak <[email protected]>
Sent: Saturday, February 7, 2026 7:32 PM
To: Nas Chung <[email protected]>; jackson.lee <[email protected]>
Cc: Mauro Carvalho Chehab <[email protected]>; Nicolas Dufresne <[email protected]>; Hans Verkuil <[email protected]>; [email protected]; [email protected]; Alper Ak <[email protected]>
Subject: [PATCH] media: chips-media: wave5: Fix possible ERR_PTR deference

The kthread_run() function returns either a valid task_struct pointer or ERR_PTR() on failure. The return value was not checked and in the error cleanup path, the code verifies if dev->irq_thread is non NULL before calling kthread_stop(). Since ERR_PTR() values are non NULL, this would result in passing an error pointer to kthread_stop(), causing a kernel panic.

Add proper IS_ERR() check after kthread_run(), log the error, set dev->irq_thread to NULL and fail the probe to prevent the driver from operating in a broken state.

Fixes e66ff2b08e4e ("media: chips-media: wave5: Fix Null reference while

testing fluster")

---
drivers/media/platform/chips-media/wave5/wave5-vpu.c | 6 ++++++

1 file changed, 6 insertions(+)
drivers/media/platform/chips-media/wave5/wave5-vpu.c +0 -0
index 76d57c6b636a..bebe2bd6893b 100644
@@ -340,6 +340,12 @@ static int wave5_vpu_probe(struct platform_device
 *pdev)
 		dev_err(&pdev->dev, "failed to get irq resource, falling back

drivers/media/platform/chips-media/wave5/wave5-vpu.c static int wave5_vpu_probe(struct platform_device · line 351

Quoted 10 lines
drivers/media/platform/chips-media/wave5/wave5-vpu.c +6 -0
 to polling\n");
 		sema_init(&dev->irq_sem, 1);
 		dev->irq_thread = kthread_run(irq_thread, dev, "irq thread");
+		if (IS_ERR(dev->irq_thread)) {
+			dev_err(&pdev->dev, "failed to create vpu irq
 thread\n");
+			ret = PTR_ERR(dev->irq_thread);
+			dev->irq_thread = NULL;
+			goto err_vdi_release;
+		}

I also ran smatch locally but couldn't reproduce the warning. Could you share the exact test command you used ?

That said, The fix looks correct to me.

Thanks.
Nas.

Quoted 6 lines
		hrtimer_setup(&dev->hrtimer, &wave5_vpu_timer_callback,
CLOCK_MONOTONIC,
			      HRTIMER_MODE_REL_PINNED);
		dev->worker = kthread_run_worker(0, "vpu_irq_thread");

--
2.43.0

A message that is not in the archive (sent off-list or not yet received): CAGpma=5ONpUwnOStE+cLpJcqrb-=ZYT4krx=whgeAup1ACERQg@mail.gmail.com

maintainer Tested-by
#3 lore raw

Hi, Alper.

Quoted 17 lines

-----Original Message-----
From: Alper Ak <[email protected]>
Sent: Wednesday, February 11, 2026 6:42 PM
To: Nas Chung <[email protected]>
Cc: jackson.lee <[email protected]>; Mauro Carvalho Chehab <[email protected]>; Nicolas Dufresne <[email protected]>; Hans Verkuil <[email protected]>; [email protected]; [email protected]
Subject: Re: [PATCH] media: chips-media: wave5: Fix possible ERR_PTR deference

Hi,

I usually run smatch with the kernel cross function database enabled. It collects return value propagation, function call relationships, assignments, etc. The database is incremental and grows over multiple rebuilds.

Quoted 5 lines

The steps I used were:
• Build the database:
~/smatch/smatch_scripts/build_kernel_data.sh
• Run smatch on the whole kernel:
~/smatch/smatch_scripts/test_kernel.sh

Thanks for the test command.

Quoted 3 lines

After applying the fix, I verified that the warning was gone with:

~/smatch/smatch_scripts/kchecker drivers/whatever/file.c

I reproduced the issue with the same command, and this patch fixes it.

Thanks.
Nas.

Quoted 77 lines

If smatch is run directly on a single file without building the database first, the warning might not be reproduced.
Best regards,
Alper Ak

Nas Chung <[email protected]>, 11 Şub 2026 Çar, 12:12 tarihinde şunu yazdı:
Hi, Alper.

Thanks for the patch.

Quoted 39 lines

-----Original Message-----
From: Alper Ak <[email protected]>
Sent: Saturday, February 7, 2026 7:32 PM
To: Nas Chung <[email protected]>; jackson.lee <[email protected]>
Cc: Mauro Carvalho Chehab <[email protected]>; Nicolas Dufresne <[email protected]>; Hans Verkuil <[email protected]>; [email protected]; [email protected]; Alper Ak <[email protected]>
Subject: [PATCH] media: chips-media: wave5: Fix possible ERR_PTR deference

The kthread_run() function returns either a valid task_struct pointer or ERR_PTR() on failure. The return value was not checked and in the error cleanup path, the code verifies if dev->irq_thread is non NULL before calling kthread_stop(). Since ERR_PTR() values are non NULL, this would result in passing an error pointer to kthread_stop(), causing a kernel panic.

Add proper IS_ERR() check after kthread_run(), log the error, set dev->irq_thread to NULL and fail the probe to prevent the driver from operating in a broken state.

Fixes e66ff2b08e4e ("media: chips-media: wave5: Fix Null reference while

testing fluster")

---
drivers/media/platform/chips-media/wave5/wave5-vpu.c | 6 ++++++

1 file changed, 6 insertions(+)
drivers/media/platform/chips-media/wave5/wave5-vpu.c +0 -0
index 76d57c6b636a..bebe2bd6893b 100644
@@ -340,6 +340,12 @@ static int wave5_vpu_probe(struct platform_device
 *pdev)

               dev_err(&pdev->dev, "failed to get irq resource, falling back to polling\n");
               sema_init(&dev->irq_sem, 1);

Quoted 8 lines

               dev->irq_thread = kthread_run(irq_thread, dev, "irq thread"); +              if (IS_ERR(dev->irq_thread)) {
+                      dev_err(&pdev->dev, "failed to create vpu irq thread\n");
+                      ret = PTR_ERR(dev->irq_thread);
+                      dev->irq_thread = NULL;
+                      goto err_vdi_release;
+              }

I also ran smatch locally but couldn't reproduce the warning. Could you share the exact test command you used ?

That said, The fix looks correct to me.

Thanks.
Nas.

Quoted 6 lines

               hrtimer_setup(&dev->hrtimer, &wave5_vpu_timer_callback, CLOCK_MONOTONIC,
                             HRTIMER_MODE_REL_PINNED); dev->worker = kthread_run_worker(0, "vpu_irq_thread"); --
2.43.0

#4 lore raw
In reply to Alper Ak

…

Quoted 1 line

or ERR_PTR() on failure. The return value was not checked and in the

error pointer

…

Quoted 3 lines

Add proper IS_ERR() check after kthread_run(), log the error, set dev->irq_thread to NULL and fail the probe to prevent the driver from operating in a broken state.

…

See also once more:
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/process/stable-kernel-rules.rst?h=v6.19#n34

Would a summary phrase like “Prevent error pointer dereference in wave5_vpu_probe()” be more appropriate?

Regards,
Markus

author
#5 lore raw

Hello everyone, look like this patch hasn't been applied. Did I miss something I needed to do to get it applied? If there is anything I need to do, please let me know.

Markus Elfring <[email protected]>, 13 Şub 2026 Cum, 14:38 tarihinde şunu yazdı:

Quoted 21 lines

…

Quoted 1 line

or ERR_PTR() on failure. The return value was not checked and in the

error pointer

…

Quoted 3 lines

Add proper IS_ERR() check after kthread_run(), log the error, set dev->irq_thread to NULL and fail the probe to prevent the driver from operating in a broken state.

…

See also once more:
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/process/stable-kernel-rules.rst?h=v6.19#n34

Would a summary phrase like “Prevent error pointer dereference in wave5_vpu_probe()” be more appropriate?

Regards,
Markus

#6 lore raw
Quoted 3 lines

Hello everyone, look like this patch hasn't been applied. Did I miss something I needed to do to get it applied? If there is anything I need to do, please let me know.

* Would you like to avoid a typo in the summary phrase?

* Will any patch review concerns get more attention?

Regards,
Markus

#7 lore raw
In reply to Alper Ak

Hi,

Le vendredi 06 mars 2026 à 09:32 +0300, Alper Ak a écrit :

Quoted 3 lines

Hello everyone, look like this patch hasn't been applied. Did I miss something I needed to do to get it applied? If there is anything I need to do, please let me know.

You received an Ack from the maintainer, and got a tested buy. But the patch has been submitted while the merge window was closed, which is fine, but means there is a small delay. It should be processed within the next two weeks. Your subject suggest a theoretical bug, so it has not be been prioritized over other patches in the queue.

regards,
Nicolas

Quoted 25 lines

Markus Elfring <[email protected]>, 13 Şub 2026 Cum, 14:38 tarihinde şunu yazdı:

Quoted 22 lines

…

Quoted 1 line

or ERR_PTR() on failure. The return value was not checked and in the

     error pointer

…

Quoted 3 lines

Add proper IS_ERR() check after kthread_run(), log the error, set dev->irq_thread to NULL and fail the probe to prevent the driver from operating in a broken state.

…

See also once more:
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/process/stable-kernel-rules.rst?h=v6.19#n34

Would a summary phrase like “Prevent error pointer dereference in wave5_vpu_probe()”
be more appropriate?

Regards,
Markus

#8 lore raw

Hi,

Le vendredi 06 mars 2026 à 08:50 -0500, Nicolas Dufresne a écrit :

Quoted 7 lines

Hi,

Le vendredi 06 mars 2026 à 09:32 +0300, Alper Ak a écrit :

Quoted 3 lines

Hello everyone, look like this patch hasn't been applied. Did I miss something I needed to do to get it applied? If there is anything I need to do, please let me know.

Quoted 5 lines

You received an Ack from the maintainer, and got a tested buy. But the patch has been submitted while the merge window was closed, which is fine, but means there is a small delay. It should be processed within the next two weeks. Your subject suggest a theoretical bug, so it has not be been prioritized over other patches in the queue.

I discovered now that I missed this one in latest fixes batchs, be reassured that its not assigned to me in patchwork and will be applied soon.

Nicolas

Quoted 29 lines

regards,
Nicolas

Quoted 25 lines

Markus Elfring <[email protected]>, 13 Şub 2026 Cum, 14:38 tarihinde şunu yazdı:

Quoted 22 lines

…

Quoted 1 line

or ERR_PTR() on failure. The return value was not checked and in the

     error pointer

…

Quoted 3 lines

Add proper IS_ERR() check after kthread_run(), log the error, set dev->irq_thread to NULL and fail the probe to prevent the driver from operating in a broken state.

…

See also once more:
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/process/stable-kernel-rules.rst?h=v6.19#n34

Would a summary phrase like “Prevent error pointer dereference in wave5_vpu_probe()”
be more appropriate?

Regards,
Markus

#9 lore raw
Quoted 2 lines

I discovered now that I missed this one in latest fixes batchs, be reassured that its not assigned to me in patchwork and will be applied soon.

Do any contributors care still for remaining patch review concerns?

Regards,
Markus