Message ID | 20181206110615.9053-1-yuval.shaia@oracle.com (mailing list archive) |
---|---|
State | Superseded |
Delegated to: | Leon Romanovsky |
Headers | show |
Series | IB/rxe: Utilize generic function to validate port number | expand |
On Thu, Dec 06, 2018 at 01:06:15PM +0200, Yuval Shaia wrote: > RXE has only one port. No need to hard code it on every verb instead use > rdma_is_port_valid to validate the given port number. > > Signed-off-by: Yuval Shaia <yuval.shaia@oracle.com> > --- > drivers/infiniband/sw/rxe/rxe_verbs.c | 23 +++++++++++++---------- > 1 file changed, 13 insertions(+), 10 deletions(-) > > diff --git a/drivers/infiniband/sw/rxe/rxe_verbs.c b/drivers/infiniband/sw/rxe/rxe_verbs.c > index 30817c79ba96..88fdb8890038 100644 > --- a/drivers/infiniband/sw/rxe/rxe_verbs.c > +++ b/drivers/infiniband/sw/rxe/rxe_verbs.c > @@ -51,6 +51,16 @@ static int rxe_query_device(struct ib_device *dev, > return 0; > } > > +static bool rxe_is_port_valid(struct rxe_dev *rxe, u8 port_num) > +{ > + if (unlikely(!rdma_is_port_valid(&rxe->ib_dev, port_num))) { > + pr_warn("Invalid port number %d\n", port_num); > + return 0; > + } > + > + return 1; > +} Let's use directly rdma_is_port_valid() without extra layer. Thanks
On Thu, Dec 06, 2018 at 01:44:12PM +0200, Leon Romanovsky wrote: > On Thu, Dec 06, 2018 at 01:06:15PM +0200, Yuval Shaia wrote: > > RXE has only one port. No need to hard code it on every verb instead use > > rdma_is_port_valid to validate the given port number. > > > > Signed-off-by: Yuval Shaia <yuval.shaia@oracle.com> > > --- > > drivers/infiniband/sw/rxe/rxe_verbs.c | 23 +++++++++++++---------- > > 1 file changed, 13 insertions(+), 10 deletions(-) > > > > diff --git a/drivers/infiniband/sw/rxe/rxe_verbs.c b/drivers/infiniband/sw/rxe/rxe_verbs.c > > index 30817c79ba96..88fdb8890038 100644 > > --- a/drivers/infiniband/sw/rxe/rxe_verbs.c > > +++ b/drivers/infiniband/sw/rxe/rxe_verbs.c > > @@ -51,6 +51,16 @@ static int rxe_query_device(struct ib_device *dev, > > return 0; > > } > > > > +static bool rxe_is_port_valid(struct rxe_dev *rxe, u8 port_num) > > +{ > > + if (unlikely(!rdma_is_port_valid(&rxe->ib_dev, port_num))) { > > + pr_warn("Invalid port number %d\n", port_num); > > + return 0; > > + } > > + > > + return 1; > > +} > > Let's use directly rdma_is_port_valid() without extra layer. Checking it a bit more, except for query_pkey the core functions already validates the port so instead - i will just remove this redundant verification. For the ib_query_pkey thing, i'll post a different patch. > > Thanks
diff --git a/drivers/infiniband/sw/rxe/rxe_verbs.c b/drivers/infiniband/sw/rxe/rxe_verbs.c index 30817c79ba96..88fdb8890038 100644 --- a/drivers/infiniband/sw/rxe/rxe_verbs.c +++ b/drivers/infiniband/sw/rxe/rxe_verbs.c @@ -51,6 +51,16 @@ static int rxe_query_device(struct ib_device *dev, return 0; } +static bool rxe_is_port_valid(struct rxe_dev *rxe, u8 port_num) +{ + if (unlikely(!rdma_is_port_valid(&rxe->ib_dev, port_num))) { + pr_warn("Invalid port number %d\n", port_num); + return 0; + } + + return 1; +} + static int rxe_query_port(struct ib_device *dev, u8 port_num, struct ib_port_attr *attr) { @@ -58,10 +68,8 @@ static int rxe_query_port(struct ib_device *dev, struct rxe_port *port; int rc = -EINVAL; - if (unlikely(port_num != 1)) { - pr_warn("invalid port_number %d\n", port_num); + if (unlikely(!rxe_is_port_valid(rxe, port_num))) goto out; - } port = &rxe->port; @@ -104,11 +112,8 @@ static int rxe_query_pkey(struct ib_device *device, struct rxe_dev *rxe = to_rdev(device); struct rxe_port *port; - if (unlikely(port_num != 1)) { - dev_warn(device->dev.parent, "invalid port_num = %d\n", - port_num); + if (unlikely(!rxe_is_port_valid(rxe, port_num))) goto err1; - } port = &rxe->port; @@ -147,10 +152,8 @@ static int rxe_modify_port(struct ib_device *dev, struct rxe_dev *rxe = to_rdev(dev); struct rxe_port *port; - if (unlikely(port_num != 1)) { - pr_warn("invalid port_num = %d\n", port_num); + if (unlikely(!rxe_is_port_valid(rxe, port_num))) goto err1; - } port = &rxe->port;
RXE has only one port. No need to hard code it on every verb instead use rdma_is_port_valid to validate the given port number. Signed-off-by: Yuval Shaia <yuval.shaia@oracle.com> --- drivers/infiniband/sw/rxe/rxe_verbs.c | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-)