Re: [PATCH rdma-next v2] RDMA/mlx5: Expose private query port

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

 



On Thu, Apr 01, 2021 at 11:50:04AM +0300, Leon Romanovsky wrote:

> +static int UVERBS_HANDLER(MLX5_IB_METHOD_QUERY_PORT)(
> +	struct uverbs_attr_bundle *attrs)
> +{
> +	struct mlx5_ib_uapi_query_port *info;
> +	struct mlx5_ib_ucontext *c;
> +	struct mlx5_ib_dev *dev;
> +	u32 port_num;
> +	int ret;
> +
> +	if (uverbs_copy_from(&port_num, attrs,
> +			     MLX5_IB_ATTR_QUERY_PORT_PORT_NUM))
> +		return -EFAULT;
> +
> +	c = to_mucontext(ib_uverbs_get_ucontext(attrs));
> +	if (IS_ERR(c))
> +		return PTR_ERR(c);
> +	dev = to_mdev(c->ibucontext.device);
> +
> +	if (!rdma_is_port_valid(&dev->ib_dev, port_num))
> +		return -EINVAL;
> +
> +	info = uverbs_zalloc(attrs, sizeof(*info));
> +	if (IS_ERR(info))
> +		return PTR_ERR(info);

This allocation is not needed, info is small enough to be on the stack

> +
> +	if (mlx5_eswitch_mode(dev->mdev) == MLX5_ESWITCH_OFFLOADS) {
> +		ret = fill_switchdev_info(dev, port_num, info);
> +		if (ret)
> +			return ret;
> +	}
> +
> +	return uverbs_copy_to(attrs, MLX5_IB_ATTR_QUERY_PORT, info,
> +			      sizeof(*info));

This should be 

uverbs_copy_to_struct_or_zero()

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