Commit d9c60bad authored by Umang Jain's avatar Umang Jain Committed by Greg Kroah-Hartman

staging: vc04_services: vchiq_core: Stop kthreads on shutdown

The various kthreads thread functions (slot_handler_func, sync_func,
recycle_func) in vchiq_core and vchiq_keepalive_thread_func in
vchiq_arm should be stopped on vchiq_shutdown().

This also address the following TODO item:
 * Fix kernel module support

hence drop it from the TODO item list.
Signed-off-by: default avatarUmang Jain <umang.jain@ideasonboard.com>
Reviewed-by: default avatarKieran Bingham <kieran.bingham@ideasonboard.com>
Link: https://lore.kernel.org/r/20240321130737.898154-6-umang.jain@ideasonboard.comSigned-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent bf189490
...@@ -16,13 +16,6 @@ some of the ones we want: ...@@ -16,13 +16,6 @@ some of the ones we want:
to manage these buffers as dmabufs so that we can zero-copy import to manage these buffers as dmabufs so that we can zero-copy import
camera images into vc4 for rendering/display. camera images into vc4 for rendering/display.
* Fix kernel module support
Even the VPU firmware doesn't support a VCHI re-connect, the driver
should properly handle a module unload. This also includes that all
resources must be freed (kthreads, debugfs entries, ...) and global
variables avoided.
* Documentation * Documentation
A short top-down description of this driver's architecture (function of A short top-down description of this driver's architecture (function of
......
...@@ -726,8 +726,9 @@ void free_bulk_waiter(struct vchiq_instance *instance) ...@@ -726,8 +726,9 @@ void free_bulk_waiter(struct vchiq_instance *instance)
int vchiq_shutdown(struct vchiq_instance *instance) int vchiq_shutdown(struct vchiq_instance *instance)
{ {
int status = 0;
struct vchiq_state *state = instance->state; struct vchiq_state *state = instance->state;
struct vchiq_arm_state *arm_state;
int status = 0;
if (mutex_lock_killable(&state->mutex)) if (mutex_lock_killable(&state->mutex))
return -EAGAIN; return -EAGAIN;
...@@ -739,6 +740,9 @@ int vchiq_shutdown(struct vchiq_instance *instance) ...@@ -739,6 +740,9 @@ int vchiq_shutdown(struct vchiq_instance *instance)
dev_dbg(state->dev, "core: (%p): returning %d\n", instance, status); dev_dbg(state->dev, "core: (%p): returning %d\n", instance, status);
arm_state = vchiq_platform_get_arm_state(state);
kthread_stop(arm_state->ka_thread);
free_bulk_waiter(instance); free_bulk_waiter(instance);
kfree(instance); kfree(instance);
...@@ -1310,7 +1314,7 @@ vchiq_keepalive_thread_func(void *v) ...@@ -1310,7 +1314,7 @@ vchiq_keepalive_thread_func(void *v)
goto shutdown; goto shutdown;
} }
while (1) { while (!kthread_should_stop()) {
long rc = 0, uc = 0; long rc = 0, uc = 0;
if (wait_for_completion_interruptible(&arm_state->ka_evt)) { if (wait_for_completion_interruptible(&arm_state->ka_evt)) {
......
...@@ -1936,7 +1936,7 @@ slot_handler_func(void *v) ...@@ -1936,7 +1936,7 @@ slot_handler_func(void *v)
DEBUG_INITIALISE(local); DEBUG_INITIALISE(local);
while (1) { while (!kthread_should_stop()) {
DEBUG_COUNT(SLOT_HANDLER_COUNT); DEBUG_COUNT(SLOT_HANDLER_COUNT);
DEBUG_TRACE(SLOT_HANDLER_LINE); DEBUG_TRACE(SLOT_HANDLER_LINE);
remote_event_wait(&state->trigger_event, &local->trigger); remote_event_wait(&state->trigger_event, &local->trigger);
...@@ -1978,7 +1978,7 @@ recycle_func(void *v) ...@@ -1978,7 +1978,7 @@ recycle_func(void *v)
if (!found) if (!found)
return -ENOMEM; return -ENOMEM;
while (1) { while (!kthread_should_stop()) {
remote_event_wait(&state->recycle_event, &local->recycle); remote_event_wait(&state->recycle_event, &local->recycle);
process_free_queue(state, found, length); process_free_queue(state, found, length);
...@@ -1997,7 +1997,7 @@ sync_func(void *v) ...@@ -1997,7 +1997,7 @@ sync_func(void *v)
state->remote->slot_sync); state->remote->slot_sync);
int svc_fourcc; int svc_fourcc;
while (1) { while (!kthread_should_stop()) {
struct vchiq_service *service; struct vchiq_service *service;
int msgid, size; int msgid, size;
int type; int type;
...@@ -2844,6 +2844,10 @@ vchiq_shutdown_internal(struct vchiq_state *state, struct vchiq_instance *instan ...@@ -2844,6 +2844,10 @@ vchiq_shutdown_internal(struct vchiq_state *state, struct vchiq_instance *instan
(void)vchiq_remove_service(instance, service->handle); (void)vchiq_remove_service(instance, service->handle);
vchiq_service_put(service); vchiq_service_put(service);
} }
kthread_stop(state->sync_thread);
kthread_stop(state->recycle_thread);
kthread_stop(state->slot_handler_thread);
} }
int int
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment