staging: most: video: replace BUG_ON with WARN_ON_ONCE and add recovery
Subsystems (2)
PATCH 1/1 staging: most: video: replace BUG_ON with WARN_ON_ONCE and add recovery
BUG_ON() halts the kernel unconditionally. The check after most_deregister_component() guards against a bug in mostcore: it currently does not call disconnect_channel() for linked channels on deregistration, so if that ever changes unexpectedly, video_devices could be non-empty.
Replace BUG_ON with WARN_ON_ONCE so the kernel stays up, and add a recovery path that drains and frees any remaining devices to avoid memory leaks in that error case.
Also document what the spinlock and mutex in struct most_video_dev each protect.
--- drivers/staging/most/video/video.c | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-)
drivers/staging/most/video/video.c +16 -3
@@ -33,14 +33,14 @@ struct most_video_dev {bool mute;struct list_head pending_mbos; -spinlock_t list_lock; +spinlock_t list_lock;/* protects pending_mbos and mute */ struct v4l2_device v4l2_dev;atomic_t access_ref;struct video_device *vdev;unsigned int ctrl_input; -struct mutex lock; +struct mutex lock;/* v4l2 device lock */ wait_queue_head_t wait_data; };
@@ -577,7 +577,20 @@ static void __exit comp_exit(void)most_deregister_configfs_subsys (&comp);most_deregister_component (&comp); -BUG_ON (!list_empty (&video_devices)); + +if (WARN_ON_ONCE (!list_empty (&video_devices))) { +/* clean up any devices unexpectedly added during deregister phase */ +spin_lock_irq (&list_lock); +list_replace_init (&video_devices, &free_list); +spin_unlock_irq (&list_lock); + +list_for_each_entry_safe (mdev, tmp, &free_list, list) { +list_del_init (&mdev->list); +comp_unregister_videodev (mdev); +v4l2_device_disconnect (&mdev->v4l2_dev); +v4l2_device_put (&mdev->v4l2_dev); + } + } }module_init (comp_init);
Signature · 1 line
2.43.0
Greg KH
maintainerQuoted 63 lines · Matan Cohen
BUG_ON()halts the kernel unconditionally. The check aftermost_deregister_component()guards against a bug in mostcore: it currently does not calldisconnect_channel()for linked channels on deregistration, so if that ever changes unexpectedly,video_devicescould be non-empty.Replace
BUG_ONwithWARN_ON_ONCEso the kernel stays up, and add a recovery path that drains and frees any remaining devices to avoid memory leaks in that error case.Also document what the spinlock and mutex in struct
most_video_deveach protect.--- drivers/staging/most/video/video.c | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-)drivers/staging/most/video/video.c +16
-3@@ -33,14 +33,14 @@ struct most_video_dev {bool mute;struct list_head pending_mbos; -spinlock_t list_lock; +spinlock_t list_lock;/* protects pending_mbos and mute */ struct v4l2_device v4l2_dev;atomic_t access_ref;struct video_device *vdev;unsigned int ctrl_input; -struct mutex lock; +struct mutex lock;/* v4l2 device lock */ wait_queue_head_t wait_data; };@@ -577,7 +577,20 @@ static void __exit comp_exit(void)most_deregister_configfs_subsys (&comp);most_deregister_component (&comp); -BUG_ON (!list_empty (&video_devices)); + +if (WARN_ON_ONCE (!list_empty (&video_devices))) { +/* clean up any devices unexpectedly added during deregister phase */ +spin_lock_irq (&list_lock); +list_replace_init (&video_devices, &free_list); +spin_unlock_irq (&list_lock); + +list_for_each_entry_safe (mdev, tmp, &free_list, list) { +list_del_init (&mdev->list); +comp_unregister_videodev (mdev); +v4l2_device_disconnect (&mdev->v4l2_dev); +v4l2_device_put (&mdev->v4l2_dev); + } + } }module_init (comp_init);Signature · 1 line
2.43.0
Hi,
This is the friendly patch-bot of Greg Kroah-Hartman. You have sent him a patch that has triggered this response. He used to manually respond to these common problems, but in order to save his sanity (he kept writing the same thing over and over, yet to different people), I was created. Hopefully you will not take offence and will fix the problem in your patch and resubmit it so that it can be accepted into the Linux kernel tree.
You are receiving this message because of the following common error(s) as indicated below:
- Your patch does not have a Signed-off-by: line. Please read the kernel file, Documentation/process/submitting-patches.rst and resend it after adding that line. Note, the line needs to be in the body of the email, before the patch, not at the bottom of the patch or in the email signature.
- Your patch did many different things all at once, making it difficult to review. All Linux kernel patches need to only do one thing at a time. If you need to do multiple things (such as clean up all coding style issues in a file/driver), do it in a sequence of patches, each one doing only one thing. This will make it easier to review the patches to ensure that they are correct, and to help alleviate any merge issues that larger patches can cause.
If you wish to discuss this problem further, or you have questions about how to resolve this issue, please feel free to respond to this email and Greg will reply once he has dug out from the pending patches received from other developers.
thanks,
greg k-h's patch email bot
Quoted 21 lines · Matan Cohen
BUG_ON()halts the kernel unconditionally. The check aftermost_deregister_component()guards against a bug in mostcore: it currently does not calldisconnect_channel()for linked channels on deregistration, so if that ever changes unexpectedly,video_devicescould be non-empty.Replace
BUG_ONwithWARN_ON_ONCEso the kernel stays up, and add a recovery path that drains and frees any remaining devices to avoid memory leaks in that error case.Also document what the spinlock and mutex in struct
most_video_deveach protect.--- drivers/staging/most/video/video.c | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-)drivers/staging/most/video/video.c +0
-0
drivers/staging/most/video/video.c struct most_video_dev { · line 36
Quoted 5 lines
drivers/staging/most/video/video.c +1
-1@@ -33,14 +33,14 @@ struct most_video_dev {bool mute;struct list_head pending_mbos; -spinlock_t list_lock; +spinlock_t list_lock;/* protects pending_mbos and mute */
I always dread these kinds of patches... The comment is useless. Way too vague and kind of wrong also. I want to see a much more thorough explanation.
regards,
dan carpenter
Quoted 3 lines · Dan Carpenter
I always dread these kinds of patches... The comment is useless. Way too vague and kind of wrong also. I want to see a much more thorough explanation.
Hi Dan and Greg's bot,
First of All Thank you for the review and quick reply.
This is my first time Contributing, I wanted to start with something well contained that I found using checkpatch.pl
My intention was twofold:
1. Replace BUG_ON with WARN_ON_ONCE — the kernel should not crash unconditionally here since the cleanup above already completed.
2. Add a recovery path to drain any remaining devices and avoid a
memory leak, in case something unexpectedly adds to video_devices, during the deregistration calls.
- I think that this was the original intention that lead the BUG_ON to be there in the first place, but I am not entirely sure.
I'll resend as v2 with:
- The lock comments into a separate Patch
- A Signed-off-by line (apologies for missing that, my bad)
- A more thorough commit message
Should I keep the recovery path with a better explanation, or drop it and use a bare WARN_ON_ONCE?
waiting for your reply before spamming with random update, let me know what you think?
Regards,
Matan Cohen
Greg KH
maintainerQuoted 7 lines · Matan Cohen
Quoted 3 lines · Dan Carpenter
I always dread these kinds of patches... The comment is useless. Way too vague and kind of wrong also. I want to see a much more thorough explanation.
Hi Dan and Greg's bot,
Quoted 7 lines
First of All Thank you for the review and quick reply.
This is my first time Contributing, I wanted to start with something well contained that I found using checkpatch.plMy intention was twofold:
1. Replace
BUG_ONwithWARN_ON_ONCE— the kernel should not crash unconditionally here since the cleanup above already completed.
Note, you have trailing whitespace in yoru email client, please fix that up.
Anyway, you can not replace BUG_ON() with WARN_ON() and expect the crash to go away due to panic-on-warn being an option that a few billion Linux systems have. If this type of thing can happen, then handle it properly and deal with it, otherwise if it is so bad that all data will be lost, live with the BUG_ON().
thanks,
greg k-h