Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

RDMA/core: Use sizeof_field() helper

Make use of the sizeof_field() helper instead of an open-coded version.

Link: https://lore.kernel.org/r/20200527144152.GA22605@embeddedor
Signed-off-by: Gustavo A. R. Silva <gustavoars@kernel.org>
Signed-off-by: Jason Gunthorpe <jgg@mellanox.com>

authored by

Gustavo A. R. Silva and committed by
Jason Gunthorpe
bebcfe85 ebd6e96b

+16 -16
+7 -7
drivers/infiniband/core/sa_query.c
··· 190 190 191 191 #define PATH_REC_FIELD(field) \ 192 192 .struct_offset_bytes = offsetof(struct sa_path_rec, field), \ 193 - .struct_size_bytes = sizeof((struct sa_path_rec *)0)->field, \ 193 + .struct_size_bytes = sizeof_field(struct sa_path_rec, field), \ 194 194 .field_name = "sa_path_rec:" #field 195 195 196 196 static const struct ib_field path_rec_table[] = { ··· 292 292 .struct_offset_bytes = \ 293 293 offsetof(struct sa_path_rec, field), \ 294 294 .struct_size_bytes = \ 295 - sizeof((struct sa_path_rec *)0)->field, \ 295 + sizeof_field(struct sa_path_rec, field), \ 296 296 .field_name = "sa_path_rec:" #field 297 297 298 298 static const struct ib_field opa_path_rec_table[] = { ··· 420 420 421 421 #define MCMEMBER_REC_FIELD(field) \ 422 422 .struct_offset_bytes = offsetof(struct ib_sa_mcmember_rec, field), \ 423 - .struct_size_bytes = sizeof ((struct ib_sa_mcmember_rec *) 0)->field, \ 423 + .struct_size_bytes = sizeof_field(struct ib_sa_mcmember_rec, field), \ 424 424 .field_name = "sa_mcmember_rec:" #field 425 425 426 426 static const struct ib_field mcmember_rec_table[] = { ··· 504 504 505 505 #define SERVICE_REC_FIELD(field) \ 506 506 .struct_offset_bytes = offsetof(struct ib_sa_service_rec, field), \ 507 - .struct_size_bytes = sizeof ((struct ib_sa_service_rec *) 0)->field, \ 507 + .struct_size_bytes = sizeof_field(struct ib_sa_service_rec, field), \ 508 508 .field_name = "sa_service_rec:" #field 509 509 510 510 static const struct ib_field service_rec_table[] = { ··· 552 552 553 553 #define CLASSPORTINFO_REC_FIELD(field) \ 554 554 .struct_offset_bytes = offsetof(struct ib_class_port_info, field), \ 555 - .struct_size_bytes = sizeof((struct ib_class_port_info *)0)->field, \ 555 + .struct_size_bytes = sizeof_field(struct ib_class_port_info, field), \ 556 556 .field_name = "ib_class_port_info:" #field 557 557 558 558 static const struct ib_field ib_classport_info_rec_table[] = { ··· 630 630 .struct_offset_bytes =\ 631 631 offsetof(struct opa_class_port_info, field), \ 632 632 .struct_size_bytes = \ 633 - sizeof((struct opa_class_port_info *)0)->field, \ 633 + sizeof_field(struct opa_class_port_info, field), \ 634 634 .field_name = "opa_class_port_info:" #field 635 635 636 636 static const struct ib_field opa_classport_info_rec_table[] = { ··· 710 710 711 711 #define GUIDINFO_REC_FIELD(field) \ 712 712 .struct_offset_bytes = offsetof(struct ib_sa_guidinfo_rec, field), \ 713 - .struct_size_bytes = sizeof((struct ib_sa_guidinfo_rec *) 0)->field, \ 713 + .struct_size_bytes = sizeof_field(struct ib_sa_guidinfo_rec, field), \ 714 714 .field_name = "sa_guidinfo_rec:" #field 715 715 716 716 static const struct ib_field guidinfo_rec_table[] = {
+1 -1
drivers/infiniband/core/ud_header.c
··· 41 41 42 42 #define STRUCT_FIELD(header, field) \ 43 43 .struct_offset_bytes = offsetof(struct ib_unpacked_ ## header, field), \ 44 - .struct_size_bytes = sizeof ((struct ib_unpacked_ ## header *) 0)->field, \ 44 + .struct_size_bytes = sizeof_field(struct ib_unpacked_ ## header, field), \ 45 45 .field_name = #header ":" #field 46 46 47 47 static const struct ib_field lrh_table[] = {
+1 -1
drivers/infiniband/core/uverbs_cmd.c
··· 3741 3741 #define UAPI_DEF_WRITE_IO(req, resp) \ 3742 3742 .write.has_resp = 1 + \ 3743 3743 BUILD_BUG_ON_ZERO(offsetof(req, response) != 0) + \ 3744 - BUILD_BUG_ON_ZERO(sizeof(((req *)0)->response) != \ 3744 + BUILD_BUG_ON_ZERO(sizeof_field(req, response) != \ 3745 3745 sizeof(u64)), \ 3746 3746 .write.req_size = sizeof(req), .write.resp_size = sizeof(resp) 3747 3747
+1 -1
drivers/infiniband/core/uverbs_ioctl.c
··· 137 137 static bool uverbs_is_attr_cleared(const struct ib_uverbs_attr *uattr, 138 138 u16 len) 139 139 { 140 - if (uattr->len > sizeof(((struct ib_uverbs_attr *)0)->data)) 140 + if (uattr->len > sizeof_field(struct ib_uverbs_attr, data)) 141 141 return ib_is_buffer_cleared(u64_to_user_ptr(uattr->data) + len, 142 142 uattr->len - len); 143 143
+6 -6
include/rdma/uverbs_ioctl.h
··· 420 420 .scope = UAPI_SCOPE_OBJECT, \ 421 421 .needs_fn_offset = \ 422 422 offsetof(struct ib_device_ops, ibdev_fn) + \ 423 - BUILD_BUG_ON_ZERO( \ 424 - sizeof(((struct ib_device_ops *)0)->ibdev_fn) != \ 425 - sizeof(void *)), \ 423 + BUILD_BUG_ON_ZERO(sizeof_field(struct ib_device_ops, \ 424 + ibdev_fn) != \ 425 + sizeof(void *)), \ 426 426 } 427 427 428 428 /* ··· 435 435 .scope = UAPI_SCOPE_METHOD, \ 436 436 .needs_fn_offset = \ 437 437 offsetof(struct ib_device_ops, ibdev_fn) + \ 438 - BUILD_BUG_ON_ZERO( \ 439 - sizeof(((struct ib_device_ops *)0)->ibdev_fn) != \ 440 - sizeof(void *)), \ 438 + BUILD_BUG_ON_ZERO(sizeof_field(struct ib_device_ops, \ 439 + ibdev_fn) != \ 440 + sizeof(void *)), \ 441 441 } 442 442 443 443 /* Call a function to determine if the entire object is supported or not */