From patchwork Fri Aug 10 02:14:41 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 10562193 X-Patchwork-Delegate: jgg@ziepe.ca Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 1250213BB for ; Fri, 10 Aug 2018 02:15:01 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 040F32BBA4 for ; Fri, 10 Aug 2018 02:15:01 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id ECF032BBD7; Fri, 10 Aug 2018 02:15:00 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C3CE82BBA4 for ; Fri, 10 Aug 2018 02:14:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727168AbeHJEmh (ORCPT ); Fri, 10 Aug 2018 00:42:37 -0400 Received: from mail-pl0-f42.google.com ([209.85.160.42]:45228 "EHLO mail-pl0-f42.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727143AbeHJEmh (ORCPT ); Fri, 10 Aug 2018 00:42:37 -0400 Received: by mail-pl0-f42.google.com with SMTP id j8-v6so3351022pll.12 for ; Thu, 09 Aug 2018 19:14:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ziepe.ca; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=D5NMclI/YYCdUEi5/ekehboTQYcDa0rppQtaewSe9sM=; b=nvKgLXzuNxV4K245TN1SyuXQK4hdezX3AR4G6uTyFbjVFvWjnEgi2Nn4K3jMXsHByx DDvabqp1lfn7c7pY4J+3u16znI9rtnjxr6t0o61PhLdiXO2nmYOUt03hPft1HBAXgPuO qlpJpADHGx7nbGG4NrO+aEW5Pa7VuB6rPI5UwZPh4F+MkC32PXTazMIuzvyoTBUJNpDg sHCy17y9cGOsTtYp1X5OtVNKY6mNL6J4wQOyUTmuHOBTP3RXoUA2Lzmyr6vwxitCxPnh iNpR/4SQrXJgfJCJk1cJNmdc6ku3F3iMg+WdrKsri5lLZDk/THHZH6W5YF5e5kGoH9sj RHXQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=D5NMclI/YYCdUEi5/ekehboTQYcDa0rppQtaewSe9sM=; b=OK8l1BZU6ILpTXftvhCYX2VKXt43h+OylPzkNLoj3fXpTjvl9Tnh16BwPP4lrlLQ9n 5gu36YcLtdQ+aZkGqI+9+s7AvgkLcIRfECxjSvYLqtwPhebOmsGkAlglVWNIOxcagciz UrMp08QrDR5yBZIHgUEFl4gzepefOoXr0BIUp8sDKMIEyrtuMbEzfPU7+fneafAHMfCI qLGeXllaJam+YW5mzfjjoxRmiKcrtTRiQjluaeUSNi5tc/11mobU7pweuRhw8SR78xzy DuUHWUf8yZRPlf8Bg8E9d5eS9GfQj+ybJjnDeWYabyzJ4xhgo/BCmGJr8XiPyG5d0+O3 rS7w== X-Gm-Message-State: AOUpUlExuDMfmR4rcgiu+FLi9IW96lE3HTvIxIL/M0G7nOa86u8ZIPKN mcCe+rO9sX2kELLMmZYoFL/9TyfpxtY= X-Google-Smtp-Source: AA+uWPxZM3LV4Gyc05fXrHL87i6GMt0Gi3IPHyWkL/zkjJYI9BQG18ah2U0l5Ne9LrkbAL6nvTRzoA== X-Received: by 2002:a17:902:1121:: with SMTP id d30-v6mr4322008pla.247.1533867296416; Thu, 09 Aug 2018 19:14:56 -0700 (PDT) Received: from ziepe.ca (S010614cc2056d97f.ed.shawcable.net. [174.3.196.123]) by smtp.gmail.com with ESMTPSA id v23-v6sm9764796pfm.80.2018.08.09.19.14.52 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 09 Aug 2018 19:14:53 -0700 (PDT) Received: from jgg by mlx with local (Exim 4.90_1) (envelope-from ) id 1fnwx1-0003gl-HZ; Thu, 09 Aug 2018 20:14:51 -0600 From: Jason Gunthorpe To: linux-rdma@vger.kernel.org, Leon Romanovsky , "Guy Levi(SW)" , Yishai Hadas , "Ruhl, Michael J" Cc: Jason Gunthorpe Subject: [PATCH v1 07/10] IB/uverbs: Use uverbs_alloc for allocations Date: Thu, 9 Aug 2018 20:14:41 -0600 Message-Id: <20180810021444.14014-8-jgg@ziepe.ca> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180810021444.14014-1-jgg@ziepe.ca> References: <20180810021444.14014-1-jgg@ziepe.ca> Sender: linux-rdma-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-rdma@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Jason Gunthorpe Several handlers need temporary allocations for the life of the method, switch them to use the uverbs_alloc allocator. Signed-off-by: Jason Gunthorpe Reviewed-by: Leon Romanovsky --- .../core/uverbs_std_types_counters.c | 20 ++--- drivers/infiniband/hw/mlx5/devx.c | 83 +++++++------------ 2 files changed, 38 insertions(+), 65 deletions(-) diff --git a/drivers/infiniband/core/uverbs_std_types_counters.c b/drivers/infiniband/core/uverbs_std_types_counters.c index dfacc9e833995d..a0ffdcf9a51cd1 100644 --- a/drivers/infiniband/core/uverbs_std_types_counters.c +++ b/drivers/infiniband/core/uverbs_std_types_counters.c @@ -104,22 +104,18 @@ static int UVERBS_HANDLER(UVERBS_METHOD_COUNTERS_READ)( uattr = uverbs_attr_get(attrs, UVERBS_ATTR_READ_COUNTERS_BUFF); read_attr.ncounters = uattr->ptr_attr.len / sizeof(u64); - read_attr.counters_buff = kcalloc(read_attr.ncounters, - sizeof(u64), GFP_KERNEL); - if (!read_attr.counters_buff) - return -ENOMEM; + read_attr.counters_buff = uverbs_zalloc( + attrs, array_size(read_attr.ncounters, sizeof(u64))); + if (IS_ERR(read_attr.counters_buff)) + return PTR_ERR(read_attr.counters_buff); ret = counters->device->read_counters(counters, &read_attr, attrs); if (ret) - goto err_read; - - ret = uverbs_copy_to(attrs, UVERBS_ATTR_READ_COUNTERS_BUFF, - read_attr.counters_buff, - read_attr.ncounters * sizeof(u64)); + return ret; -err_read: - kfree(read_attr.counters_buff); - return ret; + return uverbs_copy_to(attrs, UVERBS_ATTR_READ_COUNTERS_BUFF, + read_attr.counters_buff, + read_attr.ncounters * sizeof(u64)); } DECLARE_UVERBS_NAMED_METHOD( diff --git a/drivers/infiniband/hw/mlx5/devx.c b/drivers/infiniband/hw/mlx5/devx.c index 29c6883723902c..ac116d63e4661a 100644 --- a/drivers/infiniband/hw/mlx5/devx.c +++ b/drivers/infiniband/hw/mlx5/devx.c @@ -511,22 +511,19 @@ static int UVERBS_HANDLER(MLX5_IB_METHOD_DEVX_OTHER)( if (!devx_is_general_cmd(cmd_in)) return -EINVAL; - cmd_out = kvzalloc(cmd_out_len, GFP_KERNEL); - if (!cmd_out) - return -ENOMEM; + cmd_out = uverbs_zalloc(attrs, cmd_out_len); + if (IS_ERR(cmd_out)) + return PTR_ERR(cmd_out); MLX5_SET(general_obj_in_cmd_hdr, cmd_in, uid, c->devx_uid); err = mlx5_cmd_exec(dev->mdev, cmd_in, uverbs_attr_get_len(attrs, MLX5_IB_ATTR_DEVX_OTHER_CMD_IN), cmd_out, cmd_out_len); if (err) - goto other_cmd_free; - - err = uverbs_copy_to(attrs, MLX5_IB_ATTR_DEVX_OTHER_CMD_OUT, cmd_out, cmd_out_len); + return err; -other_cmd_free: - kvfree(cmd_out); - return err; + return uverbs_copy_to(attrs, MLX5_IB_ATTR_DEVX_OTHER_CMD_OUT, cmd_out, + cmd_out_len); } static void devx_obj_build_destroy_cmd(void *in, void *out, void *din, @@ -735,22 +732,20 @@ static int UVERBS_HANDLER(MLX5_IB_METHOD_DEVX_OBJ_CREATE)( if (!devx_is_obj_create_cmd(cmd_in)) return -EINVAL; + cmd_out = uverbs_zalloc(attrs, cmd_out_len); + if (IS_ERR(cmd_out)) + return PTR_ERR(cmd_out); + obj = kzalloc(sizeof(struct devx_obj), GFP_KERNEL); if (!obj) return -ENOMEM; - cmd_out = kvzalloc(cmd_out_len, GFP_KERNEL); - if (!cmd_out) { - err = -ENOMEM; - goto obj_free; - } - MLX5_SET(general_obj_in_cmd_hdr, cmd_in, uid, c->devx_uid); err = mlx5_cmd_exec(dev->mdev, cmd_in, uverbs_attr_get_len(attrs, MLX5_IB_ATTR_DEVX_OBJ_CREATE_CMD_IN), cmd_out, cmd_out_len); if (err) - goto cmd_free; + goto obj_free; uobj->object = obj; obj->mdev = dev->mdev; @@ -759,13 +754,10 @@ static int UVERBS_HANDLER(MLX5_IB_METHOD_DEVX_OBJ_CREATE)( err = uverbs_copy_to(attrs, MLX5_IB_ATTR_DEVX_OBJ_CREATE_CMD_OUT, cmd_out, cmd_out_len); if (err) - goto cmd_free; + goto obj_free; - kvfree(cmd_out); return 0; -cmd_free: - kvfree(cmd_out); obj_free: kfree(obj); return err; @@ -793,23 +785,19 @@ static int UVERBS_HANDLER(MLX5_IB_METHOD_DEVX_OBJ_MODIFY)( if (!devx_is_valid_obj_id(obj, cmd_in)) return -EINVAL; - cmd_out = kvzalloc(cmd_out_len, GFP_KERNEL); - if (!cmd_out) - return -ENOMEM; + cmd_out = uverbs_zalloc(attrs, cmd_out_len); + if (IS_ERR(cmd_out)) + return PTR_ERR(cmd_out); MLX5_SET(general_obj_in_cmd_hdr, cmd_in, uid, c->devx_uid); err = mlx5_cmd_exec(obj->mdev, cmd_in, uverbs_attr_get_len(attrs, MLX5_IB_ATTR_DEVX_OBJ_MODIFY_CMD_IN), cmd_out, cmd_out_len); if (err) - goto other_cmd_free; - - err = uverbs_copy_to(attrs, MLX5_IB_ATTR_DEVX_OBJ_MODIFY_CMD_OUT, - cmd_out, cmd_out_len); + return err; -other_cmd_free: - kvfree(cmd_out); - return err; + return uverbs_copy_to(attrs, MLX5_IB_ATTR_DEVX_OBJ_MODIFY_CMD_OUT, + cmd_out, cmd_out_len); } static int UVERBS_HANDLER(MLX5_IB_METHOD_DEVX_OBJ_QUERY)( @@ -834,22 +822,19 @@ static int UVERBS_HANDLER(MLX5_IB_METHOD_DEVX_OBJ_QUERY)( if (!devx_is_valid_obj_id(obj, cmd_in)) return -EINVAL; - cmd_out = kvzalloc(cmd_out_len, GFP_KERNEL); - if (!cmd_out) - return -ENOMEM; + cmd_out = uverbs_zalloc(attrs, cmd_out_len); + if (IS_ERR(cmd_out)) + return PTR_ERR(cmd_out); MLX5_SET(general_obj_in_cmd_hdr, cmd_in, uid, c->devx_uid); err = mlx5_cmd_exec(obj->mdev, cmd_in, uverbs_attr_get_len(attrs, MLX5_IB_ATTR_DEVX_OBJ_QUERY_CMD_IN), cmd_out, cmd_out_len); if (err) - goto other_cmd_free; - - err = uverbs_copy_to(attrs, MLX5_IB_ATTR_DEVX_OBJ_QUERY_CMD_OUT, cmd_out, cmd_out_len); + return err; -other_cmd_free: - kvfree(cmd_out); - return err; + return uverbs_copy_to(attrs, MLX5_IB_ATTR_DEVX_OBJ_QUERY_CMD_OUT, + cmd_out, cmd_out_len); } static int devx_umem_get(struct mlx5_ib_dev *dev, struct ib_ucontext *ucontext, @@ -896,18 +881,14 @@ static int devx_umem_get(struct mlx5_ib_dev *dev, struct ib_ucontext *ucontext, return 0; } -static int devx_umem_reg_cmd_alloc(struct devx_umem *obj, +static int devx_umem_reg_cmd_alloc(struct uverbs_attr_bundle *attrs, + struct devx_umem *obj, struct devx_umem_reg_cmd *cmd) { cmd->inlen = MLX5_ST_SZ_BYTES(create_umem_in) + (MLX5_ST_SZ_BYTES(mtt) * obj->ncont); - cmd->in = kvzalloc(cmd->inlen, GFP_KERNEL); - return cmd->in ? 0 : -ENOMEM; -} - -static void devx_umem_reg_cmd_free(struct devx_umem_reg_cmd *cmd) -{ - kvfree(cmd->in); + cmd->in = uverbs_zalloc(attrs, cmd->inlen); + return PTR_ERR_OR_ZERO(cmd->in); } static void devx_umem_reg_cmd_build(struct mlx5_ib_dev *dev, @@ -954,7 +935,7 @@ static int UVERBS_HANDLER(MLX5_IB_METHOD_DEVX_UMEM_REG)( if (err) goto err_obj_free; - err = devx_umem_reg_cmd_alloc(obj, &cmd); + err = devx_umem_reg_cmd_alloc(attrs, obj, &cmd); if (err) goto err_umem_release; @@ -964,7 +945,7 @@ static int UVERBS_HANDLER(MLX5_IB_METHOD_DEVX_UMEM_REG)( err = mlx5_cmd_exec(dev->mdev, cmd.in, cmd.inlen, cmd.out, sizeof(cmd.out)); if (err) - goto err_umem_reg_cmd_free; + goto err_umem_release; obj->mdev = dev->mdev; uobj->object = obj; @@ -973,14 +954,10 @@ static int UVERBS_HANDLER(MLX5_IB_METHOD_DEVX_UMEM_REG)( if (err) goto err_umem_destroy; - devx_umem_reg_cmd_free(&cmd); - return 0; err_umem_destroy: mlx5_cmd_exec(obj->mdev, obj->dinbox, obj->dinlen, cmd.out, sizeof(cmd.out)); -err_umem_reg_cmd_free: - devx_umem_reg_cmd_free(&cmd); err_umem_release: ib_umem_release(obj->umem); err_obj_free: