diff options
author | Roland Dreier <rolandd@cisco.com> | 2006-03-20 13:08:25 -0500 |
---|---|---|
committer | Roland Dreier <rolandd@cisco.com> | 2006-03-20 13:08:25 -0500 |
commit | 048975ac580a771fc5bb96c6b454cba897ab1a73 (patch) | |
tree | 32405003b3cb78a3e2ccf765868f60a273c1313b /drivers/infiniband | |
parent | 0b3ea0829cbcdaee6e018a83a2949ef458213f3b (diff) |
IB: Coverity fixes to sysfs.c
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>
Diffstat (limited to 'drivers/infiniband')
-rw-r--r-- | drivers/infiniband/core/sysfs.c | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/drivers/infiniband/core/sysfs.c b/drivers/infiniband/core/sysfs.c index 49601bb8475b..15121cb5a1f6 100644 --- a/drivers/infiniband/core/sysfs.c +++ b/drivers/infiniband/core/sysfs.c | |||
@@ -112,7 +112,7 @@ static ssize_t state_show(struct ib_port *p, struct port_attribute *unused, | |||
112 | return ret; | 112 | return ret; |
113 | 113 | ||
114 | return sprintf(buf, "%d: %s\n", attr.state, | 114 | return sprintf(buf, "%d: %s\n", attr.state, |
115 | attr.state >= 0 && attr.state <= ARRAY_SIZE(state_name) ? | 115 | attr.state >= 0 && attr.state < ARRAY_SIZE(state_name) ? |
116 | state_name[attr.state] : "UNKNOWN"); | 116 | state_name[attr.state] : "UNKNOWN"); |
117 | } | 117 | } |
118 | 118 | ||
@@ -472,8 +472,10 @@ alloc_group_attrs(ssize_t (*show)(struct ib_port *, | |||
472 | goto err; | 472 | goto err; |
473 | 473 | ||
474 | if (snprintf(element->name, sizeof(element->name), | 474 | if (snprintf(element->name, sizeof(element->name), |
475 | "%d", i) >= sizeof(element->name)) | 475 | "%d", i) >= sizeof(element->name)) { |
476 | kfree(element); | ||
476 | goto err; | 477 | goto err; |
478 | } | ||
477 | 479 | ||
478 | element->attr.attr.name = element->name; | 480 | element->attr.attr.name = element->name; |
479 | element->attr.attr.mode = S_IRUGO; | 481 | element->attr.attr.mode = S_IRUGO; |