[bug report] devlink: introduce object and nested devlink relationship infra
From: Dan Carpenter <hidden>
Date: 2025-02-19 09:53:40
Hello Jiri Pirko,
Commit c137743bce02 ("devlink: introduce object and nested devlink
relationship infra") from Sep 13, 2023 (linux-next), leads to the
following Smatch static checker warning:
net/devlink/core.c:118 xa_alloc_cyclic() also returns 1 on success
net/devlink/core.c
108 static struct devlink_rel *devlink_rel_alloc(void)
109 {
110 struct devlink_rel *rel;
111 static u32 next;
112 int err;
113
114 rel = kzalloc(sizeof(*rel), GFP_KERNEL);
115 if (!rel)
116 return ERR_PTR(-ENOMEM);
117
--> 118 err = xa_alloc_cyclic(&devlink_rels, &rel->index, rel,
119 xa_limit_32b, &next, GFP_KERNEL);
120 if (err) {
121 kfree(rel);
122 return ERR_PTR(err);
Obviously, returning ERR_PTR(1) is not allowed, but I'm not totally clear
on the rules if xa_alloc_cyclic() can actually return 1 here. Although
even if it can't return 1 here we should still write the check as
if (err < 0) {
123 }
124
125 refcount_set(&rel->refcount, 1);
126 INIT_DELAYED_WORK(&rel->nested_in.notify_work,
127 &devlink_rel_nested_in_notify_work);
128 return rel;
regards,
dan carpenter