Skip to content
This repository was archived by the owner on Nov 8, 2023. It is now read-only.

Commit d941b58

Browse files
kbinghamgregkh
authored andcommitted
staging: vc04_services: vchiq_arm: Fix initialisation check
The vchiq_state used to be obtained through an accessor which would validate that the VCHIQ had been initialised correctly with the remote, or return a null state. In commit 42a2f66 ("staging: vc04_services: Move global g_state to vchiq_state") the global state was moved to the vchiq_mgnt structures stored as a vchiq instance specific context. This conversion removed the helpers and instead replaced users of this helper with the assumption that the state is always available and the remote connected. The conversion does ensure that the state is always available, so some remaining state null pointer checks that remain are unnecessary, but the assumption that the remote is present and initialised is incorrect. Fix this broken assumption by re-introducing the logic that was lost during the conversion. Fixes: 42a2f66 ("staging: vc04_services: Move global g_state to vchiq_state") Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com> Reviewed-by: Stefan Wahren <wahrenst@gmx.net> Reviewed-by: Umang Jain <umang.jain@ideasonboard.com> Link: https://lore.kernel.org/r/20240620221046.2731704-1-kieran.bingham@ideasonboard.com Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 6ba59ff commit d941b58

File tree

3 files changed

+13
-3
lines changed

3 files changed

+13
-3
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -707,7 +707,7 @@ int vchiq_initialise(struct vchiq_state *state, struct vchiq_instance **instance
707707
* block forever.
708708
*/
709709
for (i = 0; i < VCHIQ_INIT_RETRIES; i++) {
710-
if (state)
710+
if (vchiq_remote_initialised(state))
711711
break;
712712
usleep_range(500, 600);
713713
}
@@ -1202,7 +1202,7 @@ void vchiq_dump_platform_instances(struct vchiq_state *state, struct seq_file *f
12021202
{
12031203
int i;
12041204

1205-
if (!state)
1205+
if (!vchiq_remote_initialised(state))
12061206
return;
12071207

12081208
/*

drivers/staging/vc04_services/interface/vchiq_arm/vchiq_core.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -413,6 +413,11 @@ struct vchiq_state {
413413
struct opaque_platform_state *platform_state;
414414
};
415415

416+
static inline bool vchiq_remote_initialised(const struct vchiq_state *state)
417+
{
418+
return state->remote && state->remote->initialised;
419+
}
420+
416421
struct bulk_waiter {
417422
struct vchiq_bulk *bulk;
418423
struct completion event;

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1170,6 +1170,11 @@ static int vchiq_open(struct inode *inode, struct file *file)
11701170

11711171
dev_dbg(state->dev, "arm: vchiq open\n");
11721172

1173+
if (!vchiq_remote_initialised(state)) {
1174+
dev_dbg(state->dev, "arm: vchiq has no connection to VideoCore\n");
1175+
return -ENOTCONN;
1176+
}
1177+
11731178
instance = kzalloc(sizeof(*instance), GFP_KERNEL);
11741179
if (!instance)
11751180
return -ENOMEM;
@@ -1200,7 +1205,7 @@ static int vchiq_release(struct inode *inode, struct file *file)
12001205

12011206
dev_dbg(state->dev, "arm: instance=%p\n", instance);
12021207

1203-
if (!state) {
1208+
if (!vchiq_remote_initialised(state)) {
12041209
ret = -EPERM;
12051210
goto out;
12061211
}

0 commit comments

Comments
 (0)