From patchwork Sat May 6 15:40:17 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geliang Tang X-Patchwork-Id: 9714963 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id E47C660362 for ; Sat, 6 May 2017 15:40:31 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B34ED27FAC for ; Sat, 6 May 2017 15:40:31 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A44A728630; Sat, 6 May 2017 15:40:31 +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=-4.1 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_MED, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 3CA6A27FAC for ; Sat, 6 May 2017 15:40:31 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id CB26089467; Sat, 6 May 2017 15:40:29 +0000 (UTC) X-Original-To: intel-gfx@lists.freedesktop.org Delivered-To: intel-gfx@lists.freedesktop.org Received: from mail-pg0-x241.google.com (mail-pg0-x241.google.com [IPv6:2607:f8b0:400e:c05::241]) by gabe.freedesktop.org (Postfix) with ESMTPS id E4FC289467; Sat, 6 May 2017 15:40:27 +0000 (UTC) Received: by mail-pg0-x241.google.com with SMTP id i63so4578365pgd.2; Sat, 06 May 2017 08:40:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=R7xjJL3KT7jtRmxKtaR0JYE7y9IkzthyUXbcl7BCGXk=; b=ubotCtO5Ib9QxDZQiOyw2trC6WfV2cWRYeUneiqoF4uxBwdshNnoRwHwLPRBpL2/9/ DcAC/vOqBXSb80z78AgOsJNoWtFOqoeYPncIZlzkO1vxKVmNHPxCoYz4li64l86pojpz zmDojX/XFSX6h0YJrOAPeLl6IQo3jCondLQa3QWMuGNZLr+V9sGsYpqglllsWYVuC9eo F7NfggLWXURpTzQ0i7o84WIX1lUVV0TWHUsnJEY4UZ/U/BBNI0sLJzLVz+J0/cxFcjLy 53Gx3FKALHf0I/qBmhN23VB//vWolo5e/YrBsRt/I7jCsX/NFdXDI6JnPSNspm+dki2M 6YtQ== 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; bh=R7xjJL3KT7jtRmxKtaR0JYE7y9IkzthyUXbcl7BCGXk=; b=sb/byQ3z8hcLTZNPwJDRwjk5AeVf+hjUdVLVwiON7CVXrjngsvHIxSLnM4BeEWQ2kX +UP16eocXLZ80gQsDnfLDl5UPGeO2t9ERJtHfP1TWrxLe4c+tGTnCZPV6VNfweaKfBKF Lku3PfwuqaI9I2X8stZ32Oqm/RMh5UK+WveMbfTCAG/YHCrpv3f0Em+8DYPMwFsIR4ik cvW5+VE7byBTiCWLPunDp9HkWcxX4C31fjUukiWDkvOO3Ix7F8UFjJD8++VQTvR9mVzX eC151Lh7sLkAdJMGR7FCJ9w4eujSyxUIfZwJLra5eJYmmizv1RYReDcIalsCE4xpu+aj yj0g== X-Gm-Message-State: AN3rC/7LcUyDJttDNM3js/FYEsCPNstFAeqGRwHzH/vraHKrZ4zMY7s8 igiKYuBQZwfeJhhK X-Received: by 10.98.211.202 with SMTP id z71mr18371106pfk.46.1494085227501; Sat, 06 May 2017 08:40:27 -0700 (PDT) Received: from localhost (li409-196.members.linode.com. [106.187.89.196]) by smtp.gmail.com with ESMTPSA id m125sm15448056pfc.3.2017.05.06.08.40.26 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Sat, 06 May 2017 08:40:27 -0700 (PDT) From: Geliang Tang To: Daniel Vetter , Jani Nikula , David Airlie Date: Sat, 6 May 2017 23:40:17 +0800 Message-Id: <6baf3aa45d0b5e0fd016b508bac905ebf8443aac.1493779294.git.geliangtang@gmail.com> X-Mailer: git-send-email 2.11.0 Cc: Geliang Tang , intel-gfx@lists.freedesktop.org, linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org Subject: [Intel-gfx] [PATCH] drm/i915: use memdup_user_nul X-BeenThere: intel-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Intel graphics driver community testing & development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: intel-gfx-bounces@lists.freedesktop.org Sender: "Intel-gfx" X-Virus-Scanned: ClamAV using ClamSMTP Use memdup_user_nul() helper instead of open-coding to simplify the code. Signed-off-by: Geliang Tang --- drivers/gpu/drm/i915/i915_debugfs.c | 13 +++---------- drivers/gpu/drm/i915/intel_pipe_crc.c | 13 +++---------- 2 files changed, 6 insertions(+), 20 deletions(-) diff --git a/drivers/gpu/drm/i915/i915_debugfs.c b/drivers/gpu/drm/i915/i915_debugfs.c index d689e51..e56b636 100644 --- a/drivers/gpu/drm/i915/i915_debugfs.c +++ b/drivers/gpu/drm/i915/i915_debugfs.c @@ -3704,16 +3704,10 @@ static ssize_t i915_displayport_test_active_write(struct file *file, if (len == 0) return 0; - input_buffer = kmalloc(len + 1, GFP_KERNEL); - if (!input_buffer) - return -ENOMEM; + input_buffer = memdup_user_nul(ubuf, len); + if (IS_ERR(input_buffer)) + return PTR_ERR(input_buffer); - if (copy_from_user(input_buffer, ubuf, len)) { - status = -EFAULT; - goto out; - } - - input_buffer[len] = '\0'; DRM_DEBUG_DRIVER("Copied %d bytes from user\n", (unsigned int)len); drm_connector_list_iter_begin(dev, &conn_iter); @@ -3739,7 +3733,6 @@ static ssize_t i915_displayport_test_active_write(struct file *file, } } drm_connector_list_iter_end(&conn_iter); -out: kfree(input_buffer); if (status < 0) return status; diff --git a/drivers/gpu/drm/i915/intel_pipe_crc.c b/drivers/gpu/drm/i915/intel_pipe_crc.c index 206ee4f..813dd3c 100644 --- a/drivers/gpu/drm/i915/intel_pipe_crc.c +++ b/drivers/gpu/drm/i915/intel_pipe_crc.c @@ -842,19 +842,12 @@ static ssize_t display_crc_ctl_write(struct file *file, const char __user *ubuf, return -E2BIG; } - tmpbuf = kmalloc(len + 1, GFP_KERNEL); - if (!tmpbuf) - return -ENOMEM; - - if (copy_from_user(tmpbuf, ubuf, len)) { - ret = -EFAULT; - goto out; - } - tmpbuf[len] = '\0'; + tmpbuf = memdup_user_nul(ubuf, len); + if (IS_ERR(tmpbuf)) + return PTR_ERR(tmpbuf); ret = display_crc_ctl_parse(dev_priv, tmpbuf, len); -out: kfree(tmpbuf); if (ret < 0) return ret;