Skip to content

Commit

Permalink
cache: use the new _nl_auto_nl_object helper
Browse files Browse the repository at this point in the history
Use the new _nl_auto_nl_object helper for cache where appropriate. Make
sure to initialze *old to NULL in cache_include() as we do not
initialize it in the error path for unknown actions.

Signed-off-by: Jonas Gorski <[email protected]>
  • Loading branch information
KanjiMonster authored and thom311 committed Sep 12, 2024
1 parent 4b9daa6 commit 831e986
Showing 1 changed file with 4 additions and 12 deletions.
16 changes: 4 additions & 12 deletions lib/cache.c
Original file line number Diff line number Diff line change
Expand Up @@ -714,17 +714,14 @@ static int __cache_pickup(struct nl_sock *sk, struct nl_cache *cache,
static int pickup_checkdup_cb(struct nl_object *c, struct nl_parser_param *p)
{
struct nl_cache *cache = (struct nl_cache *)p->pp_arg;
struct nl_object *old;
_nl_auto_nl_object struct nl_object *old = NULL;

old = nl_cache_search(cache, c);
if (old) {
if (nl_object_update(old, c) == 0) {
nl_object_put(old);
if (nl_object_update(old, c) == 0)
return 0;
}

nl_cache_remove(old);
nl_object_put(old);
}

return nl_cache_add(cache, c);
Expand Down Expand Up @@ -788,8 +785,8 @@ static int cache_include(struct nl_cache *cache, struct nl_object *obj,
struct nl_msgtype *type, change_func_t cb,
change_func_v2_t cb_v2, void *data)
{
struct nl_object *old;
struct nl_object *clone = NULL;
_nl_auto_nl_object struct nl_object *old = NULL;
_nl_auto_nl_object struct nl_object *clone = NULL;
uint64_t diff = 0;

switch (type->mt_act) {
Expand All @@ -813,19 +810,15 @@ static int cache_include(struct nl_cache *cache, struct nl_object *obj,
nl_object_put(clone);
} else if (cb)
cb(cache, old, NL_ACT_CHANGE, data);
nl_object_put(old);
return 0;
}
nl_object_put(clone);

nl_cache_remove(old);
if (type->mt_act == NL_ACT_DEL) {
if (cb_v2)
cb_v2(cache, old, NULL, 0, NL_ACT_DEL,
data);
else if (cb)
cb(cache, old, NL_ACT_DEL, data);
nl_object_put(old);
}
}

Expand All @@ -847,7 +840,6 @@ static int cache_include(struct nl_cache *cache, struct nl_object *obj,
} else if (diff && cb)
cb(cache, obj, NL_ACT_CHANGE, data);

nl_object_put(old);
}
}
break;
Expand Down

0 comments on commit 831e986

Please sign in to comment.