media: bcm2835-unicam: Fix log status runtime access
Subsystems (4)
PATCH v2 1/1 media: bcm2835-unicam: Fix log status runtime access
When requesting log status, the block might be powered off, but registers are being read.
Avoid reading the registers if the device is not resumed, thus also avoid powering up the device just for log status.
---
Changes in v2:
- changed to use pm_runtime_get_if_active()
- add corresponding put()
- Link to v1: https://patch.msgid.link/[email protected]
To: Raspberry Pi Kernel Maintenance <[email protected]>
To: Mauro Carvalho Chehab <[email protected]>
To: Florian Fainelli <[email protected]>
To: Ray Jui <[email protected]>
To: Scott Branden <[email protected]>
To: Broadcom internal kernel review list <[email protected]>
To: Sakari Ailus <[email protected]>
To: Jean-Michel Hautbois <[email protected]>
To: Laurent Pinchart <[email protected]>
To: Hans Verkuil <[email protected]>
To: Naushir Patuck <[email protected]>
Cc: Dave Stevenson <[email protected]>
Cc: [email protected]
Cc: [email protected]
Cc: [email protected]
Cc: [email protected]
--- drivers/media/platform/broadcom/bcm2835-unicam.c | 9 +++++++++ 1 file changed, 9 insertions(+)
drivers/media/platform/broadcom/bcm2835-unicam.c +9 -0
@@ -2052,6 +2052,13 @@ static int unicam_log_status(struct file *file, void *fh) node->fmt.fmt.pix.width, node->fmt.fmt.pix.height);dev_info (unicam->dev,"V4L2 format: %08x\n" , node->fmt.fmt.pix.pixelformat); + +if (!pm_runtime_get_if_active (unicam->dev)) { +dev_info (unicam->dev, +"Live data N/A due to device inactive\n" ); +return 0 ; + } + reg =unicam_reg_read (unicam,UNICAM_IPIPE ); dev_info(unicam->dev, "Unpacking/packing: %u / %u\n", unicam_get_field(reg, UNICAM_PUM_MASK),
@@ -2065,6 +2072,8 @@ static int unicam_log_status(struct file *file, void *fh)dev_info (unicam->dev,"Write pointer: %08x\n" ,unicam_reg_read (unicam,UNICAM_IBWP )); +pm_runtime_put (unicam->dev); +return 0 ; }
---
base-commit: e98d21c170b01ddef366f023bbfcf6b31509fa83
change-id: 20260521-bcmpipm-6c578e73239c
Best regards,
Signature · 1 line
Eugen Hristev <[email protected]>
Hi Eugen
Quoted 8 lines · Eugen Hristev
When requesting log status, the block might be powered off, but registers are being read.
Avoid reading the registers if the device is not resumed, thus also avoid powering up the device just for log status.Fixes 392cd78d495f ("media: bcm2835-unicam: Add support for CCP2/CSI2 camera interface")Signed-off-by Eugen Hristev <[email protected]>
Thanks.
Quoted 62 lines
---
Changes in v2:
- changed to usepm_runtime_get_if_active()
- add correspondingput()
- Link to v1: https://patch.msgid.link/[email protected]To: Raspberry Pi Kernel Maintenance <[email protected]>
To: Mauro Carvalho Chehab <[email protected]>
To: Florian Fainelli <[email protected]>
To: Ray Jui <[email protected]>
To: Scott Branden <[email protected]>
To: Broadcom internal kernel review list <[email protected]>
To: Sakari Ailus <[email protected]>
To: Jean-Michel Hautbois <[email protected]>
To: Laurent Pinchart <[email protected]>
To: Hans Verkuil <[email protected]>
To: Naushir Patuck <[email protected]>
Cc: Dave Stevenson <[email protected]>
Cc: [email protected]
Cc: [email protected]
Cc: [email protected]
Cc: [email protected]--- drivers/media/platform/broadcom/bcm2835-unicam.c | 9 +++++++++ 1 file changed, 9 insertions(+)drivers/media/platform/broadcom/bcm2835-unicam.c +9
-1@@ -2052,6 +2052,13 @@ static int unicam_log_status(struct file *file, void *fh) node->fmt.fmt.pix.width, node->fmt.fmt.pix.height);dev_info (unicam->dev,"V4L2 format: %08x\n" , node->fmt.fmt.pix.pixelformat); + +if (!pm_runtime_get_if_active (unicam->dev)) { +dev_info (unicam->dev, +"Live data N/A due to device inactive\n" ); +return 0 ; + } + reg =unicam_reg_read (unicam,UNICAM_IPIPE ); dev_info(unicam->dev, "Unpacking/packing: %u / %u\n", unicam_get_field(reg, UNICAM_PUM_MASK),@@ -2065,6 +2072,8 @@ static int unicam_log_status(struct file *file, void *fh)dev_info (unicam->dev,"Write pointer: %08x\n" ,unicam_reg_read (unicam,UNICAM_IBWP )); +pm_runtime_put (unicam->dev); +return 0 ; } ---base-commit:
e98d21c170b01ddef366f023bbfcf6b31509fa83
change-id: 20260521-bcmpipm-6c578e73239cBest regards,
--
Eugen Hristev <[email protected]>
Hi Eugen,
Le 22/05/2026 à 17:28, Eugen Hristev a écrit :
Quoted 38 lines
When requesting log status, the block might be powered off, but registers are being read.
Avoid reading the registers if the device is not resumed, thus also avoid powering up the device just for log status.Fixes 392cd78d495f ("media: bcm2835-unicam: Add support for CCP2/CSI2 camera interface")Signed-off-by Eugen Hristev <[email protected]>---
Changes in v2:
- changed to usepm_runtime_get_if_active()
- add correspondingput()
- Link to v1: https://patch.msgid.link/[email protected]To: Raspberry Pi Kernel Maintenance <[email protected]>
To: Mauro Carvalho Chehab <[email protected]>
To: Florian Fainelli <[email protected]>
To: Ray Jui <[email protected]>
To: Scott Branden <[email protected]>
To: Broadcom internal kernel review list <[email protected]>
To: Sakari Ailus <[email protected]>
To: Jean-Michel Hautbois <[email protected]>
To: Laurent Pinchart <[email protected]>
To: Hans Verkuil <[email protected]>
To: Naushir Patuck <[email protected]>
Cc: Dave Stevenson <[email protected]>
Cc: [email protected]
Cc: [email protected]
Cc: [email protected]
Cc: [email protected]--- drivers/media/platform/broadcom/bcm2835-unicam.c | 9 +++++++++ 1 file changed, 9 insertions(+)drivers/media/platform/broadcom/bcm2835-unicam.c +0
-0
drivers/media/platform/broadcom/bcm2835-unicam.c static int unicam_log_status(struct file *file, void *fh) · line 2056
Quoted 5 lines
drivers/media/platform/broadcom/bcm2835-unicam.c +2
-0@@ -2052,6 +2052,13 @@ static int unicam_log_status(struct file *file, void *fh) node->fmt.fmt.pix.width, node->fmt.fmt.pix.height);dev_info (unicam->dev,"V4L2 format: %08x\n" , node->fmt.fmt.pix.pixelformat); + +if (!pm_runtime_get_if_active (unicam->dev)) {
Well, if I am picky I would say that pm_runtime_get_if_active() can return -EINVAL if runtime PM is disabled for the device. It should then be tested against '<= 0' ?
I suppose this should not happen really often, as very few drivers actually test this case...
With or without this small change:
Thanks,
JM
Quoted 26 lines
drivers/media/platform/broadcom/bcm2835-unicam.c +7
-1+dev_info (unicam->dev, +"Live data N/A due to device inactive\n" ); +return 0 ; + } + reg =unicam_reg_read (unicam,UNICAM_IPIPE ); dev_info(unicam->dev, "Unpacking/packing: %u / %u\n", unicam_get_field(reg, UNICAM_PUM_MASK),@@ -2065,6 +2072,8 @@ static int unicam_log_status(struct file *file, void *fh)dev_info (unicam->dev,"Write pointer: %08x\n" ,unicam_reg_read (unicam,UNICAM_IBWP )); +pm_runtime_put (unicam->dev); +return 0 ; } ---base-commit:
e98d21c170b01ddef366f023bbfcf6b31509fa83
change-id: 20260521-bcmpipm-6c578e73239cBest regards,
--
Eugen Hristev <[email protected]>
Quoted 51 lines · Jean-Michel Hautbois
Hi Eugen,
Le 22/05/2026 à 17:28, Eugen Hristev a écrit :
Quoted 38 lines
When requesting log status, the block might be powered off, but registers are being read.
Avoid reading the registers if the device is not resumed, thus also avoid powering up the device just for log status.Fixes 392cd78d495f ("media: bcm2835-unicam: Add support for CCP2/CSI2 camera interface")Signed-off-by Eugen Hristev <[email protected]>---
Changes in v2:
- changed to usepm_runtime_get_if_active()
- add correspondingput()
- Link to v1: https://patch.msgid.link/[email protected]To: Raspberry Pi Kernel Maintenance <[email protected]>
To: Mauro Carvalho Chehab <[email protected]>
To: Florian Fainelli <[email protected]>
To: Ray Jui <[email protected]>
To: Scott Branden <[email protected]>
To: Broadcom internal kernel review list <[email protected]>
To: Sakari Ailus <[email protected]>
To: Jean-Michel Hautbois <[email protected]>
To: Laurent Pinchart <[email protected]>
To: Hans Verkuil <[email protected]>
To: Naushir Patuck <[email protected]>
Cc: Dave Stevenson <[email protected]>
Cc: [email protected]
Cc: [email protected]
Cc: [email protected]
Cc: [email protected]--- drivers/media/platform/broadcom/bcm2835-unicam.c | 9 +++++++++ 1 file changed, 9 insertions(+)drivers/media/platform/broadcom/bcm2835-unicam.c +0
-0drivers/media/platform/broadcom/bcm2835-unicam.c static int unicam_log_status(struct file *file, void *fh) · line 2056
Quoted 5 lines
drivers/media/platform/broadcom/bcm2835-unicam.c +2
-0@@ -2052,6 +2052,13 @@ static int unicam_log_status(struct file *file, void *fh) node->fmt.fmt.pix.width, node->fmt.fmt.pix.height);dev_info (unicam->dev,"V4L2 format: %08x\n" , node->fmt.fmt.pix.pixelformat); + +if (!pm_runtime_get_if_active (unicam->dev)) {Well, if I am picky I would say that
pm_runtime_get_if_active()can return-EINVALif runtime PM is disabled for the device. It should then be tested against '<= 0' ?
Quoted 2 lines
I suppose this should not happen really often, as very few drivers actually test this case...
I saw that. Some do. This driver enables runtime pm in probe though. So I guess it cannot happen, unless runtime pm would not selected in kernel config, but the driver depends on PM.
Ultimately I guess it's up to Sakari or Hans to decide whether it's worth checking for error code, but I picked the simpler path (and considering <depends on PM> in Kconfig) .
Quoted 34 lines
With or without this small change:
Reviewed-by Jean-Michel Hautbois <[email protected]>Thanks,
JMQuoted 26 lines
drivers/media/platform/broadcom/bcm2835-unicam.c +7
-1+dev_info (unicam->dev, +"Live data N/A due to device inactive\n" ); +return 0 ; + } + reg =unicam_reg_read (unicam,UNICAM_IPIPE ); dev_info(unicam->dev, "Unpacking/packing: %u / %u\n", unicam_get_field(reg, UNICAM_PUM_MASK),@@ -2065,6 +2072,8 @@ static int unicam_log_status(struct file *file, void *fh)dev_info (unicam->dev,"Write pointer: %08x\n" ,unicam_reg_read (unicam,UNICAM_IBWP )); +pm_runtime_put (unicam->dev); +return 0 ; } ---base-commit:
e98d21c170b01ddef366f023bbfcf6b31509fa83
change-id: 20260521-bcmpipm-6c578e73239cBest regards,
--
Eugen Hristev <[email protected]>
Hi Eugen, others,
Quoted 52 lines · Eugen Hristev
Quoted 51 lines · Jean-Michel Hautbois
Hi Eugen,
Le 22/05/2026 à 17:28, Eugen Hristev a écrit :
Quoted 38 lines
When requesting log status, the block might be powered off, but registers are being read.
Avoid reading the registers if the device is not resumed, thus also avoid powering up the device just for log status.Fixes 392cd78d495f ("media: bcm2835-unicam: Add support for CCP2/CSI2 camera interface")Signed-off-by Eugen Hristev <[email protected]>---
Changes in v2:
- changed to usepm_runtime_get_if_active()
- add correspondingput()
- Link to v1: https://patch.msgid.link/[email protected]To: Raspberry Pi Kernel Maintenance <[email protected]>
To: Mauro Carvalho Chehab <[email protected]>
To: Florian Fainelli <[email protected]>
To: Ray Jui <[email protected]>
To: Scott Branden <[email protected]>
To: Broadcom internal kernel review list <[email protected]>
To: Sakari Ailus <[email protected]>
To: Jean-Michel Hautbois <[email protected]>
To: Laurent Pinchart <[email protected]>
To: Hans Verkuil <[email protected]>
To: Naushir Patuck <[email protected]>
Cc: Dave Stevenson <[email protected]>
Cc: [email protected]
Cc: [email protected]
Cc: [email protected]
Cc: [email protected]--- drivers/media/platform/broadcom/bcm2835-unicam.c | 9 +++++++++ 1 file changed, 9 insertions(+)drivers/media/platform/broadcom/bcm2835-unicam.c +0
-0drivers/media/platform/broadcom/bcm2835-unicam.c static int unicam_log_status(struct file *file, void *fh) · line 2056
Quoted 5 lines
drivers/media/platform/broadcom/bcm2835-unicam.c +2
-0@@ -2052,6 +2052,13 @@ static int unicam_log_status(struct file *file, void *fh) node->fmt.fmt.pix.width, node->fmt.fmt.pix.height);dev_info (unicam->dev,"V4L2 format: %08x\n" , node->fmt.fmt.pix.pixelformat); + +if (!pm_runtime_get_if_active (unicam->dev)) {Well, if I am picky I would say that
pm_runtime_get_if_active()can return-EINVALif runtime PM is disabled for the device. It should then be tested against '<= 0' ?
Quoted 6 lines
Quoted 2 lines
I suppose this should not happen really often, as very few drivers actually test this case...
I saw that. Some do. This driver enables runtime pm in probe though. So I guess it cannot happen, unless runtime pm would not selected in kernel config, but the driver depends on PM.
Runtime PM can be disabled for a device via sysfs.
Quoted 4 lines
Ultimately I guess it's up to Sakari or Hans to decide whether it's worth checking for error code, but I picked the simpler path (and considering <depends on PM> in
Kconfig) .
pm_runtime_put() musn't be called if there was an error as it decrements usage_count unconditionally.
The vast majority of sensor drivers test for non-zero only and no-one has complained. They should be fixed though...
Quoted 30 lines
Quoted 30 lines
With or without this small change:
Reviewed-by Jean-Michel Hautbois <[email protected]>Thanks,
JMQuoted 23 lines
drivers/media/platform/broadcom/bcm2835-unicam.c +7
-1+dev_info (unicam->dev, +"Live data N/A due to device inactive\n" ); +return 0 ; + } + reg =unicam_reg_read (unicam,UNICAM_IPIPE ); dev_info(unicam->dev, "Unpacking/packing: %u / %u\n", unicam_get_field(reg, UNICAM_PUM_MASK),@@ -2065,6 +2072,8 @@ static int unicam_log_status(struct file *file, void *fh)dev_info (unicam->dev,"Write pointer: %08x\n" ,unicam_reg_read (unicam,UNICAM_IBWP )); +pm_runtime_put (unicam->dev); +return 0 ; } ---base-commit:
e98d21c170b01ddef366f023bbfcf6b31509fa83
change-id: 20260521-bcmpipm-6c578e73239cBest regards,
Signature · 3 lines
Regards, Sakari Ailus
Hi Sakari, Eugen,
Quoting Sakari Ailus (2026-06-01 02:32:09)
Quoted 55 lines
Hi Eugen, others,
Quoted 52 lines · Eugen Hristev
Quoted 51 lines · Jean-Michel Hautbois
Hi Eugen,
Le 22/05/2026 à 17:28, Eugen Hristev a écrit :
Quoted 38 lines
When requesting log status, the block might be powered off, but registers are being read.
Avoid reading the registers if the device is not resumed, thus also avoid powering up the device just for log status.Fixes 392cd78d495f ("media: bcm2835-unicam: Add support for CCP2/CSI2 camera interface")Signed-off-by Eugen Hristev <[email protected]>---
Changes in v2:
- changed to usepm_runtime_get_if_active()
- add correspondingput()
- Link to v1: https://patch.msgid.link/[email protected]To: Raspberry Pi Kernel Maintenance <[email protected]>
To: Mauro Carvalho Chehab <[email protected]>
To: Florian Fainelli <[email protected]>
To: Ray Jui <[email protected]>
To: Scott Branden <[email protected]>
To: Broadcom internal kernel review list <[email protected]>
To: Sakari Ailus <[email protected]>
To: Jean-Michel Hautbois <[email protected]>
To: Laurent Pinchart <[email protected]>
To: Hans Verkuil <[email protected]>
To: Naushir Patuck <[email protected]>
Cc: Dave Stevenson <[email protected]>
Cc: [email protected]
Cc: [email protected]
Cc: [email protected]
Cc: [email protected]--- drivers/media/platform/broadcom/bcm2835-unicam.c | 9 +++++++++ 1 file changed, 9 insertions(+)drivers/media/platform/broadcom/bcm2835-unicam.c +0
-0drivers/media/platform/broadcom/bcm2835-unicam.c static int unicam_log_status(struct file *file, void *fh) · line 2056
Quoted 5 lines
drivers/media/platform/broadcom/bcm2835-unicam.c +2
-0@@ -2052,6 +2052,13 @@ static int unicam_log_status(struct file *file, void *fh) node->fmt.fmt.pix.width, node->fmt.fmt.pix.height);dev_info (unicam->dev,"V4L2 format: %08x\n" , node->fmt.fmt.pix.pixelformat); + +if (!pm_runtime_get_if_active (unicam->dev)) {Well, if I am picky I would say that
pm_runtime_get_if_active()can return-EINVALif runtime PM is disabled for the device. It should then be tested against '<= 0' ?
Quoted 9 lines
Quoted 6 lines
Quoted 2 lines
I suppose this should not happen really often, as very few drivers actually test this case...
I saw that. Some do. This driver enables runtime pm in probe though. So I guess it cannot happen, unless runtime pm would not selected in kernel config, but the driver depends on PM.
Runtime PM can be disabled for a device via sysfs.
I tried this on my board, and you can only do:
echo on > /sys/class/<...>/control
Which leads to RPM count to always stay 1 regardless of get/put.
So if the driver enables RPM and never disables it unless it's removed, there's no way from userspace to make this function return -EINVAL.
Quoted 11 lines
Quoted 4 lines
Ultimately I guess it's up to Sakari or Hans to decide whether it's worth checking for error code, but I picked the simpler path (and considering <depends on PM> in
Kconfig) .
pm_runtime_put()musn't be called if there was an error as it decrementsusage_countunconditionally.The vast majority of sensor drivers test for non-zero only and no-one has complained. They should be fixed though...
This driver has an explicit "depends on PM", but even for other sensor drivers, the only case pm_runtime_get_if_active can return -EINVAL is when CONFIG_PM=n, where pm_runtime_put is also stubbed out to return -ENOSYS..
So there is nothing to fix in sesnor drivers which do:
if (!pm_runtime_get_if_active(&client->dev))
return 0;
/* write registers */
/* unconditional put */
pm_runtime_put(&client->dev)Thanks,
Jai
Quoted 36 lines
Quoted 30 lines
Quoted 30 lines
With or without this small change:
Reviewed-by Jean-Michel Hautbois <[email protected]>Thanks,
JMQuoted 23 lines
drivers/media/platform/broadcom/bcm2835-unicam.c +7
-1+dev_info (unicam->dev, +"Live data N/A due to device inactive\n" ); +return 0 ; + } + reg =unicam_reg_read (unicam,UNICAM_IPIPE ); dev_info(unicam->dev, "Unpacking/packing: %u / %u\n", unicam_get_field(reg, UNICAM_PUM_MASK),@@ -2065,6 +2072,8 @@ static int unicam_log_status(struct file *file, void *fh)dev_info (unicam->dev,"Write pointer: %08x\n" ,unicam_reg_read (unicam,UNICAM_IBWP )); +pm_runtime_put (unicam->dev); +return 0 ; } ---base-commit:
e98d21c170b01ddef366f023bbfcf6b31509fa83
change-id: 20260521-bcmpipm-6c578e73239cBest regards,
Signature · 3 lines
Regards, Sakari Ailus
Quoting Eugen Hristev (2026-05-22 20:58:50)
Quoted 7 lines
When requesting log status, the block might be powered off, but registers are being read.
Avoid reading the registers if the device is not resumed, thus also avoid powering up the device just for log status.Fixes 392cd78d495f ("media: bcm2835-unicam: Add support for CCP2/CSI2 camera interface")Signed-off-by Eugen Hristev <[email protected]>
Quoted 6 lines
---
Changes in v2:
- changed to usepm_runtime_get_if_active()
- add correspondingput()
- Link to v1: https://patch.msgid.link/[email protected]
Quoted 16 lines
To: Raspberry Pi Kernel Maintenance <[email protected]>
To: Mauro Carvalho Chehab <[email protected]>
To: Florian Fainelli <[email protected]>
To: Ray Jui <[email protected]>
To: Scott Branden <[email protected]>
To: Broadcom internal kernel review list <[email protected]>
To: Sakari Ailus <[email protected]>
To: Jean-Michel Hautbois <[email protected]>
To: Laurent Pinchart <[email protected]>
To: Hans Verkuil <[email protected]>
To: Naushir Patuck <[email protected]>
Cc: Dave Stevenson <[email protected]>
Cc: [email protected]
Cc: [email protected]
Cc: [email protected]
Cc: [email protected]
[snip]
Thanks,
Jai