Skip to content

Commit 86bc882

Browse files
lategoodbyegregkh
authored andcommitted
staging: vchiq_arm: Create keep-alive thread during probe
Creating the keep-alive thread in vchiq_platform_init_state have the following advantages: - abort driver probe if kthread_create fails (more consistent behavior) - make resource release process easier Since vchiq_keepalive_thread_func is defined below vchiq_platform_init_state, the latter must be moved. Signed-off-by: Stefan Wahren <wahrenst@gmx.net> Link: https://lore.kernel.org/r/20250309125014.37166-5-wahrenst@gmx.net Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent cfb320d commit 86bc882

File tree

1 file changed

+34
-35
lines changed
  • drivers/staging/vc04_services/interface/vchiq_arm

1 file changed

+34
-35
lines changed

drivers/staging/vc04_services/interface/vchiq_arm/vchiq_arm.c

Lines changed: 34 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -280,29 +280,6 @@ static int vchiq_platform_init(struct platform_device *pdev, struct vchiq_state
280280
return 0;
281281
}
282282

283-
int
284-
vchiq_platform_init_state(struct vchiq_state *state)
285-
{
286-
struct vchiq_arm_state *platform_state;
287-
288-
platform_state = devm_kzalloc(state->dev, sizeof(*platform_state), GFP_KERNEL);
289-
if (!platform_state)
290-
return -ENOMEM;
291-
292-
rwlock_init(&platform_state->susp_res_lock);
293-
294-
init_completion(&platform_state->ka_evt);
295-
atomic_set(&platform_state->ka_use_count, 0);
296-
atomic_set(&platform_state->ka_use_ack_count, 0);
297-
atomic_set(&platform_state->ka_release_count, 0);
298-
299-
platform_state->state = state;
300-
301-
state->platform_state = (struct opaque_platform_state *)platform_state;
302-
303-
return 0;
304-
}
305-
306283
static struct vchiq_arm_state *vchiq_platform_get_arm_state(struct vchiq_state *state)
307284
{
308285
return (struct vchiq_arm_state *)state->platform_state;
@@ -1011,6 +988,39 @@ vchiq_keepalive_thread_func(void *v)
1011988
return 0;
1012989
}
1013990

991+
int
992+
vchiq_platform_init_state(struct vchiq_state *state)
993+
{
994+
struct vchiq_arm_state *platform_state;
995+
char threadname[16];
996+
997+
platform_state = devm_kzalloc(state->dev, sizeof(*platform_state), GFP_KERNEL);
998+
if (!platform_state)
999+
return -ENOMEM;
1000+
1001+
snprintf(threadname, sizeof(threadname), "vchiq-keep/%d",
1002+
state->id);
1003+
platform_state->ka_thread = kthread_create(&vchiq_keepalive_thread_func,
1004+
(void *)state, threadname);
1005+
if (IS_ERR(platform_state->ka_thread)) {
1006+
dev_err(state->dev, "couldn't create thread %s\n", threadname);
1007+
return PTR_ERR(platform_state->ka_thread);
1008+
}
1009+
1010+
rwlock_init(&platform_state->susp_res_lock);
1011+
1012+
init_completion(&platform_state->ka_evt);
1013+
atomic_set(&platform_state->ka_use_count, 0);
1014+
atomic_set(&platform_state->ka_use_ack_count, 0);
1015+
atomic_set(&platform_state->ka_release_count, 0);
1016+
1017+
platform_state->state = state;
1018+
1019+
state->platform_state = (struct opaque_platform_state *)platform_state;
1020+
1021+
return 0;
1022+
}
1023+
10141024
int
10151025
vchiq_use_internal(struct vchiq_state *state, struct vchiq_service *service,
10161026
enum USE_TYPE_E use_type)
@@ -1331,7 +1341,6 @@ void vchiq_platform_conn_state_changed(struct vchiq_state *state,
13311341
enum vchiq_connstate newstate)
13321342
{
13331343
struct vchiq_arm_state *arm_state = vchiq_platform_get_arm_state(state);
1334-
char threadname[16];
13351344

13361345
dev_dbg(state->dev, "suspend: %d: %s->%s\n",
13371346
state->id, get_conn_state_name(oldstate), get_conn_state_name(newstate));
@@ -1346,17 +1355,7 @@ void vchiq_platform_conn_state_changed(struct vchiq_state *state,
13461355

13471356
arm_state->first_connect = 1;
13481357
write_unlock_bh(&arm_state->susp_res_lock);
1349-
snprintf(threadname, sizeof(threadname), "vchiq-keep/%d",
1350-
state->id);
1351-
arm_state->ka_thread = kthread_create(&vchiq_keepalive_thread_func,
1352-
(void *)state,
1353-
threadname);
1354-
if (IS_ERR(arm_state->ka_thread)) {
1355-
dev_err(state->dev, "suspend: Couldn't create thread %s\n",
1356-
threadname);
1357-
} else {
1358-
wake_up_process(arm_state->ka_thread);
1359-
}
1358+
wake_up_process(arm_state->ka_thread);
13601359
}
13611360

13621361
static const struct of_device_id vchiq_of_match[] = {

0 commit comments

Comments
 (0)