From: Hans de Goede <hansg@kernel.org>
To: Sanjay Chitroda <sanjayembeddedse@gmail.com>,
sakari.ailus@linux.intel.com, mchehab@kernel.org
Cc: hverkuil+cisco@kernel.org, linux-media@vger.kernel.org,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH 1/3] media: i2c: gc0310: fix probe error handling and unwind resources properly
Date: Wed, 1 Apr 2026 21:06:33 +0200 [thread overview]
Message-ID: <38dc77ed-2427-44df-847d-4d41183e0df2@kernel.org> (raw)
In-Reply-To: <20260401181657.654055-2-sanjayembedded@gmail.com>
Hi,
On 1-Apr-26 20:16, Sanjay Chitroda wrote:
> From: Sanjay Chitroda <sanjayembeddedse@gmail.com>
>
> The GC0310 probe path currently performs error cleanup by jumping to a
> common label that mirrors the driver's remove() callback. This is unsafe,
> as remove() assumes that the subdevice has been fully registered with
> the V4L2 framework, media and control resources have been initialized.
That is simply not true, all functions called in remove() internally
check if their init counter-part has succeeded and if not are a no-op.
If you're aware of any specific calls in remove() where this is not
the case, please explicitly describe these cases and describe an
example exit-error path from probe() where things actually go wrong.
> Calling remove() from probe can result in unregistering or cleaning up
> subdevice, leading to resource leaks and subtle lifecycle bugs.
>
> Rewrite the probe() error handling to unwind resources explicitly, using
> fine‑grained goto labels along with appropriate error logs. Each failure
> path now frees only successfully acquired resource, without remove().
>
> This aligns the driver with standard V4L2 sensor lifecycle expectations
> and avoids incorrect teardown during probe failures.
The rest of this reads very much like this was AI generated.
Did you use AI to generate these patches ? If so please:
Make sure you actually understand what the patch is doing and
very yourself that it actually is correct, which in this case
I believe it is not.
Regards,
Hans
>
> Fixes: 1e72afb5146a ("media: Move gc0310 sensor drivers to drivers/media/i2c/")
> Signed-off-by: Sanjay Chitroda <sanjayembeddedse@gmail.com>
> ---
> drivers/media/i2c/gc0310.c | 39 ++++++++++++++++++++++++++++----------
> 1 file changed, 29 insertions(+), 10 deletions(-)
>
> diff --git a/drivers/media/i2c/gc0310.c b/drivers/media/i2c/gc0310.c
> index 7af4d66f42a0..72a82ad4118a 100644
> --- a/drivers/media/i2c/gc0310.c
> +++ b/drivers/media/i2c/gc0310.c
> @@ -721,7 +721,7 @@ static int gc0310_probe(struct i2c_client *client)
>
> ret = gc0310_detect(sensor);
> if (ret)
> - goto err_power_down;
> + goto error_power_off;
>
> sensor->sd.internal_ops = &gc0310_internal_ops;
> sensor->sd.flags |= V4L2_SUBDEV_FL_HAS_DEVNODE;
> @@ -730,20 +730,27 @@ static int gc0310_probe(struct i2c_client *client)
>
> ret = gc0310_init_controls(sensor);
> if (ret)
> - goto err_power_down;
> + goto error_power_off;
>
> ret = media_entity_pads_init(&sensor->sd.entity, 1, &sensor->pad);
> - if (ret)
> - goto err_power_down;
> + if (ret) {
> + dev_err_probe(&client->dev, ret, "failed to init entity pads\n");
> + goto error_handler_free;
> + }
>
> sensor->sd.state_lock = sensor->ctrls.handler.lock;
> ret = v4l2_subdev_init_finalize(&sensor->sd);
> - if (ret)
> - goto err_power_down;
> + if (ret) {
> + dev_err_probe(&client->dev, ret, "subdev init error\n");
> + goto error_media_entity;
> + }
>
> ret = v4l2_async_register_subdev_sensor(&sensor->sd);
> - if (ret)
> - goto err_power_down;
> + if (ret) {
> + dev_err_probe(&client->dev, ret,
> + "failed to register gc0310 sub-device\n");
> + goto error_subdev_cleanup;
> + }
>
> pm_runtime_set_autosuspend_delay(&client->dev, 1000);
> pm_runtime_use_autosuspend(&client->dev);
> @@ -751,9 +758,21 @@ static int gc0310_probe(struct i2c_client *client)
>
> return 0;
>
> -err_power_down:
> +error_subdev_cleanup:
> + v4l2_subdev_cleanup(&sensor->sd);
> + pm_runtime_disable(&client->dev);
> + pm_runtime_set_suspended(&client->dev);
> +
> +error_media_entity:
> + media_entity_cleanup(&sensor->sd.entity);
> +
> +error_handler_free:
> + v4l2_ctrl_handler_free(&sensor->ctrls.handler);
> +
> +error_power_off:
> pm_runtime_put_noidle(&client->dev);
> - gc0310_remove(client);
> + gc0310_power_off(&client->dev);
> +
> return ret;
> }
>
next prev parent reply other threads:[~2026-04-01 19:06 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-04-01 18:16 [PATCH 0/3] media: i2c: gc0310: cleanups and sensor clock handling improvements Sanjay Chitroda
2026-04-01 18:16 ` [PATCH 1/3] media: i2c: gc0310: fix probe error handling and unwind resources properly Sanjay Chitroda
2026-04-01 19:06 ` Hans de Goede [this message]
2026-04-05 10:16 ` Sanjay Chitroda
2026-04-06 16:09 ` Hans de Goede
2026-04-07 4:32 ` Sanjay Chitroda
2026-04-01 18:16 ` [PATCH 2/3] media: i2c: gc0310: use cached client and device pointers Sanjay Chitroda
2026-04-01 19:08 ` Hans de Goede
2026-04-05 11:01 ` Sanjay Chitroda
2026-04-01 18:16 ` [PATCH 3/3] media: i2c: gc0310: Use devm_v4l2_sensor_clk_get() Sanjay Chitroda
2026-04-01 19:20 ` Hans de Goede
2026-04-19 7:38 ` Sanjay Chitroda
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=38dc77ed-2427-44df-847d-4d41183e0df2@kernel.org \
--to=hansg@kernel.org \
--cc=hverkuil+cisco@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-media@vger.kernel.org \
--cc=mchehab@kernel.org \
--cc=sakari.ailus@linux.intel.com \
--cc=sanjayembeddedse@gmail.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