drivers/battery: Handle the early changed event correctly
since it may happen before battery_xxx_register sometime Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
This commit is contained in:
parent
013a562478
commit
992747cef3
@ -467,6 +467,16 @@ int battery_charger_changed(FAR struct battery_charger_dev_s *dev,
|
||||
FAR struct battery_charger_priv_s *priv;
|
||||
int ret;
|
||||
|
||||
/* Event happen too early? */
|
||||
|
||||
if (list_is_clear(&dev->flist))
|
||||
{
|
||||
/* Yes, record it and return directly */
|
||||
|
||||
dev->mask |= mask;
|
||||
return 0;
|
||||
}
|
||||
|
||||
ret = nxsem_wait_uninterruptible(&dev->batsem);
|
||||
if (ret < 0)
|
||||
{
|
||||
|
@ -435,6 +435,16 @@ int battery_gauge_changed(FAR struct battery_gauge_dev_s *dev,
|
||||
FAR struct battery_gauge_priv_s *priv;
|
||||
int ret;
|
||||
|
||||
/* Event happen too early? */
|
||||
|
||||
if (list_is_clear(&dev->flist))
|
||||
{
|
||||
/* Yes, record it and return directly */
|
||||
|
||||
dev->mask |= mask;
|
||||
return 0;
|
||||
}
|
||||
|
||||
ret = nxsem_wait_uninterruptible(&dev->batsem);
|
||||
if (ret < 0)
|
||||
{
|
||||
|
@ -510,6 +510,16 @@ int battery_monitor_changed(FAR struct battery_monitor_dev_s *dev,
|
||||
FAR struct battery_monitor_priv_s *priv;
|
||||
int ret;
|
||||
|
||||
/* Event happen too early? */
|
||||
|
||||
if (list_is_clear(&dev->flist))
|
||||
{
|
||||
/* Yes, record it and return directly */
|
||||
|
||||
dev->mask |= mask;
|
||||
return 0;
|
||||
}
|
||||
|
||||
ret = nxsem_wait_uninterruptible(&dev->batsem);
|
||||
if (ret < 0)
|
||||
{
|
||||
|
@ -390,6 +390,11 @@ static inline bool list_is_empty(FAR struct list_node *list)
|
||||
return (list->next == list) ? true : false;
|
||||
}
|
||||
|
||||
static inline bool list_is_clear(FAR struct list_node *list)
|
||||
{
|
||||
return (list->next == NULL) ? true : false;
|
||||
}
|
||||
|
||||
static inline size_t list_length(FAR struct list_node *list)
|
||||
{
|
||||
FAR struct list_node *node = list;
|
||||
|
Loading…
Reference in New Issue
Block a user