From patchwork Wed Dec 11 10:35:11 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Vetter X-Patchwork-Id: 3324181 Return-Path: X-Original-To: patchwork-dri-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 281A69F388 for ; Wed, 11 Dec 2013 10:37:02 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 083EC206D8 for ; Wed, 11 Dec 2013 10:37:01 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) by mail.kernel.org (Postfix) with ESMTP id 5B8B520726 for ; Wed, 11 Dec 2013 10:36:56 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id CBC351057CB; Wed, 11 Dec 2013 02:36:46 -0800 (PST) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-ea0-f181.google.com (mail-ea0-f181.google.com [209.85.215.181]) by gabe.freedesktop.org (Postfix) with ESMTP id E0735FB620 for ; Wed, 11 Dec 2013 02:35:36 -0800 (PST) Received: by mail-ea0-f181.google.com with SMTP id m10so2781474eaj.26 for ; Wed, 11 Dec 2013 02:35:36 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ffwll.ch; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=w3EmbmMt0mTwl/ASoe/SlRqSgxMR3dsVAPMmWaAsO4U=; b=AOL4xokcWhh6czYYEoGh8fa800e4cFdUgHjnAAhvI/uCIGUyz25gaufzZxvx13+32e tRlDlDwt6BWB+JqMY3Vt9tmWYLwMQSaIH91rItdVge8b6mhlbFbWXmhJhslBBuR7bFvF GQfJkZi/TUwNRqpmeQg46DG8+FzRG7WsMplT0= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=w3EmbmMt0mTwl/ASoe/SlRqSgxMR3dsVAPMmWaAsO4U=; b=TYA7OoEojoXFakvKZaAFUtNI3RWcRROvZzD6L2ksxEETnA5OhRWTujpGOVBqnXTQCh wYmcKiERljxdZLuK3rbAjKlqQ2OO2uC1/x8WcN1RbpGRKUT3LNKyB5Z7nSrSfR1b05o1 8pIn2PyJn1WuHwEc+oGhMmvJ5M7cIU4X1iHN5TGW2eCvDst8ZX7FD1zI905tKcZFJaPg m6ylgW4vD5hswESMbZ5Acj6K+VvxnpYdUy8UQcFt9x/yR1qsk1oGEHPI+xQAy1yzESl9 VD1xskj8lqPb7wFC3wXd1zbJyUUfrGVHyKxqg6iS0FPQZsLYoBkGbFaYc37nrj0Ry6EZ K1hA== X-Gm-Message-State: ALoCoQnM15D/tt0r/enplP5c6vgk/5/Cs7De3SxzUzi0AoTXKI5xNU6hdNejt6CAig/nHL1H8w60 X-Received: by 10.14.88.134 with SMTP id a6mr932694eef.5.1386758136207; Wed, 11 Dec 2013 02:35:36 -0800 (PST) Received: from phenom.ffwll.local (178-83-130-250.dynamic.hispeed.ch. [178.83.130.250]) by mx.google.com with ESMTPSA id b41sm51932269eef.16.2013.12.11.02.35.34 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 11 Dec 2013 02:35:35 -0800 (PST) From: Daniel Vetter To: DRI Development Subject: [PATCH 50/50] drm: use memdup_user() as a cleanup Date: Wed, 11 Dec 2013 11:35:11 +0100 Message-Id: <1386758111-3446-51-git-send-email-daniel.vetter@ffwll.ch> X-Mailer: git-send-email 1.8.4.3 In-Reply-To: <1386758111-3446-1-git-send-email-daniel.vetter@ffwll.ch> References: <1386758111-3446-1-git-send-email-daniel.vetter@ffwll.ch> Cc: Daniel Vetter , Dan Carpenter X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: dri-devel-bounces@lists.freedesktop.org Errors-To: dri-devel-bounces@lists.freedesktop.org X-Spam-Status: No, score=-4.3 required=5.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_MED,RP_MATCHES_RCVD,T_DKIM_INVALID,UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Dan Carpenter drivers/gpu/drm/r128/r128_state.c:1014:10-17: WARNING opportunity for memdup_user /c/kernel-tests/src/cocci/drivers/gpu/drm/r128/r128_state.c:1029:9-16: WARNING opportunity for memdup_user /c/kernel-tests/src/cocci/drivers/gpu/drm/r128/r128_state.c:904:10-17: WARNING opportunity for memdup_user /c/kernel-tests/src/cocci/drivers/gpu/drm/r128/r128_state.c:914:9-16: WARNING opportunity for memdup_user Use memdup_user rather than duplicating its implementation This is a little bit restricted to reduce false positives Generated by: coccinelle/api/memdup_user.cocci CC: Daniel Vetter Signed-off-by: Dan Carpenter Signed-off-by: Daniel Vetter --- drivers/gpu/drm/r128/r128_state.c | 46 ++++++++++----------------------------- 1 file changed, 12 insertions(+), 34 deletions(-) diff --git a/drivers/gpu/drm/r128/r128_state.c b/drivers/gpu/drm/r128/r128_state.c index 22a5545c5f49..97064dd434c2 100644 --- a/drivers/gpu/drm/r128/r128_state.c +++ b/drivers/gpu/drm/r128/r128_state.c @@ -901,25 +901,16 @@ static int r128_cce_dispatch_write_span(struct drm_device *dev, return -EFAULT; buffer_size = depth->n * sizeof(u32); - buffer = kmalloc(buffer_size, GFP_KERNEL); - if (buffer == NULL) - return -ENOMEM; - if (copy_from_user(buffer, depth->buffer, buffer_size)) { - kfree(buffer); - return -EFAULT; - } + buffer = memdup_user(depth->buffer, buffer_size); + if (IS_ERR(buffer)) + return PTR_ERR(buffer); mask_size = depth->n * sizeof(u8); if (depth->mask) { - mask = kmalloc(mask_size, GFP_KERNEL); - if (mask == NULL) { + mask = memdup_user(depth->mask, mask_size); + if (IS_ERR(mask)) { kfree(buffer); - return -ENOMEM; - } - if (copy_from_user(mask, depth->mask, mask_size)) { - kfree(buffer); - kfree(mask); - return -EFAULT; + return PTR_ERR(mask); } for (i = 0; i < count; i++, x++) { @@ -1011,34 +1002,21 @@ static int r128_cce_dispatch_write_pixels(struct drm_device *dev, } buffer_size = depth->n * sizeof(u32); - buffer = kmalloc(buffer_size, GFP_KERNEL); - if (buffer == NULL) { - kfree(x); - kfree(y); - return -ENOMEM; - } - if (copy_from_user(buffer, depth->buffer, buffer_size)) { + buffer = memdup_user(depth->buffer, buffer_size); + if (IS_ERR(buffer)) { kfree(x); kfree(y); - kfree(buffer); - return -EFAULT; + return PTR_ERR(buffer); } if (depth->mask) { mask_size = depth->n * sizeof(u8); - mask = kmalloc(mask_size, GFP_KERNEL); - if (mask == NULL) { - kfree(x); - kfree(y); - kfree(buffer); - return -ENOMEM; - } - if (copy_from_user(mask, depth->mask, mask_size)) { + mask = memdup_user(depth->mask, mask_size); + if (IS_ERR(mask)) { kfree(x); kfree(y); kfree(buffer); - kfree(mask); - return -EFAULT; + return PTR_ERR(mask); } for (i = 0; i < count; i++) {