Skip to content

Commit

Permalink
staging: vc04_services: vchiq_arm: Fix initialisation check
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Kieran Bingham authored and Greg Kroah-Hartman committed Jun 24, 2024
1 parent 6ba59ff commit d941b58
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 3 deletions.
4 changes: 2 additions & 2 deletions drivers/staging/vc04_services/interface/vchiq_arm/vchiq_arm.c
Original file line number Diff line number Diff line change
Expand Up @@ -707,7 +707,7 @@ int vchiq_initialise(struct vchiq_state *state, struct vchiq_instance **instance
* block forever.
*/
for (i = 0; i < VCHIQ_INIT_RETRIES; i++) {
if (state)
if (vchiq_remote_initialised(state))
break;
usleep_range(500, 600);
}
Expand Down Expand Up @@ -1202,7 +1202,7 @@ void vchiq_dump_platform_instances(struct vchiq_state *state, struct seq_file *f
{
int i;

if (!state)
if (!vchiq_remote_initialised(state))
return;

/*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -413,6 +413,11 @@ struct vchiq_state {
struct opaque_platform_state *platform_state;
};

static inline bool vchiq_remote_initialised(const struct vchiq_state *state)
{
return state->remote && state->remote->initialised;
}

struct bulk_waiter {
struct vchiq_bulk *bulk;
struct completion event;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1170,6 +1170,11 @@ static int vchiq_open(struct inode *inode, struct file *file)

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

if (!vchiq_remote_initialised(state)) {
dev_dbg(state->dev, "arm: vchiq has no connection to VideoCore\n");
return -ENOTCONN;
}

instance = kzalloc(sizeof(*instance), GFP_KERNEL);
if (!instance)
return -ENOMEM;
Expand Down Expand Up @@ -1200,7 +1205,7 @@ static int vchiq_release(struct inode *inode, struct file *file)

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

if (!state) {
if (!vchiq_remote_initialised(state)) {
ret = -EPERM;
goto out;
}
Expand Down

0 comments on commit d941b58

Please sign in to comment.