Skip to content

Commit

Permalink
IB: Coverity fixes to sysfs.c
Browse files Browse the repository at this point in the history
Fix two bugs found by coverity:
 - Memory leak in error path of alloc_group_attrs()
 - Fencepost error in state_show(): the test should be < ARRAY_SIZE(),
   not <= ARRAY_SIZE().

Signed-off-by: Roland Dreier <rolandd@cisco.com>
  • Loading branch information
Roland Dreier committed Mar 20, 2006
1 parent 0b3ea08 commit 048975a
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions drivers/infiniband/core/sysfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ static ssize_t state_show(struct ib_port *p, struct port_attribute *unused,
return ret;

return sprintf(buf, "%d: %s\n", attr.state,
attr.state >= 0 && attr.state <= ARRAY_SIZE(state_name) ?
attr.state >= 0 && attr.state < ARRAY_SIZE(state_name) ?
state_name[attr.state] : "UNKNOWN");
}

Expand Down Expand Up @@ -472,8 +472,10 @@ alloc_group_attrs(ssize_t (*show)(struct ib_port *,
goto err;

if (snprintf(element->name, sizeof(element->name),
"%d", i) >= sizeof(element->name))
"%d", i) >= sizeof(element->name)) {
kfree(element);
goto err;
}

element->attr.attr.name = element->name;
element->attr.attr.mode = S_IRUGO;
Expand Down

0 comments on commit 048975a

Please sign in to comment.