diff options
author | Yuval Shaia <yuval.shaia@oracle.com> | 2017-01-25 11:41:37 -0500 |
---|---|---|
committer | Doug Ledford <dledford@redhat.com> | 2017-01-27 14:33:59 -0500 |
commit | 24dc831b77eca9361cf835be59fa69ea0e471afc (patch) | |
tree | 5aa6e10dfc77e48e2c969b3f6f870b3fc18f7e5e | |
parent | 2bce1a6d2209c8c776a9598741f5aa1991689dcb (diff) |
IB/core: Add inline function to validate port
Signed-off-by: Yuval Shaia <yuval.shaia@oracle.com>
Reviewed-by: Leon Romanovsky <leonro@mellanox.com>
Signed-off-by: Doug Ledford <dledford@redhat.com>
-rw-r--r-- | drivers/infiniband/core/cache.c | 18 | ||||
-rw-r--r-- | drivers/infiniband/core/cma.c | 6 | ||||
-rw-r--r-- | drivers/infiniband/core/device.c | 4 | ||||
-rw-r--r-- | drivers/infiniband/core/verbs.c | 3 | ||||
-rw-r--r-- | include/rdma/ib_verbs.h | 7 |
5 files changed, 20 insertions, 18 deletions
diff --git a/drivers/infiniband/core/cache.c b/drivers/infiniband/core/cache.c index 2e52021aa999..b1371eb9f46c 100644 --- a/drivers/infiniband/core/cache.c +++ b/drivers/infiniband/core/cache.c | |||
@@ -504,8 +504,7 @@ int ib_find_cached_gid_by_port(struct ib_device *ib_dev, | |||
504 | struct ib_gid_attr val = {.ndev = ndev, .gid_type = gid_type}; | 504 | struct ib_gid_attr val = {.ndev = ndev, .gid_type = gid_type}; |
505 | unsigned long flags; | 505 | unsigned long flags; |
506 | 506 | ||
507 | if (port < rdma_start_port(ib_dev) || | 507 | if (!rdma_is_port_valid(ib_dev, port)) |
508 | port > rdma_end_port(ib_dev)) | ||
509 | return -ENOENT; | 508 | return -ENOENT; |
510 | 509 | ||
511 | table = ib_dev->cache.ports[port - rdma_start_port(ib_dev)].gid; | 510 | table = ib_dev->cache.ports[port - rdma_start_port(ib_dev)].gid; |
@@ -562,8 +561,7 @@ static int ib_cache_gid_find_by_filter(struct ib_device *ib_dev, | |||
562 | bool found = false; | 561 | bool found = false; |
563 | 562 | ||
564 | 563 | ||
565 | if (port < rdma_start_port(ib_dev) || | 564 | if (!rdma_is_port_valid(ib_dev, port) || |
566 | port > rdma_end_port(ib_dev) || | ||
567 | !rdma_protocol_roce(ib_dev, port)) | 565 | !rdma_protocol_roce(ib_dev, port)) |
568 | return -EPROTONOSUPPORT; | 566 | return -EPROTONOSUPPORT; |
569 | 567 | ||
@@ -845,7 +843,7 @@ int ib_get_cached_gid(struct ib_device *device, | |||
845 | unsigned long flags; | 843 | unsigned long flags; |
846 | struct ib_gid_table *table; | 844 | struct ib_gid_table *table; |
847 | 845 | ||
848 | if (port_num < rdma_start_port(device) || port_num > rdma_end_port(device)) | 846 | if (!rdma_is_port_valid(device, port_num)) |
849 | return -EINVAL; | 847 | return -EINVAL; |
850 | 848 | ||
851 | table = device->cache.ports[port_num - rdma_start_port(device)].gid; | 849 | table = device->cache.ports[port_num - rdma_start_port(device)].gid; |
@@ -895,7 +893,7 @@ int ib_get_cached_pkey(struct ib_device *device, | |||
895 | unsigned long flags; | 893 | unsigned long flags; |
896 | int ret = 0; | 894 | int ret = 0; |
897 | 895 | ||
898 | if (port_num < rdma_start_port(device) || port_num > rdma_end_port(device)) | 896 | if (!rdma_is_port_valid(device, port_num)) |
899 | return -EINVAL; | 897 | return -EINVAL; |
900 | 898 | ||
901 | read_lock_irqsave(&device->cache.lock, flags); | 899 | read_lock_irqsave(&device->cache.lock, flags); |
@@ -924,7 +922,7 @@ int ib_find_cached_pkey(struct ib_device *device, | |||
924 | int ret = -ENOENT; | 922 | int ret = -ENOENT; |
925 | int partial_ix = -1; | 923 | int partial_ix = -1; |
926 | 924 | ||
927 | if (port_num < rdma_start_port(device) || port_num > rdma_end_port(device)) | 925 | if (!rdma_is_port_valid(device, port_num)) |
928 | return -EINVAL; | 926 | return -EINVAL; |
929 | 927 | ||
930 | read_lock_irqsave(&device->cache.lock, flags); | 928 | read_lock_irqsave(&device->cache.lock, flags); |
@@ -964,7 +962,7 @@ int ib_find_exact_cached_pkey(struct ib_device *device, | |||
964 | int i; | 962 | int i; |
965 | int ret = -ENOENT; | 963 | int ret = -ENOENT; |
966 | 964 | ||
967 | if (port_num < rdma_start_port(device) || port_num > rdma_end_port(device)) | 965 | if (!rdma_is_port_valid(device, port_num)) |
968 | return -EINVAL; | 966 | return -EINVAL; |
969 | 967 | ||
970 | read_lock_irqsave(&device->cache.lock, flags); | 968 | read_lock_irqsave(&device->cache.lock, flags); |
@@ -993,7 +991,7 @@ int ib_get_cached_lmc(struct ib_device *device, | |||
993 | unsigned long flags; | 991 | unsigned long flags; |
994 | int ret = 0; | 992 | int ret = 0; |
995 | 993 | ||
996 | if (port_num < rdma_start_port(device) || port_num > rdma_end_port(device)) | 994 | if (!rdma_is_port_valid(device, port_num)) |
997 | return -EINVAL; | 995 | return -EINVAL; |
998 | 996 | ||
999 | read_lock_irqsave(&device->cache.lock, flags); | 997 | read_lock_irqsave(&device->cache.lock, flags); |
@@ -1038,7 +1036,7 @@ static void ib_cache_update(struct ib_device *device, | |||
1038 | bool use_roce_gid_table = | 1036 | bool use_roce_gid_table = |
1039 | rdma_cap_roce_gid_table(device, port); | 1037 | rdma_cap_roce_gid_table(device, port); |
1040 | 1038 | ||
1041 | if (port < rdma_start_port(device) || port > rdma_end_port(device)) | 1039 | if (!rdma_is_port_valid(device, port)) |
1042 | return; | 1040 | return; |
1043 | 1041 | ||
1044 | table = device->cache.ports[port - rdma_start_port(device)].gid; | 1042 | table = device->cache.ports[port - rdma_start_port(device)].gid; |
diff --git a/drivers/infiniband/core/cma.c b/drivers/infiniband/core/cma.c index 7cb01a9463da..9c93e2fa969b 100644 --- a/drivers/infiniband/core/cma.c +++ b/drivers/infiniband/core/cma.c | |||
@@ -269,8 +269,7 @@ struct cma_device *cma_enum_devices_by_ibdev(cma_device_filter filter, | |||
269 | int cma_get_default_gid_type(struct cma_device *cma_dev, | 269 | int cma_get_default_gid_type(struct cma_device *cma_dev, |
270 | unsigned int port) | 270 | unsigned int port) |
271 | { | 271 | { |
272 | if (port < rdma_start_port(cma_dev->device) || | 272 | if (!rdma_is_port_valid(cma_dev->device, port)) |
273 | port > rdma_end_port(cma_dev->device)) | ||
274 | return -EINVAL; | 273 | return -EINVAL; |
275 | 274 | ||
276 | return cma_dev->default_gid_type[port - rdma_start_port(cma_dev->device)]; | 275 | return cma_dev->default_gid_type[port - rdma_start_port(cma_dev->device)]; |
@@ -282,8 +281,7 @@ int cma_set_default_gid_type(struct cma_device *cma_dev, | |||
282 | { | 281 | { |
283 | unsigned long supported_gids; | 282 | unsigned long supported_gids; |
284 | 283 | ||
285 | if (port < rdma_start_port(cma_dev->device) || | 284 | if (!rdma_is_port_valid(cma_dev->device, port)) |
286 | port > rdma_end_port(cma_dev->device)) | ||
287 | return -EINVAL; | 285 | return -EINVAL; |
288 | 286 | ||
289 | supported_gids = roce_gid_type_mask_support(cma_dev->device, port); | 287 | supported_gids = roce_gid_type_mask_support(cma_dev->device, port); |
diff --git a/drivers/infiniband/core/device.c b/drivers/infiniband/core/device.c index 571974cd3919..f2e48655a906 100644 --- a/drivers/infiniband/core/device.c +++ b/drivers/infiniband/core/device.c | |||
@@ -659,7 +659,7 @@ int ib_query_port(struct ib_device *device, | |||
659 | union ib_gid gid; | 659 | union ib_gid gid; |
660 | int err; | 660 | int err; |
661 | 661 | ||
662 | if (port_num < rdma_start_port(device) || port_num > rdma_end_port(device)) | 662 | if (!rdma_is_port_valid(device, port_num)) |
663 | return -EINVAL; | 663 | return -EINVAL; |
664 | 664 | ||
665 | memset(port_attr, 0, sizeof(*port_attr)); | 665 | memset(port_attr, 0, sizeof(*port_attr)); |
@@ -825,7 +825,7 @@ int ib_modify_port(struct ib_device *device, | |||
825 | if (!device->modify_port) | 825 | if (!device->modify_port) |
826 | return -ENOSYS; | 826 | return -ENOSYS; |
827 | 827 | ||
828 | if (port_num < rdma_start_port(device) || port_num > rdma_end_port(device)) | 828 | if (!rdma_is_port_valid(device, port_num)) |
829 | return -EINVAL; | 829 | return -EINVAL; |
830 | 830 | ||
831 | return device->modify_port(device, port_num, port_modify_mask, | 831 | return device->modify_port(device, port_num, port_modify_mask, |
diff --git a/drivers/infiniband/core/verbs.c b/drivers/infiniband/core/verbs.c index 71580cc28c9e..9b77fbc86903 100644 --- a/drivers/infiniband/core/verbs.c +++ b/drivers/infiniband/core/verbs.c | |||
@@ -1205,8 +1205,7 @@ int ib_resolve_eth_dmac(struct ib_device *device, | |||
1205 | { | 1205 | { |
1206 | int ret = 0; | 1206 | int ret = 0; |
1207 | 1207 | ||
1208 | if (ah_attr->port_num < rdma_start_port(device) || | 1208 | if (!rdma_is_port_valid(device, ah_attr->port_num)) |
1209 | ah_attr->port_num > rdma_end_port(device)) | ||
1210 | return -EINVAL; | 1209 | return -EINVAL; |
1211 | 1210 | ||
1212 | if (!rdma_cap_eth_ah(device, ah_attr->port_num)) | 1211 | if (!rdma_cap_eth_ah(device, ah_attr->port_num)) |
diff --git a/include/rdma/ib_verbs.h b/include/rdma/ib_verbs.h index e55afec6bb84..b1ac9735fbbe 100644 --- a/include/rdma/ib_verbs.h +++ b/include/rdma/ib_verbs.h | |||
@@ -2280,6 +2280,13 @@ static inline u8 rdma_end_port(const struct ib_device *device) | |||
2280 | return rdma_cap_ib_switch(device) ? 0 : device->phys_port_cnt; | 2280 | return rdma_cap_ib_switch(device) ? 0 : device->phys_port_cnt; |
2281 | } | 2281 | } |
2282 | 2282 | ||
2283 | static inline int rdma_is_port_valid(const struct ib_device *device, | ||
2284 | unsigned int port) | ||
2285 | { | ||
2286 | return (port >= rdma_start_port(device) && | ||
2287 | port <= rdma_end_port(device)); | ||
2288 | } | ||
2289 | |||
2283 | static inline bool rdma_protocol_ib(const struct ib_device *device, u8 port_num) | 2290 | static inline bool rdma_protocol_ib(const struct ib_device *device, u8 port_num) |
2284 | { | 2291 | { |
2285 | return device->port_immutable[port_num].core_cap_flags & RDMA_CORE_CAP_PROT_IB; | 2292 | return device->port_immutable[port_num].core_cap_flags & RDMA_CORE_CAP_PROT_IB; |