From patchwork Fri Jul 27 20:28:59 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Roland Dreier X-Patchwork-Id: 1250641 Return-Path: X-Original-To: patchwork-linux-rdma@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork1.kernel.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by patchwork1.kernel.org (Postfix) with ESMTP id A041B3FC5A for ; Fri, 27 Jul 2012 20:29:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751735Ab2G0U3G (ORCPT ); Fri, 27 Jul 2012 16:29:06 -0400 Received: from na3sys010aog108.obsmtp.com ([74.125.245.84]:47058 "HELO na3sys010aog108.obsmtp.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with SMTP id S1751249Ab2G0U3G (ORCPT ); Fri, 27 Jul 2012 16:29:06 -0400 Received: from mail-pb0-f42.google.com ([209.85.160.42]) (using TLSv1) by na3sys010aob108.postini.com ([74.125.244.12]) with SMTP ID DSNKUBL6EcXEYhFQrWMWck9qOQo9g6UzxujI@postini.com; Fri, 27 Jul 2012 13:29:05 PDT Received: by pbbrp12 with SMTP id rp12so8764840pbb.1 for ; Fri, 27 Jul 2012 13:29:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=purestorage.com; s=google; h=sender:from:to:cc:subject:date:message-id:x-mailer; bh=dq8LSBKvWHQAOs8HHHwElPluu+eJa6185Z8mqNCygLs=; b=HkKiy0dcKH+gsq3OSiOeeHcg2BthSnnVe1EwacVMF+VkIzwUSMKBbXHIMKhak2Y5SE Cg2yCNfgXbDEE3/UOSZSyZtZzmQxJjyBhDooUoh1EkfdnhpVnI+9fS2MNJrlVqxtamiF eXkPNh+fq48e+fyKMVk68AjjF0+9JMwW69R4E= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=sender:from:to:cc:subject:date:message-id:x-mailer :x-gm-message-state; bh=dq8LSBKvWHQAOs8HHHwElPluu+eJa6185Z8mqNCygLs=; b=Rp4pOfTko2bEt9ZrqhMwACeDvOZGLpaPAVLEeCESnLIs4DvxB/aJkN7iHCE35jGKVL UQjuUdk8jY1W5fdPHj+/L4mGOTQc5rsuX1BDQbrbwbJ45zB4QXBHpxGTbhuzNB5M628t NSgV4qyaxXxcykxiiNfqPflaRK6qAmjMLz+bmBio6x1sDWhCOuS1deaS47PCCedlG8Yz pH3hRnI9SZkbVV3XJqtnpf2IVyaAuFbbUb2BH9UmQVUZ1zC0ZoMYyP1yWi+Gdy/PxNy/ kg+uRdKe2+Aamh+Jd8C4qDKLsIBqtc2vN1IV5XjS8xi930dBpxTf3JMhEvKmRAILl0n0 2DBA== Received: by 10.68.224.70 with SMTP id ra6mr16846416pbc.11.1343420944606; Fri, 27 Jul 2012 13:29:04 -0700 (PDT) Received: from roland-t410s.purestorage.com ([216.200.155.2]) by mx.google.com with ESMTPS id pg9sm2176170pbb.26.2012.07.27.13.29.03 (version=TLSv1/SSLv3 cipher=OTHER); Fri, 27 Jul 2012 13:29:04 -0700 (PDT) From: Roland Dreier To: Sean Hefty Cc: linux-rdma@vger.kernel.org Subject: [PATCH] RDMA/ucma: Convert open-coded equivalent to memdup_user() Date: Fri, 27 Jul 2012 13:28:59 -0700 Message-Id: <1343420939-13764-1-git-send-email-roland@kernel.org> X-Mailer: git-send-email 1.7.10.4 X-Gm-Message-State: ALoCoQkx+KZcPQ9swKw5+SWw7QxeeTaDgyWPg48rFTVYQiknkSRHHPHXGb04f23VWH3Rxw9NGAKS Sender: linux-rdma-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-rdma@vger.kernel.org From: Roland Dreier Suggested by scripts/coccinelle/api/memdup_user.cocci. Reported-by: Fengguang Wu Signed-off-by: Roland Dreier Acked-by: Sean Hefty --- drivers/infiniband/core/ucma.c | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) diff --git a/drivers/infiniband/core/ucma.c b/drivers/infiniband/core/ucma.c index 893cb87..6bf8504 100644 --- a/drivers/infiniband/core/ucma.c +++ b/drivers/infiniband/core/ucma.c @@ -1002,23 +1002,18 @@ static ssize_t ucma_set_option(struct ucma_file *file, const char __user *inbuf, if (IS_ERR(ctx)) return PTR_ERR(ctx); - optval = kmalloc(cmd.optlen, GFP_KERNEL); - if (!optval) { - ret = -ENOMEM; - goto out1; - } - - if (copy_from_user(optval, (void __user *) (unsigned long) cmd.optval, - cmd.optlen)) { - ret = -EFAULT; - goto out2; + optval = memdup_user((void __user *) (unsigned long) cmd.optval, + cmd.optlen); + if (IS_ERR(optval)) { + ret = PTR_ERR(optval); + goto out; } ret = ucma_set_option_level(ctx, cmd.level, cmd.optname, optval, cmd.optlen); -out2: kfree(optval); -out1: + +out: ucma_put_ctx(ctx); return ret; }