From patchwork Tue Oct 7 17:54:33 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Gerecke, Jason" X-Patchwork-Id: 5048211 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 AAB53C11AB for ; Tue, 7 Oct 2014 17:55:55 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 832FD2017D for ; Tue, 7 Oct 2014 17:55:54 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 91F3020142 for ; Tue, 7 Oct 2014 17:55:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932165AbaJGRz0 (ORCPT ); Tue, 7 Oct 2014 13:55:26 -0400 Received: from mail-pa0-f52.google.com ([209.85.220.52]:51610 "EHLO mail-pa0-f52.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932166AbaJGRzY (ORCPT ); Tue, 7 Oct 2014 13:55:24 -0400 Received: by mail-pa0-f52.google.com with SMTP id fb1so7604008pad.39 for ; Tue, 07 Oct 2014 10:55:24 -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; bh=1DE18RzbXntX9HlV/mlgf/vrwO06JHXLMk2mgIeTEnw=; b=JBesOzLqTbnuu63Hhtbo2Gz1HKV0lQ0FFkjr1crjpotYmdQAU0/8xCftPpQ6Dbwrip SDtwnBkHuYpL2xzy+2GoagEO4dyOQ/hM5e3ew8EHOhByntJRH3hdf9eIILIb4uSy4UYY PQw2jw8vEKmvHAjMb0Rm51RS4Af265ShgUfGbqxLhHkhEBIslOFTQa8dQJq9vpqIIuQl bKkprQmATsJt9OdwH7oyzX40TOO7nBdn9mi901TFvgvRxm0jGgoseblmQtYFcDzMOAXK bW18aNQOR0wMnqN+l9DJh+VTZAWKH+cqjOj+H257b+KBpuxKcBjSzf7symAhYo/U2jV0 PCXA== X-Received: by 10.70.36.79 with SMTP id o15mr5576116pdj.6.1412704523953; Tue, 07 Oct 2014 10:55:23 -0700 (PDT) Received: from wacom-arch2.localdomain ([67.51.163.2]) by mx.google.com with ESMTPSA id pg2sm16535229pbb.43.2014.10.07.10.55.21 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 07 Oct 2014 10:55:22 -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] HID: wacom: Prevent potential null dereference after disconnect Date: Tue, 7 Oct 2014 10:54:33 -0700 Message-Id: <1412704473-6708-1-git-send-email-killertofu@gmail.com> X-Mailer: git-send-email 2.1.2 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=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 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 --- 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..d9ae467 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;