Skip to content

Commit b44eef0

Browse files
committed
libibumad: Increase max device supported to 128
- Create new struct on the heap to prevent allocation of too much memory on the stack Fixes: be54b52 ("libibumad: Add new API to support SMI/GSI seperation") Signed-off-by: Asaf Mazor <amazor@nvidia.com>
1 parent 2241546 commit b44eef0

2 files changed

Lines changed: 15 additions & 6 deletions

File tree

libibumad/umad.c

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,9 @@ struct guid_ca_pairs_mapping {
9090
struct umad_ca_pair *ca_pair;
9191
};
9292

93+
typedef struct { char _ca_names_arr[UMAD_MAX_DEVICES][UMAD_CA_NAME_LEN]; } ca_names_t;
94+
95+
9396
#define IBWARN(fmt, args...) fprintf(stderr, "ibwarn: [%d] %s: " fmt "\n", getpid(), __func__, ## args)
9497

9598
#define TRACE if (umaddebug) IBWARN
@@ -1476,24 +1479,28 @@ static int count_ports_by_guid(char legacy_ca_names[][UMAD_CA_NAME_LEN], size_t
14761479
int umad_get_smi_gsi_pairs(struct umad_ca_pair cas[], size_t max)
14771480
{
14781481
size_t added_devices = 0, added_mappings = 0;
1479-
char legacy_ca_names[UMAD_MAX_DEVICES][UMAD_CA_NAME_LEN] = {};
1482+
ca_names_t *legacy_ca_names = malloc(sizeof(ca_names_t));
1483+
if (!legacy_ca_names)
1484+
return -1;
14801485
struct port_guid_port_count counts[UMAD_MAX_PORTS] = {};
14811486
struct guid_ca_pairs_mapping mapping[UMAD_MAX_PORTS] = {};
14821487

14831488
memset(cas, 0, sizeof(struct umad_ca_pair) * max);
1484-
int cas_found = umad_get_cas_names(legacy_ca_names, UMAD_MAX_DEVICES);
1489+
int cas_found = umad_get_cas_names(legacy_ca_names->_ca_names_arr, UMAD_MAX_DEVICES);
14851490

1486-
if (cas_found < 0)
1491+
if (cas_found < 0) {
1492+
free(legacy_ca_names);
14871493
return 0;
1494+
}
14881495

1489-
count_ports_by_guid(legacy_ca_names, cas_found, counts, UMAD_MAX_PORTS);
1496+
count_ports_by_guid(legacy_ca_names->_ca_names_arr, cas_found, counts, UMAD_MAX_PORTS);
14901497

14911498
size_t c_idx = 0;
14921499

14931500
for (c_idx = 0; c_idx < (size_t)cas_found; ++c_idx) {
14941501
umad_ca_t curr_ca;
14951502

1496-
if (umad_get_ca(legacy_ca_names[c_idx], &curr_ca) < 0)
1503+
if (umad_get_ca(legacy_ca_names->_ca_names_arr[c_idx], &curr_ca) < 0)
14971504
continue;
14981505

14991506
size_t p_idx = 0;
@@ -1525,13 +1532,15 @@ int umad_get_smi_gsi_pairs(struct umad_ca_pair cas[], size_t max)
15251532
break;
15261533
} else {
15271534
umad_release_ca(&curr_ca);
1535+
free(legacy_ca_names);
15281536
return -1;
15291537
}
15301538
}
15311539

15321540
umad_release_ca(&curr_ca);
15331541
}
15341542

1543+
free(legacy_ca_names);
15351544
return added_devices;
15361545
}
15371546

libibumad/umad.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ union umad_gid {
6262
} global;
6363
} __attribute__((aligned(4))) __attribute__((packed));
6464

65-
#define UMAD_MAX_DEVICES 32
65+
#define UMAD_MAX_DEVICES 128
6666
#define UMAD_ANY_PORT 0
6767
typedef struct ib_mad_addr {
6868
__be32 qpn;

0 commit comments

Comments
 (0)