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>pull/1354/merge
parent
7a79b0bfd8
commit
56cb557279
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@
|
|||
//
|
||||
// Copyright (C) 2015 Google, Inc
|
||||
|
||||
#include <linux/cleanup.h>
|
||||
#include <linux/delay.h>
|
||||
#include <linux/device.h>
|
||||
#include <linux/limits.h>
|
||||
|
|
@ -1153,5 +1154,19 @@ int cros_ec_get_cmd_versions(struct cros_ec_device *ec_dev, u16 cmd)
|
|||
}
|
||||
EXPORT_SYMBOL_GPL(cros_ec_get_cmd_versions);
|
||||
|
||||
/**
|
||||
* cros_ec_device_registered - Return if the ec_dev is registered.
|
||||
*
|
||||
* @ec_dev: EC device
|
||||
*
|
||||
* Return: true if registered. Otherwise, false.
|
||||
*/
|
||||
bool cros_ec_device_registered(struct cros_ec_device *ec_dev)
|
||||
{
|
||||
guard(mutex)(&ec_dev->lock);
|
||||
return ec_dev->registered;
|
||||
}
|
||||
EXPORT_SYMBOL_GPL(cros_ec_device_registered);
|
||||
|
||||
MODULE_LICENSE("GPL");
|
||||
MODULE_DESCRIPTION("ChromeOS EC communication protocol helpers");
|
||||
|
|
|
|||
|
|
@ -128,6 +128,7 @@ struct cros_ec_command {
|
|||
* @dout_size: Size of dout buffer to allocate (zero to use static dout).
|
||||
* @wake_enabled: True if this device can wake the system from sleep.
|
||||
* @suspended: True if this device had been suspended.
|
||||
* @registered: True if this device had been registered.
|
||||
* @cmd_xfer: Send command to EC and get response.
|
||||
* Returns the number of bytes received if the communication
|
||||
* succeeded, but that doesn't mean the EC was happy with the
|
||||
|
|
@ -186,6 +187,7 @@ struct cros_ec_device {
|
|||
int dout_size;
|
||||
bool wake_enabled;
|
||||
bool suspended;
|
||||
bool registered;
|
||||
int (*cmd_xfer)(struct cros_ec_device *ec,
|
||||
struct cros_ec_command *msg);
|
||||
int (*pkt_xfer)(struct cros_ec_device *ec,
|
||||
|
|
@ -278,6 +280,8 @@ int cros_ec_cmd_readmem(struct cros_ec_device *ec_dev, u8 offset, u8 size, void
|
|||
|
||||
int cros_ec_get_cmd_versions(struct cros_ec_device *ec_dev, u16 cmd);
|
||||
|
||||
bool cros_ec_device_registered(struct cros_ec_device *ec_dev);
|
||||
|
||||
/**
|
||||
* cros_ec_get_time_ns() - Return time in ns.
|
||||
*
|
||||
|
|
|
|||
Loading…
Reference in New Issue