From patchwork Thu Oct 5 00:53:24 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kees Cook X-Patchwork-Id: 9986213 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 E8B84605A8 for ; Thu, 5 Oct 2017 00:57:45 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D9D5128C43 for ; Thu, 5 Oct 2017 00:57:45 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id CE59728C45; Thu, 5 Oct 2017 00:57:45 +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 2199128C43 for ; Thu, 5 Oct 2017 00:57:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752996AbdJEAxa (ORCPT ); Wed, 4 Oct 2017 20:53:30 -0400 Received: from mail-pf0-f178.google.com ([209.85.192.178]:50623 "EHLO mail-pf0-f178.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752447AbdJEAx1 (ORCPT ); Wed, 4 Oct 2017 20:53:27 -0400 Received: by mail-pf0-f178.google.com with SMTP id m63so7130007pfk.7 for ; Wed, 04 Oct 2017 17:53:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=date:from:to:cc:subject:message-id:mime-version:content-disposition; bh=78C0OGGKpNNXg4YAYw1LRJwmMUAUBI6ttq0Zm1bJiko=; b=Lo0s37WbN5oUT3THFn5Suh9VIaPiyAYL0fLilv0+rJJDlgFGMwemga6/09nUa/1w/q coQOT6TiUSTE7jbkeyD1ZqZE4SlTdmp0/wEQARJ1vE+vuB4gwzWEy0nmmgV8FDRFwxV7 xTo1QiiyIcxwdeqB0rrssbHEBwjU9wPJ9puww= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:mime-version :content-disposition; bh=78C0OGGKpNNXg4YAYw1LRJwmMUAUBI6ttq0Zm1bJiko=; b=EDYn4wzLEsinOXudx+QI5hZTJhb4w11sV/HB/faLUgAoeBVVjpfYt07W2/07jLNXzO 0qgJFOlul2xk9cCJPoQ3PhXpOqtwHDCDYwsd2nc7veqIa6GreZT/wI6/4NoK+ugrpNnu C69VRz8lGRAWCQmkBvbDkA1BDN0TR1/J03+iLJDjFyRiKc8rmvf8uwkK3bSZT6xfwEkv +y59XhKFKDKtyRkDEUDVpCa4UzMe4V+ZQJPUuxKE9R4mddrc+zl5WCbkjFqyNNcLZV1/ hhAiJ8rUmzlUw8iAtlAVcjdo0Pm7zZ8WlKc8UhDzBUdbbwpT1Rfl6bPpDVTUph7Mu71Z KsMg== X-Gm-Message-State: AMCzsaWmW0lNzupHPZh629sB6mBkHitURK05vAF3rzUxnz9dcH4EtX5P Gv83ZOF685zT5KGpo+GAQShUpsB23Cg= X-Google-Smtp-Source: AOwi7QBqKOSESnJOB8FZZBhHph0uMCVv1KH3uVmE2Z93vlCK9GaTqNqSxg7VJqN3vcHbJ3oa6XaVdg== X-Received: by 10.99.115.79 with SMTP id d15mr10961908pgn.343.1507164806561; Wed, 04 Oct 2017 17:53:26 -0700 (PDT) Received: from www.outflux.net (173-164-112-133-Oregon.hfc.comcastbusiness.net. [173.164.112.133]) by smtp.gmail.com with ESMTPSA id 20sm28518468pft.109.2017.10.04.17.53.25 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 04 Oct 2017 17:53:25 -0700 (PDT) Date: Wed, 4 Oct 2017 17:53:24 -0700 From: Kees Cook To: linux-kernel@vger.kernel.org Cc: Jiri Kosina , Benjamin Tissoires , linux-input@vger.kernel.org, linux-usb@vger.kernel.org, Thomas Gleixner Subject: [PATCH] HID: usbhid: Convert timers to use timer_setup() Message-ID: <20171005005324.GA23752@beast> MIME-Version: 1.0 Content-Disposition: inline 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 In preparation for unconditionally passing the struct timer_list pointer to all timer callbacks, switch to using the new timer_setup() and from_timer() to pass the timer pointer explicitly. Adds pointer back to hid_device for multitouch. Cc: Jiri Kosina Cc: Benjamin Tissoires Cc: linux-input@vger.kernel.org Cc: linux-usb@vger.kernel.org Cc: Thomas Gleixner Signed-off-by: Kees Cook Reviewed-by: Benjamin Tissoires --- This requires commit 686fef928bba ("timer: Prepare to change timer callback argument type") in v4.14-rc3, but should be otherwise stand-alone. --- drivers/hid/hid-multitouch.c | 10 ++++++---- drivers/hid/usbhid/hid-core.c | 8 ++++---- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/drivers/hid/hid-multitouch.c b/drivers/hid/hid-multitouch.c index 440b999304a5..b0e3e2614b18 100644 --- a/drivers/hid/hid-multitouch.c +++ b/drivers/hid/hid-multitouch.c @@ -112,6 +112,7 @@ struct mt_device { struct mt_slot curdata; /* placeholder of incoming data */ struct mt_class mtclass; /* our mt device class */ struct timer_list release_timer; /* to release sticky fingers */ + struct hid_device *hdev; /* hid_device we're attached to */ struct mt_fields *fields; /* temporary placeholder for storing the multitouch fields */ unsigned long mt_io_flags; /* mt flags (MT_IO_FLAGS_*) */ @@ -1245,10 +1246,10 @@ static void mt_release_contacts(struct hid_device *hid) td->num_received = 0; } -static void mt_expired_timeout(unsigned long arg) +static void mt_expired_timeout(struct timer_list *t) { - struct hid_device *hdev = (void *)arg; - struct mt_device *td = hid_get_drvdata(hdev); + struct mt_device *td = from_timer(td, t, release_timer); + struct hid_device *hdev = td->hdev; /* * An input report came in just before we release the sticky fingers, @@ -1279,6 +1280,7 @@ static int mt_probe(struct hid_device *hdev, const struct hid_device_id *id) dev_err(&hdev->dev, "cannot allocate multitouch data\n"); return -ENOMEM; } + td->hdev = hdev; td->mtclass = *mtclass; td->inputmode = -1; td->maxcontact_report_id = -1; @@ -1330,7 +1332,7 @@ static int mt_probe(struct hid_device *hdev, const struct hid_device_id *id) */ hdev->quirks |= HID_QUIRK_NO_INIT_REPORTS; - setup_timer(&td->release_timer, mt_expired_timeout, (long)hdev); + timer_setup(&td->release_timer, mt_expired_timeout, 0); ret = hid_parse(hdev); if (ret != 0) diff --git a/drivers/hid/usbhid/hid-core.c b/drivers/hid/usbhid/hid-core.c index 089bad8a9a21..9f9fe0e58f5b 100644 --- a/drivers/hid/usbhid/hid-core.c +++ b/drivers/hid/usbhid/hid-core.c @@ -101,10 +101,10 @@ static int hid_start_in(struct hid_device *hid) } /* I/O retry timer routine */ -static void hid_retry_timeout(unsigned long _hid) +static void hid_retry_timeout(struct timer_list *t) { - struct hid_device *hid = (struct hid_device *) _hid; - struct usbhid_device *usbhid = hid->driver_data; + struct usbhid_device *usbhid = from_timer(usbhid, t, io_retry); + struct hid_device *hid = usbhid->hid; dev_dbg(&usbhid->intf->dev, "retrying intr urb\n"); if (hid_start_in(hid)) @@ -1363,7 +1363,7 @@ static int usbhid_probe(struct usb_interface *intf, const struct usb_device_id * init_waitqueue_head(&usbhid->wait); INIT_WORK(&usbhid->reset_work, hid_reset); - setup_timer(&usbhid->io_retry, hid_retry_timeout, (unsigned long) hid); + timer_setup(&usbhid->io_retry, hid_retry_timeout, 0); spin_lock_init(&usbhid->lock); ret = hid_add_device(hid);