From 4ee116c3b4001c9d43ccecb5bb1a6f24c64a00b6 Mon Sep 17 00:00:00 2001 From: Tristan Honscheid Date: Thu, 6 Jul 2023 16:08:08 -0600 Subject: [PATCH] sensor: ism330dhcx: Incorrect handle passed to ctx struct in SPI mode 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 --- drivers/sensor/ism330dhcx/ism330dhcx_spi.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/sensor/ism330dhcx/ism330dhcx_spi.c b/drivers/sensor/ism330dhcx/ism330dhcx_spi.c index 5a20812caa12db..103978e65d5670 100644 --- a/drivers/sensor/ism330dhcx/ism330dhcx_spi.c +++ b/drivers/sensor/ism330dhcx/ism330dhcx_spi.c @@ -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; }