frame-xchg: Fix frame_watch_remove_by_handler for group 0
PATCH 1/2 frame-xchg: Fix frame_watch_remove_by_handler for group 0
Don't match the default group's (group_id 0) wdev_id against the provided wdev_id because the default group can be used on all wdevs and its wdev_id is 0. Also match individual item's wdev_id in the group to make up for this although it normally wouldn't matter.
--- src/frame-xchg.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-)
src/frame-xchg.c +5 -3
@@ -661,6 +661,7 @@ bool frame_watch_wdev_remove(uint64_t wdev_id) }struct frame_watch_handler_check_info { +uint64_t wdev_id;frame_watch_cb_t handler;void *user_data; };
@@ -671,7 +672,8 @@ static bool frame_watch_item_remove_by_handler(void *data, void *user_data) l_container_of(data, struct frame_watch, super);struct frame_watch_handler_check_info *info = user_data; -if (watch->super.notify != info->handler || +if (watch->wdev_id != info->wdev_id || + watch->super.notify != info->handler || watch->super.notify_data != info->user_data)return false;
@@ -702,9 +704,9 @@ static bool frame_watch_remove_by_handler(uint64_t wdev_id, uint32_t group_id, void *user_data) {struct watch_group_match_info group_info = - { wdev_id, group_id }; + { group_id ==0 ?0 : wdev_id, group_id };struct frame_watch_handler_check_info handler_info = - { handler, user_data }; + { wdev_id, handler, user_data };struct watch_group *group =l_queue_find (watch_groups, frame_watch_group_match, &group_info);
Signature · 1 line
2.25.1
PATCH 2/2 frame-xchg: Use frame_watch_group_match in frame_watch_group_get
--- src/frame-xchg.c | 42 +++++++++++++++++++----------------------- 1 file changed, 19 insertions(+), 23 deletions(-)
src/frame-xchg.c +19 -23
@@ -439,21 +439,30 @@ err:return NULL ; } -static struct watch_group *frame_watch_group_get (uint64_t wdev_id,uint32_t id) +struct watch_group_match_info { +uint64_t wdev_id; +uint32_t id; +}; + +static bool frame_watch_group_match (const void *a,const void *b) { -const struct l_queue_entry *entry; -struct watch_group *group; +const struct watch_group *group = a; +const struct watch_group_match_info *info = b; -for (entry =l_queue_get_entries (watch_groups); entry; - entry = entry->next) { - group = entry->data; +return group->wdev_id == info->wdev_id && group->id == info->id; +} -if (group->id == id && (id ==0 || group->wdev_id == wdev_id)) -return group; +static struct watch_group *frame_watch_group_get (uint64_t wdev_id,uint32_t id) +{ +struct watch_group_match_info info = { id ==0 ?0 : wdev_id, id }; +struct watch_group *group =l_queue_find (watch_groups, + frame_watch_group_match, &info); + +if (!group) { + group =frame_watch_group_new (wdev_id, id); +l_queue_push_tail (watch_groups, group); } - group =frame_watch_group_new (wdev_id, id); -l_queue_push_tail (watch_groups, group);return group; }
@@ -590,19 +599,6 @@ bool frame_watch_add(uint64_t wdev_id, uint32_t group_id, uint16_t frame_type,return true; } -struct watch_group_match_info { -uint64_t wdev_id; -uint32_t id; -}; - -static bool frame_watch_group_match (const void *a,const void *b) -{ -const struct watch_group *group = a; -const struct watch_group_match_info *info = b; - -return group->wdev_id == info->wdev_id && group->id == info->id; -} -bool frame_watch_group_remove (uint64_t wdev_id,uint32_t group_id) {struct watch_group_match_info info = { wdev_id, group_id };
Signature · 1 line
2.25.1
Hi Andrew,
Quoted 8 lines · Andrew Zaborowski
Don't match the default group's (
group_id0)wdev_idagainst the providedwdev_idbecause the default group can be used on all wdevs and itswdev_idis 0. Also match individual item'swdev_idin the group to make up for this although it normally wouldn't matter.--- src/frame-xchg.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-)
Both applied, thanks.
Regards,
-Denis