mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH v3] media: pci: intel: ivsc: fix error handling in mei_ace driver
@ 2025-09-23  2:09 Ma Ke
  2025-09-23  3:06 ` Cao, Bingbu
  0 siblings, 1 reply; 2+ messages in thread
From: Ma Ke @ 2025-09-23  2:09 UTC (permalink / raw)
  To: sakari.ailus, bingbu.cao, lixu.zhang, stanislaw.gruszka, mchehab
  Cc: linux-media, linux-kernel, akpm, Ma Ke

The mei_ace driver contains a device reference count leak in
mei_ace_setup_dev_link() where device_find_child_by_name() increases
the reference count of the found device but this reference is not
properly decreased in the success path. Add put_device() in
mei_ace_setup_dev_link() and delete put_device() in mei_ace_remove(),
which ensures that the reference count of the device is correctly
managed regardless of whether the probe is successful or fails.

Found by code review.

Signed-off-by: Ma Ke <make24@iscas.ac.cn>
---
Changes in v3:
- deleted the tag of Fixes and CC, and moved put_device() to immediately after device_link_add() as suggestions;
Changes in v2:
- modified the put_device() operations and the patch title as suggestions.
---
 drivers/media/pci/intel/ivsc/mei_ace.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/media/pci/intel/ivsc/mei_ace.c b/drivers/media/pci/intel/ivsc/mei_ace.c
index 98310b8511b1..9969c02da671 100644
--- a/drivers/media/pci/intel/ivsc/mei_ace.c
+++ b/drivers/media/pci/intel/ivsc/mei_ace.c
@@ -414,6 +414,7 @@ static int mei_ace_setup_dev_link(struct mei_ace *ace)
 	/* setup link between mei_ace and mei_csi */
 	ace->csi_link = device_link_add(csi_dev, dev, DL_FLAG_PM_RUNTIME |
 					DL_FLAG_RPM_ACTIVE | DL_FLAG_STATELESS);
+	put_device(csi_dev);
 	if (!ace->csi_link) {
 		ret = -EINVAL;
 		dev_err(dev, "failed to link to %s\n", dev_name(csi_dev));
@@ -522,7 +523,6 @@ static void mei_ace_remove(struct mei_cl_device *cldev)
 	cancel_work_sync(&ace->work);
 
 	device_link_del(ace->csi_link);
-	put_device(ace->csi_dev);
 
 	pm_runtime_disable(&cldev->dev);
 	pm_runtime_set_suspended(&cldev->dev);
-- 
2.17.1


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

* RE: [PATCH v3] media: pci: intel: ivsc: fix error handling in mei_ace driver
  2025-09-23  2:09 [PATCH v3] media: pci: intel: ivsc: fix error handling in mei_ace driver Ma Ke
@ 2025-09-23  3:06 ` Cao, Bingbu
  0 siblings, 0 replies; 2+ messages in thread
From: Cao, Bingbu @ 2025-09-23  3:06 UTC (permalink / raw)
  To: Ma Ke, sakari.ailus, Zhang, Lixu, stanislaw.gruszka, mchehab
  Cc: linux-media, linux-kernel, akpm

Hi, Ke

Better update the subject, it's not related to error handling.

------------------------------------------------------------------------
BRs,  
Bingbu Cao

>-----Original Message-----
>From: Ma Ke <make24@iscas.ac.cn>
>Sent: Tuesday, September 23, 2025 10:10 AM
>To: sakari.ailus@linux.intel.com; Cao, Bingbu <bingbu.cao@intel.com>;
>Zhang, Lixu <lixu.zhang@intel.com>; stanislaw.gruszka@linux.intel.com;
>mchehab@kernel.org
>Cc: linux-media@vger.kernel.org; linux-kernel@vger.kernel.org;
>akpm@linux-foundation.org; Ma Ke <make24@iscas.ac.cn>
>Subject: [PATCH v3] media: pci: intel: ivsc: fix error handling in
>mei_ace driver
>
>The mei_ace driver contains a device reference count leak in
>mei_ace_setup_dev_link() where device_find_child_by_name() increases
>the reference count of the found device but this reference is not
>properly decreased in the success path. Add put_device() in
>mei_ace_setup_dev_link() and delete put_device() in mei_ace_remove(),
>which ensures that the reference count of the device is correctly
>managed regardless of whether the probe is successful or fails.
>
>Found by code review.
>
>Signed-off-by: Ma Ke <make24@iscas.ac.cn>
>---
>Changes in v3:
>- deleted the tag of Fixes and CC, and moved put_device() to
>immediately after device_link_add() as suggestions; Changes in v2:
>- modified the put_device() operations and the patch title as
>suggestions.
>---
> drivers/media/pci/intel/ivsc/mei_ace.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
>diff --git a/drivers/media/pci/intel/ivsc/mei_ace.c
>b/drivers/media/pci/intel/ivsc/mei_ace.c
>index 98310b8511b1..9969c02da671 100644
>--- a/drivers/media/pci/intel/ivsc/mei_ace.c
>+++ b/drivers/media/pci/intel/ivsc/mei_ace.c
>@@ -414,6 +414,7 @@ static int mei_ace_setup_dev_link(struct mei_ace
>*ace)
> 	/* setup link between mei_ace and mei_csi */
> 	ace->csi_link = device_link_add(csi_dev, dev, DL_FLAG_PM_RUNTIME
>|
> 					DL_FLAG_RPM_ACTIVE |
>DL_FLAG_STATELESS);
>+	put_device(csi_dev);
> 	if (!ace->csi_link) {
> 		ret = -EINVAL;
> 		dev_err(dev, "failed to link to %s\n", dev_name(csi_dev));
>@@ -522,7 +523,6 @@ static void mei_ace_remove(struct mei_cl_device
>*cldev)
> 	cancel_work_sync(&ace->work);
>
> 	device_link_del(ace->csi_link);
>-	put_device(ace->csi_dev);
>
> 	pm_runtime_disable(&cldev->dev);
> 	pm_runtime_set_suspended(&cldev->dev);
>--
>2.17.1


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

end of thread, other threads:[~2025-09-23  3:06 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-09-23  2:09 [PATCH v3] media: pci: intel: ivsc: fix error handling in mei_ace driver Ma Ke
2025-09-23  3:06 ` Cao, Bingbu

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

all inboxes | Powered by JetHome®