From: Biren Pandya <birenpandya@gmail.com>
To: Sakari Ailus <sakari.ailus@linux.intel.com>,
Mauro Carvalho Chehab <mchehab@kernel.org>,
linux-media@vger.kernel.org
Cc: linux-kernel@vger.kernel.org, Biren Pandya <birenpandya@gmail.com>
Subject: [PATCH 2/2] media: i2c: ov7740: Fix unchecked pm_runtime_get_sync() in remove()
Date: Tue, 16 Jun 2026 02:34:12 +0530 [thread overview]
Message-ID: <20260615210412.34567-3-birenpandya@gmail.com> (raw)
In-Reply-To: <20260615210412.34567-1-birenpandya@gmail.com>
The ov7740_remove() function unconditionally called pm_runtime_get_sync()
but completely ignored the return value. If the device was already in an
error state or disconnected, this could lead to an unbalanced PM runtime
usage count or attempt to communicate with an unresponsive device.
Replace pm_runtime_get_sync() with pm_runtime_resume_and_get() to ensure
the device actually resumed before attempting to issue I2C power-off
commands, and safely put the PM runtime usage counter.
Signed-off-by: Biren Pandya <birenpandya@gmail.com>
---
drivers/media/i2c/ov7740.c | 9 ++++++---
1 file changed, 6 insertions(+), 3 deletions(-)
diff --git a/drivers/media/i2c/ov7740.c b/drivers/media/i2c/ov7740.c
index 62c124a1353a..6b81882da307 100644
--- a/drivers/media/i2c/ov7740.c
+++ b/drivers/media/i2c/ov7740.c
@@ -1115,17 +1115,20 @@ static void ov7740_remove(struct i2c_client *client)
{
struct v4l2_subdev *sd = i2c_get_clientdata(client);
struct ov7740 *ov7740 = container_of(sd, struct ov7740, subdev);
+ int ret;
v4l2_async_unregister_subdev(sd);
media_entity_cleanup(&ov7740->subdev.entity);
ov7740_free_controls(ov7740);
- pm_runtime_get_sync(&client->dev);
+ ret = pm_runtime_resume_and_get(&client->dev);
pm_runtime_disable(&client->dev);
pm_runtime_set_suspended(&client->dev);
- pm_runtime_put_noidle(&client->dev);
- ov7740_set_power(ov7740, 0);
+ if (ret >= 0) {
+ ov7740_set_power(ov7740, 0);
+ pm_runtime_put_noidle(&client->dev);
+ }
}
static int __maybe_unused ov7740_runtime_suspend(struct device *dev)
--
2.50.1 (Apple Git-155)
next prev parent reply other threads:[~2026-06-15 21:04 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-06-15 21:04 [PATCH 0/2] media: i2c: ov7740: Fix remove() teardown and PM runtime Biren Pandya
2026-06-15 21:04 ` [PATCH 1/2] media: i2c: ov7740: Fix use-after-destroy in remove() Biren Pandya
2026-07-08 8:59 ` Sakari Ailus
2026-06-15 21:04 ` Biren Pandya [this message]
2026-07-08 8:46 ` [PATCH 2/2] media: i2c: ov7740: Fix unchecked pm_runtime_get_sync() " Sakari Ailus
[not found] ` <20260708125720.27156-4-birenpandya@gmail.com>
2026-07-08 12:57 ` [PATCH v2 1/2] media: i2c: ov7740: fix unbalanced pm_runtime_get_sync in remove Biren Pandya
2026-07-08 12:57 ` [PATCH v2 2/2] media: i2c: ov7740: fix use-after-destroy " Biren Pandya
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=20260615210412.34567-3-birenpandya@gmail.com \
--to=birenpandya@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-media@vger.kernel.org \
--cc=mchehab@kernel.org \
--cc=sakari.ailus@linux.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