Skip to content

Commit cebd1c7

Browse files
jilaypandyanashif
authored andcommitted
drivers: sensor: emul_bmi160: fix cid 215232
This commit fixes the issue of Null pointer dereferencing Signed-off-by: Jilay Pandya <[email protected]>
1 parent 532c775 commit cebd1c7

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

drivers/sensor/bosch/bmi160/emul_bmi160.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -180,10 +180,15 @@ static int bmi160_emul_io_spi(const struct emul *target, const struct spi_config
180180
LOG_DBG("Unknown tx_bufs->count %d", count);
181181
return -EIO;
182182
}
183-
tx = tx_bufs->buffers;
184-
txd = &tx_bufs->buffers[1];
183+
tx = tx_bufs ? tx_bufs->buffers : NULL;
184+
txd = tx_bufs ? &tx_bufs->buffers[1] : NULL;
185185
rxd = rx_bufs ? &rx_bufs->buffers[1] : NULL;
186186

187+
if (tx == NULL) {
188+
LOG_DBG("tx cannot be NULL");
189+
return -EIO;
190+
}
191+
187192
if (tx->len != 1) {
188193
LOG_DBG("Unknown tx->len %d", tx->len);
189194
return -EIO;

0 commit comments

Comments
 (0)