From patchwork Thu Jan 12 17:17:42 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johan Hovold X-Patchwork-Id: 9513671 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 0C10260476 for ; Thu, 12 Jan 2017 17:19:52 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id EF275286F4 for ; Thu, 12 Jan 2017 17:19:51 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E3AC5286FA; Thu, 12 Jan 2017 17:19:51 +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=-6.3 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI, RCVD_IN_SORBS_SPAM, T_DKIM_INVALID autolearn=unavailable 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 56F8D286F4 for ; Thu, 12 Jan 2017 17:19:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751181AbdALRTO (ORCPT ); Thu, 12 Jan 2017 12:19:14 -0500 Received: from mail-lf0-f66.google.com ([209.85.215.66]:33510 "EHLO mail-lf0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751007AbdALRS3 (ORCPT ); Thu, 12 Jan 2017 12:18:29 -0500 Received: by mail-lf0-f66.google.com with SMTP id k62so2808726lfg.0; Thu, 12 Jan 2017 09:17:59 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=9DopMb2t1XPY/hPh1bz81X7OaRFtY68RKEaQd+E6G8k=; b=NCa/5unzqAo7cY7s/5KaZDYBPLC/WqeFDgiOODbnOOkGYZlk3bVHkh8MSF0zMDcEmp dinvV5iri3OrhQ5+oxj9x71UID5u6/E6ve5HjVOQfeVnZ7BXXkb1nhamD24Ii3sdoB/J lcr74hJw00H44GHYA/1TN1HWZmq8cC+ZzkCZPrXzhbD+cLRDJmjQc82bzXemcNA5bXRp dVzy6aVGZr3GA/xgcMyLO2U6DYG6mB8tZVODLteptwPEAJtfYiGelNXywytngTYL7l+I jTIKgBwMpLG4HYeGr8iyK1P7rjNatEMJdsBm2QTxI5WF0NkQ5Dqhh8i1Kv9kFMqEu0WT hbBw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=9DopMb2t1XPY/hPh1bz81X7OaRFtY68RKEaQd+E6G8k=; b=nXqLsZTBVufo9guvMoiF4pSingUI9F1uSjSTjvgoebHcMrE0EYixqOEIjKoCtNFrwK gNAfdMdemsVDrMPUeGXnUyHr1vsy2OOhDm5Lf6Ncoc5xCzJfQNteVVy3geZ0MAFfQef5 xsmfOh5ucaXwJs+oPeSLAxpRiwA7glOCsspy8jU+rRzIotfJXVElMf8IC8D8CcxSY3vO FMolMyfS5R4OXkFkflcu6mHV8b4ShgWTIKtocyI0bY5BH8KowuxcnqbMabE6q6qFHzux 0I+U53GpwPwAcNFqP9c7MmcwOB/1OW02V/F62eTYazT96NRGC7rOAJCyRVMjfykSlBH+ UCVQ== X-Gm-Message-State: AIkVDXI8XaytdKy89GtpqOkzk5I9hoBMh55/aZTkQso7q33VQ9Pzf/oaiRPIwFPvBBYj8g== X-Received: by 10.25.31.17 with SMTP id f17mr6349342lff.22.1484241478593; Thu, 12 Jan 2017 09:17:58 -0800 (PST) Received: from xi.terra (c-04aadb54.07-184-6d6c6d4.cust.bredbandsbolaget.se. [84.219.170.4]) by smtp.gmail.com with ESMTPSA id s6sm2608921ljd.42.2017.01.12.09.17.57 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 12 Jan 2017 09:17:57 -0800 (PST) Received: from johan by xi.terra with local (Exim 4.88) (envelope-from ) id 1cRj0h-0001Z5-5E; Thu, 12 Jan 2017 18:17:59 +0100 From: Johan Hovold To: Jiri Kosina Cc: Benjamin Tissoires , linux-input@vger.kernel.org, linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, Johan Hovold , stable Subject: [PATCH 1/2] HID: corsair: fix DMA buffers on stack Date: Thu, 12 Jan 2017 18:17:42 +0100 Message-Id: <20170112171743.5972-2-johan@kernel.org> X-Mailer: git-send-email 2.10.2 In-Reply-To: <20170112171743.5972-1-johan@kernel.org> References: <20170112171743.5972-1-johan@kernel.org> Sender: linux-input-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Not all platforms support DMA to the stack, and specifically since v4.9 this is no longer supported on x86 with VMAP_STACK either. Note that the macro-mode buffer was larger than necessary. Fixes: 6f78193ee9ea ("HID: corsair: Add Corsair Vengeance K90 driver") Cc: stable Signed-off-by: Johan Hovold --- drivers/hid/hid-corsair.c | 54 ++++++++++++++++++++++++++++++++++++----------- 1 file changed, 42 insertions(+), 12 deletions(-) diff --git a/drivers/hid/hid-corsair.c b/drivers/hid/hid-corsair.c index 717704e9ae07..5971907a23b1 100644 --- a/drivers/hid/hid-corsair.c +++ b/drivers/hid/hid-corsair.c @@ -148,7 +148,11 @@ static enum led_brightness k90_backlight_get(struct led_classdev *led_cdev) struct usb_interface *usbif = to_usb_interface(dev->parent); struct usb_device *usbdev = interface_to_usbdev(usbif); int brightness; - char data[8]; + char *data; + + data = kmalloc(8, GFP_KERNEL); + if (!data) + return -ENOMEM; ret = usb_control_msg(usbdev, usb_rcvctrlpipe(usbdev, 0), K90_REQUEST_STATUS, @@ -158,16 +162,22 @@ static enum led_brightness k90_backlight_get(struct led_classdev *led_cdev) if (ret < 0) { dev_warn(dev, "Failed to get K90 initial state (error %d).\n", ret); - return -EIO; + ret = -EIO; + goto out; } brightness = data[4]; if (brightness < 0 || brightness > 3) { dev_warn(dev, "Read invalid backlight brightness: %02hhx.\n", data[4]); - return -EIO; + ret = -EIO; + goto out; } - return brightness; + ret = brightness; +out: + kfree(data); + + return ret; } static enum led_brightness k90_record_led_get(struct led_classdev *led_cdev) @@ -253,7 +263,11 @@ static ssize_t k90_show_macro_mode(struct device *dev, struct usb_interface *usbif = to_usb_interface(dev->parent); struct usb_device *usbdev = interface_to_usbdev(usbif); const char *macro_mode; - char data[8]; + char *data; + + data = kmalloc(2, GFP_KERNEL); + if (!data) + return -ENOMEM; ret = usb_control_msg(usbdev, usb_rcvctrlpipe(usbdev, 0), K90_REQUEST_GET_MODE, @@ -263,7 +277,8 @@ static ssize_t k90_show_macro_mode(struct device *dev, if (ret < 0) { dev_warn(dev, "Failed to get K90 initial mode (error %d).\n", ret); - return -EIO; + ret = -EIO; + goto out; } switch (data[0]) { @@ -277,10 +292,15 @@ static ssize_t k90_show_macro_mode(struct device *dev, default: dev_warn(dev, "K90 in unknown mode: %02hhx.\n", data[0]); - return -EIO; + ret = -EIO; + goto out; } - return snprintf(buf, PAGE_SIZE, "%s\n", macro_mode); + ret = snprintf(buf, PAGE_SIZE, "%s\n", macro_mode); +out: + kfree(data); + + return ret; } static ssize_t k90_store_macro_mode(struct device *dev, @@ -320,7 +340,11 @@ static ssize_t k90_show_current_profile(struct device *dev, struct usb_interface *usbif = to_usb_interface(dev->parent); struct usb_device *usbdev = interface_to_usbdev(usbif); int current_profile; - char data[8]; + char *data; + + data = kmalloc(8, GFP_KERNEL); + if (!data) + return -ENOMEM; ret = usb_control_msg(usbdev, usb_rcvctrlpipe(usbdev, 0), K90_REQUEST_STATUS, @@ -330,16 +354,22 @@ static ssize_t k90_show_current_profile(struct device *dev, if (ret < 0) { dev_warn(dev, "Failed to get K90 initial state (error %d).\n", ret); - return -EIO; + ret = -EIO; + goto out; } current_profile = data[7]; if (current_profile < 1 || current_profile > 3) { dev_warn(dev, "Read invalid current profile: %02hhx.\n", data[7]); - return -EIO; + ret = -EIO; + goto out; } - return snprintf(buf, PAGE_SIZE, "%d\n", current_profile); + ret = snprintf(buf, PAGE_SIZE, "%d\n", current_profile); +out: + kfree(data); + + return ret; } static ssize_t k90_store_current_profile(struct device *dev,