Skip to content

Commit

Permalink
sensor: ism330dhcx: Incorrect handle passed to ctx struct in SPI mode
Browse files Browse the repository at this point in the history
The ISM330DHCX driver immediately segfaults when run in SPI mode. A bad
pointer is being passed into the `dev` param of `ism330dhcx_spi_read`.
Tracing this back, it appears that the handle field of the ctx struct
is being set to the device's data struct while `ism330dhcx_spi_read`
expects `ctx->handle` to be a pointer to a device struct.

Modify `ism330dhcx_spi_init()` to insert the correct pointer into the
context struct. Unfortunately this requires a cast to discard the
`const` qualifier, but this is how it is done in I2C mode (see
`ism330dhcx_i2c_init()`). The only other way would be to change the
declaration of `stmdev_ctx_t`, which is owned by the HAL module.

Signed-off-by: Tristan Honscheid <honscheid@google.com>
  • Loading branch information
tristan-google committed Jul 6, 2023
1 parent c15ff10 commit 4ee116c
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion drivers/sensor/ism330dhcx/ism330dhcx_spi.c
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ int ism330dhcx_spi_init(const struct device *dev)
data->ctx_spi.mdelay = (stmdev_mdelay_ptr) stmemsc_mdelay;

data->ctx = &data->ctx_spi;
data->ctx->handle = data;
data->ctx->handle = (void *)dev;

return 0;
}
Expand Down

0 comments on commit 4ee116c

Please sign in to comment.