diff --git a/drivers/sensors/sensor.c b/drivers/sensors/sensor.c index 8d59c80747c..c170189bbfe 100644 --- a/drivers/sensors/sensor.c +++ b/drivers/sensors/sensor.c @@ -1027,6 +1027,7 @@ static int sensor_ioctl(FAR struct file *filep, int cmd, unsigned long arg) return -EINVAL; } + ret = -ENOTSUP; if (lower->ops->flush != NULL) { /* Lower half driver will do flush in asynchronous mode, @@ -1040,12 +1041,25 @@ static int sensor_ioctl(FAR struct file *filep, int cmd, unsigned long arg) user->flushing = true; } } - else + + if (ret == -ENOTSUP) { /* If flush is not supported, complete immediately */ + user->flushing = false; user->event |= SENSOR_EVENT_FLUSH_COMPLETE; sensor_pollnotify_one(user, POLLPRI, user->role); + + /* If caller isn't from remote core, convert ENOTSUP + * to zero return, indicating the flush is completed. + * If it's from remote core, need to inform the remote + * core the flush is not supported for driver. + */ + + if ((filep->f_oflags & SENSOR_REMOTE) == 0) + { + ret = 0; + } } nxrmutex_unlock(&upper->lock); diff --git a/drivers/sensors/sensor_rpmsg.c b/drivers/sensors/sensor_rpmsg.c index f10af1692f8..892d059be2a 100644 --- a/drivers/sensors/sensor_rpmsg.c +++ b/drivers/sensors/sensor_rpmsg.c @@ -781,6 +781,17 @@ static int sensor_rpmsg_flush(FAR struct sensor_lowerhalf_s *lower, { ret = drv->ops->flush(drv, filep); } + else if ((filep->f_oflags & SENSOR_REMOTE) || + dev->nadvertisers > 0) + { + /* If the driver (drv) does not support the flush operation, + * and the caller is a remote invocation or the current device + * is an advertiser, then you can still consider the flush + * operation as unsupported and therefore return ENOTSUP + */ + + return -ENOTSUP; + } else if (!(filep->f_oflags & SENSOR_REMOTE)) { ret = sensor_rpmsg_ioctl(dev, SNIOC_FLUSH, 0, 0, true);