From patchwork Thu Oct 5 00:53:18 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kees Cook X-Patchwork-Id: 9986215 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 17BD0605A8 for ; Thu, 5 Oct 2017 00:57:56 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 069EC28C43 for ; Thu, 5 Oct 2017 00:57:56 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id ED47528C46; Thu, 5 Oct 2017 00:57:55 +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=-7.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, RCVD_IN_DNSWL_HI 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 48B3728C43 for ; Thu, 5 Oct 2017 00:57:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752980AbdJEAxZ (ORCPT ); Wed, 4 Oct 2017 20:53:25 -0400 Received: from mail-pf0-f181.google.com ([209.85.192.181]:52111 "EHLO mail-pf0-f181.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752977AbdJEAxV (ORCPT ); Wed, 4 Oct 2017 20:53:21 -0400 Received: by mail-pf0-f181.google.com with SMTP id n14so5232697pfh.8 for ; Wed, 04 Oct 2017 17:53:21 -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=QyDvHh4nLHlQsZycOkas0yoKxQ84ZKheszBPprf66BY=; b=WdCUT5kOMn19Z/QIjw1LWpMARA0VenEmp/YW1J9wnu4lcJi5r6Hlo01AXexx18gjj5 0eXOJDhQSrrBXE2jekCr8ir/gkQOo8+vGC+FReQHK/wgYeA3Zgnt3Ia6XBZcrKb0n0TQ 4iKeJWJokunfwl2G3MV9S8u8+YdXzMd00vF0s= 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=QyDvHh4nLHlQsZycOkas0yoKxQ84ZKheszBPprf66BY=; b=hZuso8ODuUCwAV8YSptcdBbjgiha2vEYKgtk0szf066GM8RknuYZI4ZIrJBfy34jFS k6NnFMAhYIV9NFz/Js96BPqVa9Hx8jkXNp1uxhqZ+jQx+dtYuZcOaIhsS/0V/Om2+MoQ aSxFj0QdTd8ZOVSRVwR8mQMfkfi85UDoiao/sOzLMAt1hpvub+/9aR/UPwJV4e2QK/J5 8sP76p1L0hQX3VGzDkBt4bP0K5X3eyTLyHYfDmLQbAl6E0fXJK+BF9QmFc6AKPfafHIb 2yOq1pA838FyjZLc7haolpOcWRxndFNnjvlQ7zeGX7tpmFXUV0e2bcv1m2gglUuVXea0 wvCw== X-Gm-Message-State: AHPjjUhL8tEVWh+Fq23ZpcVBXrhw3XuqbNZbfVXMFRrh33YEsbN6Si1C I39rL7HdnZydsdELm+45QuN4rg== X-Google-Smtp-Source: AOwi7QCPZWuG3OUwK/wMQzEJdl02/zBrkorZSEBX3U7zpjMG09jLVLTb9/QdvkChocvlNV/JED633A== X-Received: by 10.99.104.138 with SMTP id d132mr20048941pgc.268.1507164800674; Wed, 04 Oct 2017 17:53:20 -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 u192sm28385353pgc.18.2017.10.04.17.53.19 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 04 Oct 2017 17:53:19 -0700 (PDT) Date: Wed, 4 Oct 2017 17:53:18 -0700 From: Kees Cook To: linux-kernel@vger.kernel.org Cc: Dmitry Torokhov , Mauro Carvalho Chehab , Hans Verkuil , Sakari Ailus , Geliang Tang , linux-input@vger.kernel.org, linux-media@vger.kernel.org, Thomas Gleixner Subject: [PATCH] input: Convert timers to use timer_setup() Message-ID: <20171005005318.GA23738@beast> MIME-Version: 1.0 Content-Disposition: inline Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@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. One input_dev user hijacks the input_dev software autorepeat timer to perform its own repeat management. However, there is not path back to the existing status variable, so add a generic one to the input structure and use that instead. Cc: Dmitry Torokhov Cc: Mauro Carvalho Chehab Cc: Hans Verkuil Cc: Sakari Ailus Cc: Geliang Tang Cc: linux-input@vger.kernel.org Cc: linux-media@vger.kernel.org Cc: Thomas Gleixner Signed-off-by: Kees Cook --- This requires commit 686fef928bba ("timer: Prepare to change timer callback argument type") in v4.14-rc3, but should be otherwise stand-alone. --- drivers/input/input.c | 12 ++++++------ drivers/media/pci/ttpci/av7110.h | 1 - drivers/media/pci/ttpci/av7110_ir.c | 16 ++++++++-------- include/linux/input.h | 2 ++ 4 files changed, 16 insertions(+), 15 deletions(-) diff --git a/drivers/input/input.c b/drivers/input/input.c index d268fdc23c64..497ad2dcb699 100644 --- a/drivers/input/input.c +++ b/drivers/input/input.c @@ -76,7 +76,7 @@ static void input_start_autorepeat(struct input_dev *dev, int code) { if (test_bit(EV_REP, dev->evbit) && dev->rep[REP_PERIOD] && dev->rep[REP_DELAY] && - dev->timer.data) { + dev->timer.function) { dev->repeat_key = code; mod_timer(&dev->timer, jiffies + msecs_to_jiffies(dev->rep[REP_DELAY])); @@ -179,9 +179,9 @@ static void input_pass_event(struct input_dev *dev, * dev->event_lock here to avoid racing with input_event * which may cause keys get "stuck". */ -static void input_repeat_key(unsigned long data) +static void input_repeat_key(struct timer_list *t) { - struct input_dev *dev = (void *) data; + struct input_dev *dev = from_timer(dev, t, timer); unsigned long flags; spin_lock_irqsave(&dev->event_lock, flags); @@ -1790,7 +1790,7 @@ struct input_dev *input_allocate_device(void) device_initialize(&dev->dev); mutex_init(&dev->mutex); spin_lock_init(&dev->event_lock); - init_timer(&dev->timer); + timer_setup(&dev->timer, NULL, 0); INIT_LIST_HEAD(&dev->h_list); INIT_LIST_HEAD(&dev->node); @@ -2053,8 +2053,8 @@ static void devm_input_device_unregister(struct device *dev, void *res) */ void input_enable_softrepeat(struct input_dev *dev, int delay, int period) { - dev->timer.data = (unsigned long) dev; - dev->timer.function = input_repeat_key; + dev->timer.function = (TIMER_FUNC_TYPE)input_repeat_key; + dev->timer_data = 0; dev->rep[REP_DELAY] = delay; dev->rep[REP_PERIOD] = period; } diff --git a/drivers/media/pci/ttpci/av7110.h b/drivers/media/pci/ttpci/av7110.h index 347827925c14..b98a4f3006df 100644 --- a/drivers/media/pci/ttpci/av7110.h +++ b/drivers/media/pci/ttpci/av7110.h @@ -93,7 +93,6 @@ struct infrared { u8 inversion; u16 last_key; u16 last_toggle; - u8 delay_timer_finished; }; diff --git a/drivers/media/pci/ttpci/av7110_ir.c b/drivers/media/pci/ttpci/av7110_ir.c index ca05198de2c2..a883caa6488c 100644 --- a/drivers/media/pci/ttpci/av7110_ir.c +++ b/drivers/media/pci/ttpci/av7110_ir.c @@ -155,16 +155,16 @@ static void av7110_emit_key(unsigned long parm) if (timer_pending(&ir->keyup_timer)) { del_timer(&ir->keyup_timer); if (ir->last_key != keycode || toggle != ir->last_toggle) { - ir->delay_timer_finished = 0; + ir->input_dev->timer_data = 0; input_event(ir->input_dev, EV_KEY, ir->last_key, 0); input_event(ir->input_dev, EV_KEY, keycode, 1); input_sync(ir->input_dev); - } else if (ir->delay_timer_finished) { + } else if (ir->input_dev->timer_data) { input_event(ir->input_dev, EV_KEY, keycode, 2); input_sync(ir->input_dev); } } else { - ir->delay_timer_finished = 0; + ir->input_dev->timer_data = 0; input_event(ir->input_dev, EV_KEY, keycode, 1); input_sync(ir->input_dev); } @@ -206,11 +206,12 @@ static void input_register_keys(struct infrared *ir) /* called by the input driver after rep[REP_DELAY] ms */ -static void input_repeat_key(unsigned long parm) +static void input_repeat_key(struct timer_list *t) { - struct infrared *ir = (struct infrared *) parm; + struct input_dev *dev = from_timer(dev, t, timer); - ir->delay_timer_finished = 1; + /* Key repeat started */ + dev->timer_data = 1; } @@ -365,8 +366,7 @@ int av7110_ir_init(struct av7110 *av7110) input_free_device(input_dev); return err; } - input_dev->timer.function = input_repeat_key; - input_dev->timer.data = (unsigned long) &av7110->ir; + input_dev->timer.function = (TIMER_FUNC_TYPE)input_repeat_key; if (av_cnt == 1) { e = proc_create("av7110_ir", S_IWUSR, NULL, &av7110_ir_proc_fops); diff --git a/include/linux/input.h b/include/linux/input.h index fb5e23c7ed98..dcd117bf1027 100644 --- a/include/linux/input.h +++ b/include/linux/input.h @@ -70,6 +70,7 @@ struct input_value { * @repeat_key: stores key code of the last key pressed; used to implement * software autorepeat * @timer: timer for software autorepeat + * @timer_data: timer data for software autorepeat overrides * @rep: current values for autorepeat parameters (delay, rate) * @mt: pointer to multitouch state * @absinfo: array of &struct input_absinfo elements holding information @@ -152,6 +153,7 @@ struct input_dev { unsigned int repeat_key; struct timer_list timer; + unsigned long timer_data; int rep[REP_CNT];