Skip to content

Commit

Permalink
staging: vchiq_arm: Get the rid off struct vchiq_2835_state
Browse files Browse the repository at this point in the history
The whole benefit of this encapsulating struct is questionable.
It just stores a flag to signalize the init state of vchiq_arm_state.
Beside the fact this flag is set too soon, the access to uninitialized
members should be avoided. So initialize vchiq_arm_state properly before
assign it directly to vchiq_state.

Signed-off-by: Stefan Wahren <[email protected]>
Link: https://lore.kernel.org/r/[email protected]
Signed-off-by: Greg Kroah-Hartman <[email protected]>
  • Loading branch information
lategoodbye authored and gregkh committed Jun 24, 2024
1 parent 935cb76 commit 4e27661
Showing 1 changed file with 6 additions and 19 deletions.
25 changes: 6 additions & 19 deletions drivers/staging/vc04_services/interface/vchiq_arm/vchiq_arm.c
Original file line number Diff line number Diff line change
Expand Up @@ -109,11 +109,6 @@ struct vchiq_arm_state {
int first_connect;
};

struct vchiq_2835_state {
int inited;
struct vchiq_arm_state arm_state;
};

struct vchiq_pagelist_info {
struct pagelist *pagelist;
size_t pagelist_buffer_size;
Expand Down Expand Up @@ -613,29 +608,21 @@ vchiq_arm_init_state(struct vchiq_state *state,
int
vchiq_platform_init_state(struct vchiq_state *state)
{
struct vchiq_2835_state *platform_state;
struct vchiq_arm_state *platform_state;

state->platform_state = kzalloc(sizeof(*platform_state), GFP_KERNEL);
if (!state->platform_state)
platform_state = kzalloc(sizeof(*platform_state), GFP_KERNEL);
if (!platform_state)
return -ENOMEM;

platform_state = (struct vchiq_2835_state *)state->platform_state;

platform_state->inited = 1;
vchiq_arm_init_state(state, &platform_state->arm_state);
vchiq_arm_init_state(state, platform_state);
state->platform_state = (struct opaque_platform_state *)platform_state;

return 0;
}

static struct vchiq_arm_state *vchiq_platform_get_arm_state(struct vchiq_state *state)
{
struct vchiq_2835_state *platform_state;

platform_state = (struct vchiq_2835_state *)state->platform_state;

WARN_ON_ONCE(!platform_state->inited);

return &platform_state->arm_state;
return (struct vchiq_arm_state *)state->platform_state;
}

void
Expand Down

0 comments on commit 4e27661

Please sign in to comment.