Skip to content

Commit 8f649b5

Browse files
keesjgunthorpe
authored andcommitted
IB/hfi1: Replace 1-element array with singleton
Zero-length arrays are deprecated[1] and are being replaced with flexible array members in support of the ongoing efforts to tighten the FORTIFY_SOURCE routines on memcpy(), correctly instrument array indexing with UBSAN_BOUNDS, and to globally enable -fstrict-flex-arrays=3. Replace zero-length array with flexible-array member "lvs" in struct opa_port_data_counters_msg and struct opa_port_error_counters64_msg. Additionally, the "port" member of several structs is defined as a single-element, but is only ever accessed at index 0. Replace it with a singleton so that flexible array usage is sane. This results in no differences in binary output. [1] KSPP/linux#78 Link: https://lore.kernel.org/r/20221118215847.never.416-kees@kernel.org Signed-off-by: Kees Cook <keescook@chromium.org> Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>
1 parent 34a046f commit 8f649b5

File tree

1 file changed

+11
-11
lines changed
  • drivers/infiniband/hw/hfi1

1 file changed

+11
-11
lines changed

drivers/infiniband/hw/hfi1/mad.c

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2437,9 +2437,9 @@ struct opa_port_data_counters_msg {
24372437
__be64 port_vl_xmit_wait_data;
24382438
__be64 port_vl_rcv_bubble;
24392439
__be64 port_vl_mark_fecn;
2440-
} vls[0];
2440+
} vls[];
24412441
/* array size defined by #bits set in vl_select_mask*/
2442-
} port[1]; /* array size defined by #ports in attribute modifier */
2442+
} port;
24432443
};
24442444

24452445
struct opa_port_error_counters64_msg {
@@ -2470,9 +2470,9 @@ struct opa_port_error_counters64_msg {
24702470
u8 reserved3[7];
24712471
struct _vls_ectrs {
24722472
__be64 port_vl_xmit_discards;
2473-
} vls[0];
2473+
} vls[];
24742474
/* array size defined by #bits set in vl_select_mask */
2475-
} port[1]; /* array size defined by #ports in attribute modifier */
2475+
} port;
24762476
};
24772477

24782478
struct opa_port_error_info_msg {
@@ -2543,7 +2543,7 @@ struct opa_port_error_info_msg {
25432543
u8 error_info;
25442544
} __packed fm_config_ei;
25452545
__u32 reserved9;
2546-
} port[1]; /* actual array size defined by #ports in attr modifier */
2546+
} port;
25472547
};
25482548

25492549
/* opa_port_error_info_msg error_info_select_mask bit definitions */
@@ -2966,7 +2966,7 @@ static int pma_get_opa_datacounters(struct opa_pma_mad *pmp,
29662966
}
29672967

29682968
/* Sanity check */
2969-
response_data_size = struct_size(req, port[0].vls, num_vls);
2969+
response_data_size = struct_size(req, port.vls, num_vls);
29702970

29712971
if (response_data_size > sizeof(pmp->data)) {
29722972
pmp->mad_hdr.status |= IB_SMP_INVALID_FIELD;
@@ -2986,7 +2986,7 @@ static int pma_get_opa_datacounters(struct opa_pma_mad *pmp,
29862986
return reply((struct ib_mad_hdr *)pmp);
29872987
}
29882988

2989-
rsp = &req->port[0];
2989+
rsp = &req->port;
29902990
memset(rsp, 0, sizeof(*rsp));
29912991

29922992
rsp->port_number = port;
@@ -3182,7 +3182,7 @@ static int pma_get_opa_porterrors(struct opa_pma_mad *pmp,
31823182
return reply((struct ib_mad_hdr *)pmp);
31833183
}
31843184

3185-
response_data_size = struct_size(req, port[0].vls, num_vls);
3185+
response_data_size = struct_size(req, port.vls, num_vls);
31863186

31873187
if (response_data_size > sizeof(pmp->data)) {
31883188
pmp->mad_hdr.status |= IB_SMP_INVALID_FIELD;
@@ -3201,7 +3201,7 @@ static int pma_get_opa_porterrors(struct opa_pma_mad *pmp,
32013201
return reply((struct ib_mad_hdr *)pmp);
32023202
}
32033203

3204-
rsp = &req->port[0];
3204+
rsp = &req->port;
32053205

32063206
ibp = to_iport(ibdev, port_num);
32073207
ppd = ppd_from_ibp(ibp);
@@ -3340,7 +3340,7 @@ static int pma_get_opa_errorinfo(struct opa_pma_mad *pmp,
33403340
u64 reg;
33413341

33423342
req = (struct opa_port_error_info_msg *)pmp->data;
3343-
rsp = &req->port[0];
3343+
rsp = &req->port;
33443344

33453345
num_ports = OPA_AM_NPORT(be32_to_cpu(pmp->mad_hdr.attr_mod));
33463346
num_pslm = hweight64(be64_to_cpu(req->port_select_mask[3]));
@@ -3590,7 +3590,7 @@ static int pma_set_opa_errorinfo(struct opa_pma_mad *pmp,
35903590
u32 error_info_select;
35913591

35923592
req = (struct opa_port_error_info_msg *)pmp->data;
3593-
rsp = &req->port[0];
3593+
rsp = &req->port;
35943594

35953595
num_ports = OPA_AM_NPORT(be32_to_cpu(pmp->mad_hdr.attr_mod));
35963596
num_pslm = hweight64(be64_to_cpu(req->port_select_mask[3]));

0 commit comments

Comments
 (0)