Skip to contentSkip to conversation

media: vimc: streamer: if kthread_stop fails, ignore the error

PATCH Superseded Dafna Hirschfeld 3 participants 3 messages Jan 19, 2020 – Jan 21, 2020 Media (V4L/DVB)

v4 of 5 Superseded Latest is v5 →

lore
Share & tools
lore
#0 lore raw

PATCH v4 1/1 media: vimc: streamer: if kthread_stop fails, ignore the error

Ignore errors returned from kthread_stop since the vimc subdevices should still be notified that streaming stopped so they can release the memory for the streaming, and also kthread should be set to NULL. kthread_stop can return -EINTR in case the thread did not yet run. This can happen if userspace calls streamon and streamoff right after.

---
Changes from v3: change the comment to explain when kthread fails

 drivers/media/platform/vimc/vimc-streamer.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)
drivers/media/platform/vimc/vimc-streamer.c +8 -2
index cd6b55433c9e..26ec81b265c4 100644
@@ -215,9 +215,15 @@ int vimc_streamer_s_stream(struct vimc_stream *stream,
 			return 0;
 
 		ret = kthread_stop(stream->kthread);
-		if (ret)
-			return ret;
 
+		/*
+		 * kthread_stop returns -EINTR in cases when streamon was
+		 * immediately followed by streamoff, and the thread didn't had
+		 * a chance to run. Ignore errors to stop the stream in the
+		 * pipeline.
+		 */
+		if (ret)
+			dev_warn(ved->dev, "kthread_stop returned '%d'\n", ret);
 		stream->kthread = NULL;
 
 		vimc_streamer_pipeline_terminate(stream);
Signature · 1 line
2.17.1
#1 lore raw

Hi Dafna,

Thanks for the patch.

Quoted 9 lines · Dafna Hirschfeld

Ignore errors returned from kthread_stop since the vimc subdevices should still be notified that streaming stopped so they can release the memory for the streaming, and also kthread should be set to NULL. kthread_stop can return -EINTR in case the thread did not yet run. This can happen if userspace calls streamon and streamoff right after.

Quoted 4 lines

---
Changes from v3: change the comment to explain when kthread fails

Please keep all the history here, so we'd see the changes done to v1, v2, v3.

Quoted 12 lines
 drivers/media/platform/vimc/vimc-streamer.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)
drivers/media/platform/vimc/vimc-streamer.c +0 -1
index cd6b55433c9e..26ec81b265c4 100644
@@ -215,9 +215,15 @@ int vimc_streamer_s_stream(struct vimc_stream *stream,
                        return 0;
 
                ret = kthread_stop(stream->kthread);
-               if (ret)

drivers/media/platform/vimc/vimc-streamer.c int vimc_streamer_s_stream(struct vimc_stream *stream, · line 226

Quoted 10 lines
drivers/media/platform/vimc/vimc-streamer.c +8 -1
-                       return ret;
 
+               /*
+                * kthread_stop returns -EINTR in cases when streamon was
+                * immediately followed by streamoff, and the thread didn't had
+                * a chance to run. Ignore errors to stop the stream in the
+                * pipeline.
+                */
+               if (ret)
+                       dev_warn(ved->dev, "kthread_stop returned '%d'\n", ret);

Is this situation serious enough to deserve warning the user? If not, perhaps dev_dbg would be better.

Regards,
Ezequiel

Acked-by
#2 lore raw
Quoted 33 lines · Ezequiel Garcia

Hi Dafna,

Thanks for the patch.

Quoted 9 lines · Dafna Hirschfeld

Ignore errors returned from kthread_stop since the vimc subdevices should still be notified that streaming stopped so they can release the memory for the streaming, and also kthread should be set to NULL. kthread_stop can return -EINTR in case the thread did not yet run. This can happen if userspace calls streamon and streamoff right after.

Quoted 4 lines

---
Changes from v3: change the comment to explain when kthread fails

Please keep all the history here, so we'd see the changes done to v1, v2, v3.

Quoted 10 lines
 drivers/media/platform/vimc/vimc-streamer.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)
drivers/media/platform/vimc/vimc-streamer.c +0 -0
index cd6b55433c9e..26ec81b265c4 100644
@@ -215,9 +215,15 @@ int vimc_streamer_s_stream(struct vimc_stream *stream,
                        return 0;
 
Quoted 4 lines

drivers/media/platform/vimc/vimc-streamer.c int vimc_streamer_s_stream(struct vimc_stream *stream, · line 218

Quoted 4 lines
drivers/media/platform/vimc/vimc-streamer.c +0 -2
                ret = kthread_stop(stream->kthread);
-               if (ret)
-                       return ret;
 

no new line is required here.
The idea is to keep the error check as close as possible of the function who generated the error.

Quoted 8 lines

drivers/media/platform/vimc/vimc-streamer.c int vimc_streamer_s_stream(struct vimc_stream *stream, · line 226

Quoted 8 lines
drivers/media/platform/vimc/vimc-streamer.c +8 -0
+               /*
+                * kthread_stop returns -EINTR in cases when streamon was
+                * immediately followed by streamoff, and the thread didn't had
+                * a chance to run. Ignore errors to stop the stream in the
+                * pipeline.
+                */
+               if (ret)
+                       dev_warn(ved->dev, "kthread_stop returned '%d'\n", ret);

Please, re-add the new line here (I thought you had already done this in a previous version).

Quoted 3 lines

Is this situation serious enough to deserve warning the user? If not, perhaps dev_dbg would be better.

I agree, this is a normal usecase, please change to dev_dgb().

With these changes

Thanks
Helen

Quoted 4 lines

Regards,
Ezequiel