Linux Media Controller development
 help / color / mirror / Atom feed
From: Mehdi Djait <mehdi.djait@linux.intel.com>
To: "Vadillo, Miguel" <miguel.vadillo@intel.com>
Cc: linux-media@vger.kernel.org, wei.a.xu@intel.com,
	atul.raut@intel.com,  sakari.ailus@linux.intel.com,
	antti.laakso@linux.intel.com, kieran.bingham@ideasonboard.com
Subject: Re: [PATCH v3 1/3] media: i2c: cvs: Add driver of Intel Computer Vision Sensing Controller(CVS)
Date: Mon, 25 May 2026 10:36:38 +0200	[thread overview]
Message-ID: <ahQIk6QV9HRwxyyJ@mdjait-mobl> (raw)
In-Reply-To: <173d3eec-de57-43eb-ba46-d08c8c1dc8b2@intel.com>

Hi Miguel,

On Sat, May 23, 2026 at 04:37:41PM -0700, Vadillo, Miguel wrote:
> Hi Mehdi,
> 
> On 5/22/26 1:39 AM, Mehdi Djait wrote:
> > Hi Miguel,
> > 
> > Thank you for the patch.
> > 
> > On Thu, May 21, 2026 at 03:23:57PM -0700, Miguel Vadillo wrote:
> > > Add driver for Intel Computer Vision Sensing (CVS) devices found on
> > 
> > [..]
> > 
> > > +fail_i2c:
> > > +	ret = cvs_csi_init(ctx, dev, i2c);
> > > +	if (ret) {
> > > +		dev_err_probe(dev, ret, "CSI init failed\n");
> > > +		goto err_put_ipu;
> > > +	}
> > > +
> > > +	dev_set_drvdata(dev, ctx);
> > > +	pm_runtime_set_autosuspend_delay(dev, 1000);
> > > +	pm_runtime_use_autosuspend(dev);
> > > +	pm_runtime_enable(dev);
> > > +	pm_runtime_idle(dev);
> > > +
> > > +	/*
> > > +	 * Create a PM runtime device link with IPU as consumer and CVS as
> > > +	 * supplier. When the IPU runtime-resumes to start streaming, the PM
> > > +	 * framework automatically resumes CVS first, triggering
> > > +	 * cvs_runtime_resume() which hands CSI-2 link ownership to the host.
> > > +	 */
> > > +	ctx->ipu_link = device_link_add(&ipu->dev, dev,
> > > +					DL_FLAG_PM_RUNTIME |
> > > +					DL_FLAG_RPM_ACTIVE |
> > > +					DL_FLAG_STATELESS);
> > > +	put_device(&ipu->dev);
> > > +	if (!ctx->ipu_link) {
> > > +		dev_err(dev, "IPU device link failed\n");
> > > +		ret = -ENODEV;
> > > +		goto err_csi_remove;
> > > +	}
> > > +
> > > +	if (has_acpi_companion(dev))
> > > +		acpi_dev_clear_dependencies(ACPI_COMPANION(dev));
> > > +
> > > +	return 0;
> > > +
> > > +err_csi_remove:
> > > +	if (ctx->ipu_link)
> > > +		device_link_del(ctx->ipu_link);
> > > +	cvs_csi_remove(ctx);
> > > +	pm_runtime_dont_use_autosuspend(dev);
> > > +	pm_runtime_disable(dev);
> > > +	pm_runtime_set_suspended(dev);
> > > +	return ret;
> > 
> > this return ret seems wrong here.
> 
> Are you referring to just the space before return?
> @@ -1318,10 +1318,12 @@ static int cvs_core_probe(struct device *dev, struct
> i2c_client *i2c)
>         pm_runtime_dont_use_autosuspend(dev);
>         pm_runtime_disable(dev);
>         pm_runtime_set_suspended(dev);
> +
>         return ret;
> 
>  err_put_ipu:
>         put_device(&ipu->dev);
> +
>         return ret;
>  }
> 
> put_device(ipu) was already done after the ipu_link so no need to waterfall
> all the way down. Please clarify if I am misunderstanding your comment.

that's the expected code flow with goto err_x, goto err_y; -> That you do the
error handling in reverse order of allocation/init and then finish by return ret.

So in this case how about you hold on the the ipu-dev a bit longer,
remove the return ret of err_csi_remove and put_device() at the end if everything goes without error:

diff --git a/drivers/media/i2c/cvs/core.c b/drivers/media/i2c/cvs/core.c
index 9db56eb77645..b8d270c001b3 100644
--- a/drivers/media/i2c/cvs/core.c
+++ b/drivers/media/i2c/cvs/core.c
@@ -815,7 +815,6 @@ static int cvs_core_probe(struct device *dev, struct i2c_client *i2c)
                                        DL_FLAG_PM_RUNTIME |
                                        DL_FLAG_RPM_ACTIVE |
                                        DL_FLAG_STATELESS);
-       put_device(&ipu->dev);
        if (!ctx->ipu_link) {
                dev_err(dev, "IPU device link failed\n");
                ret = -ENODEV;
@@ -825,6 +824,8 @@ static int cvs_core_probe(struct device *dev, struct i2c_client *i2c)
        if (has_acpi_companion(dev))
                acpi_dev_clear_dependencies(ACPI_COMPANION(dev));
 
+       put_device(&ipu->dev);
+
        return 0;
 
 err_csi_remove:
@@ -834,7 +835,6 @@ static int cvs_core_probe(struct device *dev, struct i2c_client *i2c)
        pm_runtime_dont_use_autosuspend(dev);
        pm_runtime_disable(dev);
        pm_runtime_set_suspended(dev);
-       return ret;
 
 err_put_ipu:
        put_device(&ipu->dev);


(Actually if you want to go just a tiny bit the extra mile and see if we
can solve this without holding a reference to the dev for the whole
probe function will actually simplify the error handling a lot, this is
of course not a priority at all and I am ok with whatever you choose to
do)

--
Kind Regards
Mehdi Djait

  reply	other threads:[~2026-05-25  8:36 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-05-21 22:23 [PATCH v3 0/3] media: i2c: cvs: Add Intel CVS driver Miguel Vadillo
2026-05-21 22:23 ` [PATCH v3 1/3] media: i2c: cvs: Add driver of Intel Computer Vision Sensing Controller(CVS) Miguel Vadillo
2026-05-22  8:39   ` Mehdi Djait
2026-05-23 23:37     ` Vadillo, Miguel
2026-05-25  8:36       ` Mehdi Djait [this message]
2026-05-22 14:41   ` Mehdi Djait
2026-05-23 23:33     ` Vadillo, Miguel
2026-05-21 22:23 ` [PATCH v3 2/3] media: pci: intel: Add CVS support for IPU bridge driver Miguel Vadillo
2026-05-21 22:23 ` [PATCH v3 3/3] ACPI: scan: Honor _DEP for Intel CVS devices Miguel Vadillo

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=ahQIk6QV9HRwxyyJ@mdjait-mobl \
    --to=mehdi.djait@linux.intel.com \
    --cc=antti.laakso@linux.intel.com \
    --cc=atul.raut@intel.com \
    --cc=kieran.bingham@ideasonboard.com \
    --cc=linux-media@vger.kernel.org \
    --cc=miguel.vadillo@intel.com \
    --cc=sakari.ailus@linux.intel.com \
    --cc=wei.a.xu@intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox