diff options
| author | Tzung-Bi Shih <tzungbi@kernel.org> | 2025-08-28 08:36:00 +0000 |
|---|---|---|
| committer | Tzung-Bi Shih <tzungbi@kernel.org> | 2025-09-14 11:34:41 +0800 |
| commit | 56cb557279d70397cefb497e0f06bdd6fd685f8e (patch) | |
| tree | a863b7f72ea4e475ae1363a96da57e4cad1a9687 /drivers/platform/chrome/cros_ec.c | |
| parent | 7a79b0bfd8b3995a39d25bffcf57273635c0e542 (diff) | |
platform/chrome: cros_ec: Add a flag to track registration state
Introduce a `registered` flag to the `struct cros_ec_device` to allow
callers to determine if the device has been fully registered and is
ready for use.
This is a preparatory step to prevent race conditions where other drivers
might try to access the device before it is fully registered or after
it has been unregistered.
Link: https://lore.kernel.org/r/20250828083601.856083-5-tzungbi@kernel.org
Signed-off-by: Tzung-Bi Shih <tzungbi@kernel.org>
Diffstat (limited to 'drivers/platform/chrome/cros_ec.c')
| -rw-r--r-- | drivers/platform/chrome/cros_ec.c | 7 |
1 files changed, 7 insertions, 0 deletions
diff --git a/drivers/platform/chrome/cros_ec.c b/drivers/platform/chrome/cros_ec.c index 61bcef8741db..1da79e3d215b 100644 --- a/drivers/platform/chrome/cros_ec.c +++ b/drivers/platform/chrome/cros_ec.c @@ -9,6 +9,7 @@ * battery charging and regulator control, firmware update. */ +#include <linux/cleanup.h> #include <linux/interrupt.h> #include <linux/module.h> #include <linux/of_platform.h> @@ -316,6 +317,9 @@ int cros_ec_register(struct cros_ec_device *ec_dev) goto exit; } + scoped_guard(mutex, &ec_dev->lock) + ec_dev->registered = true; + dev_info(dev, "Chrome EC device registered\n"); /* @@ -343,6 +347,9 @@ EXPORT_SYMBOL(cros_ec_register); */ void cros_ec_unregister(struct cros_ec_device *ec_dev) { + scoped_guard(mutex, &ec_dev->lock) + ec_dev->registered = false; + if (ec_dev->mkbp_event_supported) blocking_notifier_chain_unregister(&ec_dev->event_notifier, &ec_dev->notifier_ready); |