Re: [PATCH rdma-next v1 03/11] RDMA/efa: Use in-kernel offsetofend() to check field availability

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Fri, Mar 13, 2020 at 10:44:56AM -0300, Jason Gunthorpe wrote:
> On Tue, Mar 10, 2020 at 11:14:30AM +0200, Leon Romanovsky wrote:
> > From: Leon Romanovsky <leonro@xxxxxxxxxxxx>
> >
> > Remove custom and duplicated variant of offsetofend().
> >
> > Signed-off-by: Leon Romanovsky <leonro@xxxxxxxxxxxx>
> >  drivers/infiniband/hw/efa/efa_verbs.c | 7 ++-----
> >  1 file changed, 2 insertions(+), 5 deletions(-)
> >
> > diff --git a/drivers/infiniband/hw/efa/efa_verbs.c b/drivers/infiniband/hw/efa/efa_verbs.c
> > index bf3120f140f7..5c57098a4aee 100644
> > +++ b/drivers/infiniband/hw/efa/efa_verbs.c
> > @@ -144,9 +144,6 @@ static inline bool is_rdma_read_cap(struct efa_dev *dev)
> >  	return dev->dev_attr.device_caps & EFA_ADMIN_FEATURE_DEVICE_ATTR_DESC_RDMA_READ_MASK;
> >  }
> >
> > -#define field_avail(x, fld, sz) (offsetof(typeof(x), fld) + \
> > -				 sizeof_field(typeof(x), fld) <= (sz))
> > -
> >  #define is_reserved_cleared(reserved) \
> >  	!memchr_inv(reserved, 0, sizeof(reserved))
> >
> > @@ -609,7 +606,7 @@ struct ib_qp *efa_create_qp(struct ib_pd *ibpd,
> >  	if (err)
> >  		goto err_out;
> >
> > -	if (!field_avail(cmd, driver_qp_type, udata->inlen)) {
> > +	if (offsetofend(typeof(cmd), driver_qp_type) > udata->inlen) {
>
> The > needs to be >=, and generally we write compares as
>    'variable XX constant'

Why ">="
The original code is
if (!field_avail(cmd, driver_qp_type, udata->inlen))
==>
if (!(offsetof(typeof(cmd), driver_qp_type) + sizeof_field(typeof(cmd), driver_qp_type,) <= (udata->inlen))
===>
if (!(offsetofend(typeof(cmd), driver_qp_type) <= (udata->inlen))
===>
if (offsetofend(typeof(cmd), driver_qp_type) > (udata->inlen)

like I wrote.

>


>
> > @@ -896,7 +893,7 @@ int efa_create_cq(struct ib_cq *ibcq, const struct ib_cq_init_attr *attr,
> >  		goto err_out;
> >  	}
> >
> > -	if (!field_avail(cmd, num_sub_cqs, udata->inlen)) {
> > +	if (offsetofend(typeof(cmd), num_sub_cqs) > udata->inlen) {
>
> Same
>
> Jason



[Index of Archives]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Photo]     [Yosemite News]     [Yosemite Photos]     [Linux Kernel]     [Linux SCSI]     [XFree86]

  Powered by Linux