cx25821_video_register() initializes a capture channel's control handler before setting up its queue and registering its video device. A failure in control creation, handler setup, queue initialization or video device registration reaches fail_unreg, which includes the current channel. However, cx25821_video_unregister() only frees the handler if the video device was successfully registered. The current channel's controls are therefore leaked on those failures. Keep video unregistration conditional, but free the control handler unconditionally. v4l2_ctrl_handler_free() safely handles the zeroed handlers of channels that do not have controls. Fixes: f8d7ee70919d ("[media] cx25821: convert to the control framework") Cc: stable@vger.kernel.org Assisted-by: DeepSeek-V4.1-Flash and OpenAI Codex Signed-off-by: Wentao Liang --- drivers/media/pci/cx25821/cx25821-video.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/drivers/media/pci/cx25821/cx25821-video.c b/drivers/media/pci/cx25821/cx25821-video.c index 84aa1209e717..84aa7efc50d5 100644 --- a/drivers/media/pci/cx25821/cx25821-video.c +++ b/drivers/media/pci/cx25821/cx25821-video.c @@ -656,10 +656,9 @@ void cx25821_video_unregister(struct cx25821_dev *dev, int chan_num) { cx_clear(PCI_INT_MSK, 1); - if (video_is_registered(&dev->channels[chan_num].vdev)) { + if (video_is_registered(&dev->channels[chan_num].vdev)) video_unregister_device(&dev->channels[chan_num].vdev); - v4l2_ctrl_handler_free(&dev->channels[chan_num].hdl); - } + v4l2_ctrl_handler_free(&dev->channels[chan_num].hdl); } int cx25821_video_register(struct cx25821_dev *dev) -- 2.34.1