| From c6be6471004e0e4d10d0514146d8c41550823d63 Mon Sep 17 00:00:00 2001 |
| From: Wentong Wu <wentong.wu@intel.com> |
| Date: Fri, 7 Jun 2024 21:25:46 +0800 |
| Subject: media: ivsc: csi: add separate lock for v4l2 control handler |
| |
| From: Wentong Wu <wentong.wu@intel.com> |
| |
| commit c6be6471004e0e4d10d0514146d8c41550823d63 upstream. |
| |
| There're possibilities that privacy status change notification happens |
| in the middle of the ongoing mei command which already takes the command |
| lock, but v4l2_ctrl_s_ctrl() would also need the same lock prior to this |
| patch, so this may results in circular locking problem. This patch adds |
| one dedicated lock for v4l2 control handler to avoid described issue. |
| |
| Fixes: 29006e196a56 ("media: pci: intel: ivsc: Add CSI submodule") |
| Cc: stable@vger.kernel.org # for 6.6 and later |
| Reported-by: Hao Yao <hao.yao@intel.com> |
| Signed-off-by: Wentong Wu <wentong.wu@intel.com> |
| Tested-by: Jason Chen <jason.z.chen@intel.com> |
| Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com> |
| Signed-off-by: Hans Verkuil <hverkuil-cisco@xs4all.nl> |
| Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org> |
| --- |
| drivers/media/pci/intel/ivsc/mei_csi.c | 8 +++++++- |
| 1 file changed, 7 insertions(+), 1 deletion(-) |
| |
| --- a/drivers/media/pci/intel/ivsc/mei_csi.c |
| +++ b/drivers/media/pci/intel/ivsc/mei_csi.c |
| @@ -124,6 +124,8 @@ struct mei_csi { |
| struct v4l2_ctrl_handler ctrl_handler; |
| struct v4l2_ctrl *freq_ctrl; |
| struct v4l2_ctrl *privacy_ctrl; |
| + /* lock for v4l2 controls */ |
| + struct mutex ctrl_lock; |
| unsigned int remote_pad; |
| /* start streaming or not */ |
| int streaming; |
| @@ -609,11 +611,13 @@ static int mei_csi_init_controls(struct |
| u32 max; |
| int ret; |
| |
| + mutex_init(&csi->ctrl_lock); |
| + |
| ret = v4l2_ctrl_handler_init(&csi->ctrl_handler, 2); |
| if (ret) |
| return ret; |
| |
| - csi->ctrl_handler.lock = &csi->lock; |
| + csi->ctrl_handler.lock = &csi->ctrl_lock; |
| |
| max = ARRAY_SIZE(link_freq_menu_items) - 1; |
| csi->freq_ctrl = v4l2_ctrl_new_int_menu(&csi->ctrl_handler, |
| @@ -772,6 +776,7 @@ err_entity: |
| |
| err_ctrl_handler: |
| v4l2_ctrl_handler_free(&csi->ctrl_handler); |
| + mutex_destroy(&csi->ctrl_lock); |
| v4l2_async_nf_unregister(&csi->notifier); |
| v4l2_async_nf_cleanup(&csi->notifier); |
| |
| @@ -791,6 +796,7 @@ static void mei_csi_remove(struct mei_cl |
| v4l2_async_nf_unregister(&csi->notifier); |
| v4l2_async_nf_cleanup(&csi->notifier); |
| v4l2_ctrl_handler_free(&csi->ctrl_handler); |
| + mutex_destroy(&csi->ctrl_lock); |
| v4l2_async_unregister_subdev(&csi->subdev); |
| v4l2_subdev_cleanup(&csi->subdev); |
| media_entity_cleanup(&csi->subdev.entity); |