Skip to content

Commit 24c0583

Browse files
ubiedafabiobaltieri
authored andcommitted
bmm350: Set streaming handle to NULL when done
To follow with error-handling of multi-shot items, they won't be marked as cancelled. Instead, we expect them to stop being submitted, hence we dispose the handle upon finishing every shot. Signed-off-by: Luis Ubieda <[email protected]>
1 parent 2e2d4af commit 24c0583

File tree

1 file changed

+18
-11
lines changed

1 file changed

+18
-11
lines changed

drivers/sensor/bosch/bmm350/bmm350_stream.c

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,19 @@ enum bmm350_stream_state {
2020
BMM350_STREAM_BUSY = 2,
2121
};
2222

23+
static void bmm350_stream_result(const struct device *dev, int err)
24+
{
25+
struct bmm350_data *data = dev->data;
26+
struct rtio_iodev_sqe *iodev_sqe = data->stream.iodev_sqe;
27+
28+
data->stream.iodev_sqe = NULL;
29+
if (err < 0) {
30+
rtio_iodev_sqe_err(iodev_sqe, err);
31+
} else {
32+
rtio_iodev_sqe_ok(iodev_sqe, 0);
33+
}
34+
}
35+
2336
static void bmm350_stream_event_complete(struct rtio *ctx, const struct rtio_sqe *sqe, void *arg0)
2437
{
2538
struct rtio_iodev_sqe *iodev_sqe = (struct rtio_iodev_sqe *)arg0;
@@ -69,13 +82,7 @@ static void bmm350_stream_event_complete(struct rtio *ctx, const struct rtio_sqe
6982

7083
bmm350_stream_evt_finish:
7184
atomic_set(&data->stream.state, BMM350_STREAM_ON);
72-
73-
if (err < 0) {
74-
rtio_iodev_sqe_err(iodev_sqe, err);
75-
} else {
76-
rtio_iodev_sqe_ok(iodev_sqe, 0);
77-
}
78-
85+
bmm350_stream_result(dev, err);
7986
}
8087

8188
static void bmm350_event_handler(const struct device *dev)
@@ -115,7 +122,7 @@ static void bmm350_event_handler(const struct device *dev)
115122
&buf, &buf_len);
116123
CHECKIF(err != 0 || buf_len < sizeof(struct bmm350_encoded_data)) {
117124
LOG_ERR("Failed to allocate BMM350 encoded buffer: %d", err);
118-
rtio_iodev_sqe_err(iodev_sqe, -ENOMEM);
125+
bmm350_stream_result(dev, -ENOMEM);
119126
return;
120127
}
121128

@@ -127,7 +134,7 @@ static void bmm350_event_handler(const struct device *dev)
127134
edata->payload.buf, sizeof(edata->payload.buf),
128135
&read_sqe);
129136
CHECKIF(err < 0 || !read_sqe) {
130-
rtio_iodev_sqe_err(iodev_sqe, err);
137+
bmm350_stream_result(dev, err);
131138
return;
132139
}
133140
read_sqe->flags |= RTIO_SQE_CHAINED;
@@ -169,14 +176,14 @@ void bmm350_stream_submit(const struct device *dev,
169176
/* Set PMU command configuration */
170177
err = bmm350_prep_reg_write_async(dev, BMM350_REG_INT_CTRL, cfg->int_flags, NULL);
171178
if (err < 0) {
172-
rtio_iodev_sqe_err(iodev_sqe, err);
179+
bmm350_stream_result(dev, err);
173180
return;
174181
}
175182
rtio_submit(cfg->bus.rtio.ctx, 0);
176183

177184
err = gpio_pin_interrupt_configure_dt(&cfg->drdy_int, GPIO_INT_EDGE_TO_ACTIVE);
178185
if (err < 0) {
179-
rtio_iodev_sqe_err(iodev_sqe, err);
186+
bmm350_stream_result(dev, err);
180187
return;
181188
}
182189
}

0 commit comments

Comments
 (0)