From patchwork Wed Oct 8 18:25:42 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Gerecke, Jason" X-Patchwork-Id: 5055011 X-Patchwork-Delegate: jikos@jikos.cz Return-Path: X-Original-To: patchwork-linux-input@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 82F6FC11AB for ; Wed, 8 Oct 2014 18:26:08 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id A3785201ED for ; Wed, 8 Oct 2014 18:26:07 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id BEE8A201DD for ; Wed, 8 Oct 2014 18:26:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753711AbaJHS0F (ORCPT ); Wed, 8 Oct 2014 14:26:05 -0400 Received: from mail-pd0-f181.google.com ([209.85.192.181]:53067 "EHLO mail-pd0-f181.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751928AbaJHS0E (ORCPT ); Wed, 8 Oct 2014 14:26:04 -0400 Received: by mail-pd0-f181.google.com with SMTP id z10so7265064pdj.40 for ; Wed, 08 Oct 2014 11:26:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=Mu5s03PH70PY2U7ngVAGpcf03TYB0wG7HbAKzky+Grs=; b=qOH3RK+2nCmp64Cj2fngT+f7Ce8xU6Xv5F+uGbez5GNip6G7zHaRrqJSpXMOkAB4dk U2NdfDREJd0M+zj1TJdbD0XEwEzI6F3rDqwZiltTn3GWp8Xn3E+/gVzqKFyX/jWcc5Po Q8W/VcqZlX1CeDyaGUCzaXBPn80H+esbwzBDOno7E7vR+fNzyvSwx1tF7dqQaXlHO2x9 GZ7VcyI7yemX/cLrL9iaw1TjyV68dZfQ4hKSnFykwgM0986HAY4/h6YtxtzHOEnyIODk LeVCVC5uLfnls3JyZyH9WkX0fThw/I50T2jedpLiVfgOhrPxj+VoBL0UKhaHCLC94ElV pIGg== X-Received: by 10.70.37.35 with SMTP id v3mr12938263pdj.120.1412792762761; Wed, 08 Oct 2014 11:26:02 -0700 (PDT) Received: from wacom-arch2.localdomain ([67.51.163.2]) by mx.google.com with ESMTPSA id tc5sm620700pbc.51.2014.10.08.11.26.00 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 08 Oct 2014 11:26:01 -0700 (PDT) From: Jason Gerecke To: jkosina@suse.cz, benjamin.tissoires@gmail.com, pinglinux@gmail.com Cc: linux-input@vger.kernel.org, linux-kernel@vger.kernel.org, Jason Gerecke Subject: [PATCH v2] HID: wacom: Prevent potential null dereference after disconnect Date: Wed, 8 Oct 2014 11:25:42 -0700 Message-Id: <1412792742-4075-1-git-send-email-killertofu@gmail.com> X-Mailer: git-send-email 2.1.2 In-Reply-To: <1412704473-6708-1-git-send-email-killertofu@gmail.com> References: <1412704473-6708-1-git-send-email-killertofu@gmail.com> Sender: linux-input-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org X-Spam-Status: No, score=-6.8 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, T_DKIM_INVALID, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=ham 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 Repeated connect/disconnect cycles under GNOME can trigger an occasional OOPS from within e.g. wacom_led_select_store, presumably due to a timing issue where userspace begins setting a value immediately before the device disconnects and our shared data is whisked away. Signed-off-by: Jason Gerecke --- Changes in v2: * Added in missing escape character drivers/hid/wacom_sys.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/drivers/hid/wacom_sys.c b/drivers/hid/wacom_sys.c index 8593047..265429b 100644 --- a/drivers/hid/wacom_sys.c +++ b/drivers/hid/wacom_sys.c @@ -641,6 +641,9 @@ static ssize_t wacom_led_select_store(struct device *dev, int set_id, unsigned int id; int err; + if (!wacom) + return -ENODEV; + err = kstrtouint(buf, 10, &id); if (err) return err; @@ -666,6 +669,8 @@ static ssize_t wacom_led##SET_ID##_select_show(struct device *dev, \ { \ struct hid_device *hdev = container_of(dev, struct hid_device, dev);\ struct wacom *wacom = hid_get_drvdata(hdev); \ + if (!wacom) \ + return -ENODEV; \ return scnprintf(buf, PAGE_SIZE, "%d\n", \ wacom->led.select[SET_ID]); \ } \ @@ -702,7 +707,8 @@ static ssize_t wacom_##name##_luminance_store(struct device *dev, \ { \ struct hid_device *hdev = container_of(dev, struct hid_device, dev);\ struct wacom *wacom = hid_get_drvdata(hdev); \ - \ + if (!wacom) \ + return -ENODEV; \ return wacom_luminance_store(wacom, &wacom->led.field, \ buf, count); \ } \ @@ -710,6 +716,8 @@ static ssize_t wacom_##name##_luminance_show(struct device *dev, \ struct device_attribute *attr, char *buf) \ { \ struct wacom *wacom = dev_get_drvdata(dev); \ + if (!wacom) \ + return -ENODEV; \ return scnprintf(buf, PAGE_SIZE, "%d\n", wacom->led.field); \ } \ static DEVICE_ATTR(name##_luminance, DEV_ATTR_RW_PERM, \ @@ -729,6 +737,9 @@ static ssize_t wacom_button_image_store(struct device *dev, int button_id, unsigned len; u8 xfer_id; + if (!wacom) + return -ENODEV; + if (hdev->bus == BUS_BLUETOOTH) { len = 256; xfer_id = WAC_CMD_ICON_BT_XFER;