From 38393cfc940d3032325c6dc6de60b870fc0ea0ac Mon Sep 17 00:00:00 2001 From: Jiuzhu Dong Date: Tue, 14 Jun 2022 11:44:24 +0800 Subject: [PATCH] driver/sensor: move register_driver to end to avoid race condition Signed-off-by: Jiuzhu Dong --- drivers/sensors/sensor.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/drivers/sensors/sensor.c b/drivers/sensors/sensor.c index 89b47813ba..ac487bb39f 100644 --- a/drivers/sensors/sensor.c +++ b/drivers/sensors/sensor.c @@ -1048,14 +1048,6 @@ int sensor_custom_register(FAR struct sensor_lowerhalf_s *lower, lower->nbuffer = 0; } - upper->state.nbuffer = lower->nbuffer; - sninfo("Registering %s\n", path); - ret = register_driver(path, &g_sensor_fops, 0666, upper); - if (ret) - { - goto drv_err; - } - #ifdef CONFIG_SENSORS_RPMSG lower = sensor_rpmsg_register(lower, path); if (lower == NULL) @@ -1065,7 +1057,15 @@ int sensor_custom_register(FAR struct sensor_lowerhalf_s *lower, } #endif + upper->state.nbuffer = lower->nbuffer; upper->lower = lower; + sninfo("Registering %s\n", path); + ret = register_driver(path, &g_sensor_fops, 0666, upper); + if (ret) + { + goto drv_err; + } + return ret; drv_err: