IB/mthca: Avoid integer overflow when dealing with profile size

mthca_make_profile() returns the size in bytes of the HCA context
layout it creates, or a negative value if an error occurs.  However,
the return value is declared as u64 and the memfree initialization
path casts this value to int to test if it is negative.  This makes it
think incorrectly than an error has occurred if the context size
happens to be bigger than 2GB, since this turns into a negative int.

Fix this by having mthca_make_profile() return an s64 and testing
for an error by checking whether this 64-bit value itself is negative.

Signed-off-by: Roland Dreier <rolandd@cisco.com>
This commit is contained in:
Roland Dreier
2008-04-16 21:01:13 -07:00
parent f4f82994d1
commit 19773539d6
3 changed files with 10 additions and 7 deletions

View File

@@ -63,7 +63,7 @@ enum {
MTHCA_NUM_PDS = 1 << 15
};
u64 mthca_make_profile(struct mthca_dev *dev,
s64 mthca_make_profile(struct mthca_dev *dev,
struct mthca_profile *request,
struct mthca_dev_lim *dev_lim,
struct mthca_init_hca_param *init_hca)
@@ -77,7 +77,7 @@ u64 mthca_make_profile(struct mthca_dev *dev,
};
u64 mem_base, mem_avail;
u64 total_size = 0;
s64 total_size = 0;
struct mthca_resource *profile;
struct mthca_resource tmp;
int i, j;