Skip to content

Commit 8fee983

Browse files
alexapostoludanieldegrasse
authored andcommitted
drivers: sensor: asahi_kasei: akm09918c: Null check before dereference
cb_sqe could have been NULL before being passed into the callback function, which expects cb_sqe to be non-NULL. Add NULL check before the callback function with cb_sqe is called. The reordering of the callback function after the sqe drop is okay as the sqe drop is called when cb_sqe is NULL and the callback function isn't expected to work when cb_sqe is NULL. Signed-off-by: Alexander Apostolu <apostolu240@gmail.com>
1 parent 789a0a8 commit 8fee983

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

drivers/sensor/asahi_kasei/akm09918c/akm09918c_async.c

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -138,15 +138,16 @@ void akm09918_async_fetch(struct k_work *work)
138138

139139
struct rtio_sqe *cb_sqe = rtio_sqe_acquire(data->rtio_ctx);
140140

141-
rtio_sqe_prep_callback_no_cqe(cb_sqe, akm09918_complete_cb, (void *)ctx->iodev_sqe, NULL);
142-
143-
if (burstRead_sqe != NULL && cb_sqe != NULL) {
144-
burstRead_sqe->flags |= RTIO_SQE_CHAINED;
145-
rtio_submit(data->rtio_ctx, 0);
146-
} else {
141+
if (burstRead_sqe == NULL || cb_sqe == NULL) {
147142
rtio_sqe_drop_all(data->rtio_ctx);
148143
rtio_iodev_sqe_err(ctx->iodev_sqe, -ENOMEM);
144+
return;
149145
}
146+
147+
rtio_sqe_prep_callback_no_cqe(cb_sqe, akm09918_complete_cb, (void *)ctx->iodev_sqe, NULL);
148+
149+
burstRead_sqe->flags |= RTIO_SQE_CHAINED;
150+
rtio_submit(data->rtio_ctx, 0);
150151
}
151152

152153
void akm09918_complete_cb(struct rtio *rtio_ctx, const struct rtio_sqe *sqe, void *arg0)

0 commit comments

Comments
 (0)