dect
/
libnl
Archived
13
0
Fork 0

use safe cache lookup variants internally

Signed-off-by: Thomas Graf <tgraf@suug.ch>
This commit is contained in:
Thomas Graf 2012-11-16 00:20:18 +01:00
parent 2b3912a320
commit cb82c2a545
4 changed files with 24 additions and 11 deletions

View File

@ -266,11 +266,13 @@ int nl_cache_alloc_name(const char *kind, struct nl_cache **result)
struct nl_cache_ops *ops;
struct nl_cache *cache;
ops = nl_cache_ops_lookup(kind);
ops = nl_cache_ops_lookup_safe(kind);
if (!ops)
return -NLE_NOCACHE;
if (!(cache = nl_cache_alloc(ops)))
cache = nl_cache_alloc(ops);
nl_cache_ops_put(ops);
if (!cache)
return -NLE_NOMEM;
*result = cache;

View File

@ -314,11 +314,12 @@ int nl_cache_mngr_add(struct nl_cache_mngr *mngr, const char *name,
struct nl_cache *cache;
int err;
ops = nl_cache_ops_lookup(name);
ops = nl_cache_ops_lookup_safe(name);
if (!ops)
return -NLE_NOCACHE;
cache = nl_cache_alloc(ops);
nl_cache_ops_put(ops);
if (!cache)
return -NLE_NOMEM;

View File

@ -733,14 +733,18 @@ int nl_msg_parse(struct nl_msg *msg, void (*cb)(struct nl_object *, void *),
.cb = cb,
.arg = arg,
};
int err;
ops = nl_cache_ops_associate(nlmsg_get_proto(msg),
nlmsg_hdr(msg)->nlmsg_type);
ops = nl_cache_ops_associate_safe(nlmsg_get_proto(msg),
nlmsg_hdr(msg)->nlmsg_type);
if (ops == NULL)
return -NLE_MSGTYPE_NOSUPPORT;
p.pp_arg = &x;
return nl_cache_parse(ops, NULL, nlmsg_hdr(msg), &p);
err = nl_cache_parse(ops, NULL, nlmsg_hdr(msg), &p);
nl_cache_ops_put(ops);
return err;
}
/** @} */
@ -801,13 +805,14 @@ static void print_hdr(FILE *ofd, struct nl_msg *msg)
fprintf(ofd, " .nlmsg_len = %d\n", nlh->nlmsg_len);
ops = nl_cache_ops_associate(nlmsg_get_proto(msg), nlh->nlmsg_type);
ops = nl_cache_ops_associate_safe(nlmsg_get_proto(msg), nlh->nlmsg_type);
if (ops) {
mt = nl_msgtype_lookup(ops, nlh->nlmsg_type);
if (!mt)
BUG();
snprintf(buf, sizeof(buf), "%s::%s", ops->co_name, mt->mt_name);
nl_cache_ops_put(ops);
} else
nl_nlmsgtype2str(nlh->nlmsg_type, buf, sizeof(buf));
@ -888,8 +893,8 @@ void nl_msg_dump(struct nl_msg *msg, FILE *ofd)
int payloadlen = nlmsg_len(hdr);
int attrlen = 0;
ops = nl_cache_ops_associate(nlmsg_get_proto(msg),
hdr->nlmsg_type);
ops = nl_cache_ops_associate_safe(nlmsg_get_proto(msg),
hdr->nlmsg_type);
if (ops) {
attrlen = nlmsg_attrlen(hdr, ops->co_hdrsize);
payloadlen -= attrlen;
@ -906,6 +911,9 @@ void nl_msg_dump(struct nl_msg *msg, FILE *ofd)
attrlen = nlmsg_attrlen(hdr, ops->co_hdrsize);
dump_attrs(ofd, attrs, attrlen, 0);
}
if (ops)
nl_cache_ops_put(ops);
}
fprintf(ofd,

View File

@ -85,11 +85,13 @@ int nl_object_alloc_name(const char *kind, struct nl_object **result)
{
struct nl_cache_ops *ops;
ops = nl_cache_ops_lookup(kind);
ops = nl_cache_ops_lookup_safe(kind);
if (!ops)
return -NLE_OPNOTSUPP;
if (!(*result = nl_object_alloc(ops->co_obj_ops)))
*result = nl_object_alloc(ops->co_obj_ops);
nl_cache_ops_put(ops);
if (!*result)
return -NLE_NOMEM;
return 0;