From 4617721c502b2ddaa4e324e86da4997edf738fa5 Mon Sep 17 00:00:00 2001 From: Steven Rostedt Date: Wed, 2 Sep 2026 09:55:01 -0400 Subject: ftrace: Synchronize the initialization of ftrace_ops There's some internal state that ftrace_ops needs to have set, but since it can be declared outside of the ftrace.c code, it calls ftrace_ops_init() on the ops in every global function. The issue is that if two tasks call it on the same ops at the same time it is possible to have the initialization of one corrupt the initialization of the other call. Create a ops_mutex to use to synchronize every initialization of the ftrace_ops. The mutex is taken within checking the ftrace_ops flag that states it was initializied but the flag is checked again after the mutex has been taken. Checking first outside the mutex allows it to shortcut having to take the mutex. But then the check needs to be done again after the mute is taken in case of races. Cc: stable@vger.kernel.org Link: https://patch.msgid.link/20260902095501.6b59af20@gandalf.local.home Fixes: f04f24fb7e48d ("ftrace, kprobes: Fix a deadlock on ftrace_regex_lock") Reported-by: sashiko-bot@kernel.org Close: https://lore.kernel.org/all/20260829025528.49A831F000E9@smtp.kernel.org/ Signed-off-by: Steven Rostedt --- drivers/gnss/ubx.c | 153 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 153 insertions(+) create mode 100644 drivers/gnss/ubx.c (limited to 'drivers/gnss/ubx.c') diff --git a/drivers/gnss/ubx.c b/drivers/gnss/ubx.c new file mode 100644 index 000000000..23894ff75 --- /dev/null +++ b/drivers/gnss/ubx.c @@ -0,0 +1,153 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * u-blox GNSS receiver driver + * + * Copyright (C) 2018 Johan Hovold + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "serial.h" + +struct ubx_data { + struct regulator *vcc; +}; + +static int ubx_set_active(struct gnss_serial *gserial) +{ + struct ubx_data *data = gnss_serial_get_drvdata(gserial); + int ret; + + ret = regulator_enable(data->vcc); + if (ret) + return ret; + + return 0; +} + +static int ubx_set_standby(struct gnss_serial *gserial) +{ + struct ubx_data *data = gnss_serial_get_drvdata(gserial); + int ret; + + ret = regulator_disable(data->vcc); + if (ret) + return ret; + + return 0; +} + +static int ubx_set_power(struct gnss_serial *gserial, + enum gnss_serial_pm_state state) +{ + switch (state) { + case GNSS_SERIAL_ACTIVE: + return ubx_set_active(gserial); + case GNSS_SERIAL_OFF: + case GNSS_SERIAL_STANDBY: + return ubx_set_standby(gserial); + } + + return -EINVAL; +} + +static const struct gnss_serial_ops ubx_gserial_ops = { + .set_power = ubx_set_power, +}; + +static int ubx_probe(struct serdev_device *serdev) +{ + struct gnss_serial *gserial; + struct gpio_desc *safeboot; + struct gpio_desc *reset; + struct ubx_data *data; + int ret; + + gserial = gnss_serial_allocate(serdev, sizeof(*data)); + if (IS_ERR(gserial)) { + ret = PTR_ERR(gserial); + return ret; + } + + gserial->ops = &ubx_gserial_ops; + + gserial->gdev->type = GNSS_TYPE_UBX; + + data = gnss_serial_get_drvdata(gserial); + + data->vcc = devm_regulator_get(&serdev->dev, "vcc"); + if (IS_ERR(data->vcc)) { + ret = PTR_ERR(data->vcc); + goto err_free_gserial; + } + + ret = devm_regulator_get_enable_optional(&serdev->dev, "v-bckp"); + if (ret < 0 && ret != -ENODEV) + goto err_free_gserial; + + /* Deassert safeboot */ + safeboot = devm_gpiod_get_optional(&serdev->dev, "safeboot", GPIOD_OUT_LOW); + if (IS_ERR(safeboot)) { + ret = PTR_ERR(safeboot); + goto err_free_gserial; + } + + /* Deassert reset */ + reset = devm_gpiod_get_optional(&serdev->dev, "reset", GPIOD_OUT_LOW); + if (IS_ERR(reset)) { + ret = PTR_ERR(reset); + goto err_free_gserial; + } + + ret = gnss_serial_register(gserial); + if (ret) + goto err_free_gserial; + + return 0; + +err_free_gserial: + gnss_serial_free(gserial); + + return ret; +} + +static void ubx_remove(struct serdev_device *serdev) +{ + struct gnss_serial *gserial = serdev_device_get_drvdata(serdev); + + gnss_serial_deregister(gserial); + gnss_serial_free(gserial); +} + +#ifdef CONFIG_OF +static const struct of_device_id ubx_of_match[] = { + { .compatible = "u-blox,neo-6m" }, + { .compatible = "u-blox,neo-8" }, + { .compatible = "u-blox,neo-m8" }, + {}, +}; +MODULE_DEVICE_TABLE(of, ubx_of_match); +#endif + +static struct serdev_device_driver ubx_driver = { + .driver = { + .name = "gnss-ubx", + .of_match_table = of_match_ptr(ubx_of_match), + .pm = &gnss_serial_pm_ops, + }, + .probe = ubx_probe, + .remove = ubx_remove, +}; +module_serdev_device_driver(ubx_driver); + +MODULE_AUTHOR("Johan Hovold "); +MODULE_DESCRIPTION("u-blox GNSS receiver driver"); +MODULE_LICENSE("GPL v2"); -- cgit v1.3.1