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 42a2f6664e18 ("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: 42a2f6664e18 ("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>

authored by Kieran Bingham and committed by Greg Kroah-Hartman d941b587 6ba59ff4

+13 -3
+2 -2
drivers/staging/vc04_services/interface/vchiq_arm/vchiq_arm.c
··· 707 * block forever. 708 */ 709 for (i = 0; i < VCHIQ_INIT_RETRIES; i++) { 710 - if (state) 711 break; 712 usleep_range(500, 600); 713 } ··· 1202 { 1203 int i; 1204 1205 - if (!state) 1206 return; 1207 1208 /*
··· 707 * block forever. 708 */ 709 for (i = 0; i < VCHIQ_INIT_RETRIES; i++) { 710 + if (vchiq_remote_initialised(state)) 711 break; 712 usleep_range(500, 600); 713 } ··· 1202 { 1203 int i; 1204 1205 + if (!vchiq_remote_initialised(state)) 1206 return; 1207 1208 /*
+5
drivers/staging/vc04_services/interface/vchiq_arm/vchiq_core.h
··· 413 struct opaque_platform_state *platform_state; 414 }; 415 416 struct bulk_waiter { 417 struct vchiq_bulk *bulk; 418 struct completion event;
··· 413 struct opaque_platform_state *platform_state; 414 }; 415 416 + static inline bool vchiq_remote_initialised(const struct vchiq_state *state) 417 + { 418 + return state->remote && state->remote->initialised; 419 + } 420 + 421 struct bulk_waiter { 422 struct vchiq_bulk *bulk; 423 struct completion event;
+6 -1
drivers/staging/vc04_services/interface/vchiq_arm/vchiq_dev.c
··· 1170 1171 dev_dbg(state->dev, "arm: vchiq open\n"); 1172 1173 instance = kzalloc(sizeof(*instance), GFP_KERNEL); 1174 if (!instance) 1175 return -ENOMEM; ··· 1205 1206 dev_dbg(state->dev, "arm: instance=%p\n", instance); 1207 1208 - if (!state) { 1209 ret = -EPERM; 1210 goto out; 1211 }
··· 1170 1171 dev_dbg(state->dev, "arm: vchiq open\n"); 1172 1173 + if (!vchiq_remote_initialised(state)) { 1174 + dev_dbg(state->dev, "arm: vchiq has no connection to VideoCore\n"); 1175 + return -ENOTCONN; 1176 + } 1177 + 1178 instance = kzalloc(sizeof(*instance), GFP_KERNEL); 1179 if (!instance) 1180 return -ENOMEM; ··· 1200 1201 dev_dbg(state->dev, "arm: instance=%p\n", instance); 1202 1203 + if (!vchiq_remote_initialised(state)) { 1204 ret = -EPERM; 1205 goto out; 1206 }