drivers/media/pci/intel/ivsc/mei_ace.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
The device reference counting in mei_ace_setup_dev_link() was
incomplete, as the reference acquired by device_find_child_by_name()
was not released immediately on the success path. Add put_device() to
properly balance the reference count. Additionally, the redundant
put_device() in mei_ace_remove() is removed.
Found by code review.
Signed-off-by: Ma Ke <make24@iscas.ac.cn>
---
Changes in v4:
- updated the subject as suggestions;
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
Hi Ma, Thanks for the update. On Tue, Sep 23, 2025 at 11:36:50AM +0800, Ma Ke wrote: > The device reference counting in mei_ace_setup_dev_link() was > incomplete, as the reference acquired by device_find_child_by_name() > was not released immediately on the success path. Add put_device() to I wouldn't say it's incomplete, that reference is put in the driver's remove function. The reference may be put right after calling device_link_add() as device_link_add() takes a reference already. So this patch would be a cleanup, not a fix. > properly balance the reference count. Additionally, the redundant > put_device() in mei_ace_remove() is removed. > > Found by code review. > > Signed-off-by: Ma Ke <make24@iscas.ac.cn> > --- > Changes in v4: > - updated the subject as suggestions; > 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)); I believe there's still extra put_device() call some lines below from here on the error path. > @@ -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); -- Regards, Sakari Ailus
© 2016 - 2025 Red Hat, Inc.