From: Tarang Raval tarang.raval@siliconsignals.io
[ Upstream commit b493cd3c03641f9bbaa9787e43ca92163cb50051 ]
pm_runtime_suspended() only checks the current runtime PM status and does not modify it, making it ineffective in this context. This could result in improper power management if the device remains active when removed.
This patch fixes the issue by introducing a check with pm_runtime_status_suspended() to determine if the device is already suspended. If it is not, it calls imx334_power_off() to power down the device and then uses pm_runtime_set_suspended() to correctly update the runtime PM status to suspended.
Signed-off-by: Tarang Raval tarang.raval@siliconsignals.io Signed-off-by: Sakari Ailus sakari.ailus@linux.intel.com Signed-off-by: Hans Verkuil hverkuil@xs4all.nl Signed-off-by: Sasha Levin sashal@kernel.org ---
**YES** This commit should **definitely** be backported to stable kernel trees. Here's my extensive analysis: ## Bug Analysis **The Core Issue**: Line 1435 in the current `imx334_remove()` function contains a critical bug: ```c pm_runtime_suspended(&client->dev); // WRONG - this is a boolean query function ``` This should be: ```c pm_runtime_set_suspended(&client->dev); // CORRECT - this sets the PM state ``` ## Evidence from Code Analysis 1. **Function Signature Mismatch**: - `pm_runtime_suspended()` returns `bool` and only **queries** the current state - `pm_runtime_set_suspended()` returns `void` and **modifies** the runtime PM state 2. **Comparison with Similar Drivers**: Every other IMX sensor driver in the kernel uses the correct pattern: - **imx290.c**: `pm_runtime_set_suspended(imx290->dev);` - **imx258.c**: `pm_runtime_set_suspended(&client->dev);` - **imx412.c**: `pm_runtime_set_suspended(&client->dev);` - **imx274.c**: `pm_runtime_set_suspended(&client->dev);` - **imx415.c**: `pm_runtime_set_suspended(&client->dev);` 3. **Missing Power Management**: The current imx334 driver fails to ensure the device is powered off during removal, unlike the established pattern: ```c if (!pm_runtime_status_suspended(&client->dev)) { imx334_power_off(&client->dev); pm_runtime_set_suspended(&client->dev); } ``` ## Impact Assessment **Why This Is Critical for Stable Backporting**: 1. **Resource Leaks**: If the device is powered on during removal, the clock (`imx334->inclk`) and GPIO resources may not be properly released, leading to resource leaks. 2. **Runtime PM State Corruption**: The kernel's runtime PM subsystem maintains internal state that becomes inconsistent when `pm_runtime_suspended()` is called instead of `pm_runtime_set_suspended()`. 3. **Driver Reload Issues**: If the driver is unloaded and reloaded, the inconsistent PM state can cause subsequent power management operations to fail. 4. **System Power Management**: Improper PM cleanup can affect system-wide power management, potentially preventing proper suspend/resume cycles. ## Stable Tree Suitability Criteria ✅ **Fixes a clear bug**: Yes - wrong function call causing runtime PM state corruption ✅ **Small and contained**: Yes - 3-line change in one function ✅ **Minimal regression risk**: Yes - follows established patterns from other drivers ✅ **Important bugfix**: Yes - affects device cleanup and system stability ✅ **No architectural changes**: Yes - simple correction to existing code ✅ **Follows similar pattern**: Yes - matches Similar Commit #2 which was marked "YES" ## Comparison with Similar Commits This commit closely matches **Similar Commit #2** (CCS driver runtime PM fix) which was marked for backporting because it: - Fixed runtime PM status handling in remove function - Had minimal risk and clear benefit - Followed established patterns The commit is much more suitable than **Similar Commits #1, #3, #4, #5** which were marked "NO" because they involved: - Code cleanup/refactoring (#1) - Redundant code removal (#3) - Complex error handling changes (#4) - Major feature additions (#5) ## Conclusion This is a textbook example of a stable tree candidate: it fixes a clear, impactful bug with minimal code change and follows well-established patterns. The fix prevents resource leaks and runtime PM state corruption that can affect system stability.
drivers/media/i2c/imx334.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/drivers/media/i2c/imx334.c b/drivers/media/i2c/imx334.c index b51721c01e1d6..63d812a41542f 100644 --- a/drivers/media/i2c/imx334.c +++ b/drivers/media/i2c/imx334.c @@ -1435,7 +1435,10 @@ static void imx334_remove(struct i2c_client *client) v4l2_ctrl_handler_free(sd->ctrl_handler);
pm_runtime_disable(&client->dev); - pm_runtime_suspended(&client->dev); + if (!pm_runtime_status_suspended(&client->dev)) { + imx334_power_off(&client->dev); + pm_runtime_set_suspended(&client->dev); + }
mutex_destroy(&imx334->mutex); }