Skip to content

Commit 52f1133

Browse files
ClaCodescfriedt
authored andcommitted
drivers: gnss: quectel lcx6g: Fix overflow by using timepoint-API
Make use of the timepoint-API to fix a potential 32-bit unsigned int overflow in this driver. Signed-off-by: Cla Mattia Galliard <[email protected]>
1 parent 18f1abd commit 52f1133

File tree

1 file changed

+4
-6
lines changed

1 file changed

+4
-6
lines changed

drivers/gnss/gnss_quectel_lcx6g.c

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
#include <zephyr/logging/log.h>
2323
LOG_MODULE_REGISTER(quectel_lcx6g, CONFIG_GNSS_LOG_LEVEL);
2424

25-
#define QUECTEL_LCX6G_PM_TIMEOUT_MS 500U
25+
#define QUECTEL_LCX6G_PM_TIMEOUT K_MSEC(500U)
2626
#define QUECTEL_LCX6G_SCRIPT_TIMEOUT_S 10U
2727

2828
#define QUECTEL_LCX6G_PAIR_NAV_MODE_STATIONARY 4
@@ -74,7 +74,7 @@ struct quectel_lcx6g_data {
7474
};
7575

7676
struct k_sem lock;
77-
k_timeout_t pm_timeout;
77+
k_timepoint_t pm_deadline;
7878
};
7979

8080
#ifdef CONFIG_PM_DEVICE
@@ -182,18 +182,16 @@ static void quectel_lcx6g_unlock(const struct device *dev)
182182
static void quectel_lcx6g_pm_changed(const struct device *dev)
183183
{
184184
struct quectel_lcx6g_data *data = dev->data;
185-
uint32_t pm_ready_at_ms;
186185

187-
pm_ready_at_ms = k_uptime_get() + QUECTEL_LCX6G_PM_TIMEOUT_MS;
188-
data->pm_timeout = K_TIMEOUT_ABS_MS(pm_ready_at_ms);
186+
data->pm_deadline = sys_timepoint_calc(QUECTEL_LCX6G_PM_TIMEOUT);
189187
}
190188

191189
static void quectel_lcx6g_await_pm_ready(const struct device *dev)
192190
{
193191
struct quectel_lcx6g_data *data = dev->data;
194192

195193
LOG_INF("Waiting until PM ready");
196-
k_sleep(data->pm_timeout);
194+
k_sleep(sys_timepoint_timeout(data->pm_deadline));
197195
}
198196

199197
static int quectel_lcx6g_resume(const struct device *dev)

0 commit comments

Comments
 (0)