From patchwork Thu May 19 19:01:56 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Heiner Kallweit X-Patchwork-Id: 9128303 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 0523F60213 for ; Thu, 19 May 2016 19:02:50 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E5D5828117 for ; Thu, 19 May 2016 19:02:49 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id DAB9B281B8; Thu, 19 May 2016 19:02:49 +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.8 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, T_DKIM_INVALID autolearn=ham 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 6A55E28117 for ; Thu, 19 May 2016 19:02:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754228AbcESTCr (ORCPT ); Thu, 19 May 2016 15:02:47 -0400 Received: from mail-wm0-f67.google.com ([74.125.82.67]:34268 "EHLO mail-wm0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751646AbcESTCq (ORCPT ); Thu, 19 May 2016 15:02:46 -0400 Received: by mail-wm0-f67.google.com with SMTP id n129so23531642wmn.1 for ; Thu, 19 May 2016 12:02:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:subject:to:cc:message-id:date:user-agent:mime-version :content-transfer-encoding; bh=glnBrOazsmdKUN0OCIWHOBzNBWBlmWioUK/GK23BMV4=; b=M8yoxnVBZDq2aLD4UialqFI0mmI4YSB7p0ZHU6V0D9E5/ub/0NgUiSjJxUfMMeNdM0 HgWkSvYSS1ZtoGH/7pCvaC3Q4ECB9N6KVBsDIXXtHaxsWpUQBWuH+I7OhMCBIlPivqoq jFc/Og40IuM68PeHxYP3No4ufLY4DHs6Ct+T1OsubANoikuE6iSAi7JdkCl4k/2UTws1 UNj63Q4i85r9yKwAJEJTGz2MudqXDJWqDEXD7xxgWKD0FNJkeUuLG2+Tewzgv9UBx7Tz A/moUX/vbif65L0nDrHwMDWudYtsoQae4aYK6J1V26JhTT0Kxg+KUOVcl142EMzXcDiX gTWg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:subject:to:cc:message-id:date:user-agent :mime-version:content-transfer-encoding; bh=glnBrOazsmdKUN0OCIWHOBzNBWBlmWioUK/GK23BMV4=; b=WIqWi8OeDHa6K/jjdqq1hZBnHzs91+UtDMdR0sY/KjuUsqtcV4QYDufG6O41G82rKO V9tkdh3MWJdqFw+DZLjPXkopPKvNCbhREU0CrCn0MZ4bsVaSvdF5q7kBpQUOt41e6vsJ /gL1zS+4h/LLiP+aHQ04E+LU3uVsXr9blmOM5VzVTN2mRbiTnEqMPQeRJMynUsZBHZBz KGJ1mCH4oC+6Ck/GyItExiDCE0tDrqbA5Aj0wkFAqFP4i7MBypJPc3Ms2rWcWa0q09F6 gFpgA+UPBwPmHtq9HR6r92K6k6AIKwPzPAJqKLUFzi7CxkaCNkhptPggSrph7PpKSoXQ 8PWQ== X-Gm-Message-State: AOPr4FUoaGOJTRvquNiMO30Ma0LvvMcq39MmcQfiS48P9KkYsXfDP8pTHgjNA/p5g3FuOg== X-Received: by 10.194.86.129 with SMTP id p1mr14913482wjz.117.1463684564717; Thu, 19 May 2016 12:02:44 -0700 (PDT) Received: from ?IPv6:2003:62:5f01:4400:846f:38c9:5cf2:89af? (p200300625F014400846F38C95CF289AF.dip0.t-ipconnect.de. [2003:62:5f01:4400:846f:38c9:5cf2:89af]) by smtp.googlemail.com with ESMTPSA id i1sm15846469wjm.12.2016.05.19.12.02.43 (version=TLSv1/SSLv3 cipher=OTHER); Thu, 19 May 2016 12:02:44 -0700 (PDT) From: Heiner Kallweit Subject: [PATCH v2 1/2] media: rc: make fifo size for raw events configurable via rc_dev To: Mauro Carvalho Chehab Cc: linux-media@vger.kernel.org Message-ID: <67474fa8-4f58-75e4-f5b2-1b07c6b21009@gmail.com> Date: Thu, 19 May 2016 21:01:56 +0200 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:45.0) Gecko/20100101 Thunderbird/45.1.0 MIME-Version: 1.0 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 Currently the fifo size is 512 elements. After a recent patch the size of struct ir_raw_event is down to 8 bytes, so the fifo still consumes 4KB. In most cases a much smaller fifo is sufficient, e.g. nuvoton-cir triggers event processing after 24 events latest. This patch introduces an element raw_fifo_size to struct rc_dev to allow configuring the fifo size. If not set the current default MAX_IR_EVENT_SIZE is used. Signed-off-by: Heiner Kallweit --- v2: - access dev->raw_fifo_size only after check for !dev --- drivers/media/rc/rc-core-priv.h | 2 +- drivers/media/rc/rc-ir-raw.c | 14 ++++++++++++-- include/media/rc-core.h | 2 ++ 3 files changed, 15 insertions(+), 3 deletions(-) diff --git a/drivers/media/rc/rc-core-priv.h b/drivers/media/rc/rc-core-priv.h index 585d5e5..ae6f81e 100644 --- a/drivers/media/rc/rc-core-priv.h +++ b/drivers/media/rc/rc-core-priv.h @@ -39,7 +39,7 @@ struct ir_raw_event_ctrl { struct task_struct *thread; spinlock_t lock; /* fifo for the pulse/space durations */ - DECLARE_KFIFO(kfifo, struct ir_raw_event, MAX_IR_EVENT_SIZE); + DECLARE_KFIFO_PTR(kfifo, struct ir_raw_event); ktime_t last_event; /* when last event occurred */ enum raw_event_type last_type; /* last event type */ struct rc_dev *dev; /* pointer to the parent rc_dev */ diff --git a/drivers/media/rc/rc-ir-raw.c b/drivers/media/rc/rc-ir-raw.c index 144304c..f9b7734 100644 --- a/drivers/media/rc/rc-ir-raw.c +++ b/drivers/media/rc/rc-ir-raw.c @@ -261,17 +261,24 @@ int ir_raw_event_register(struct rc_dev *dev) { int rc; struct ir_raw_handler *handler; + unsigned fifo_size = MAX_IR_EVENT_SIZE; if (!dev) return -EINVAL; + if (dev->raw_fifo_size) + fifo_size = dev->raw_fifo_size; + dev->raw = kzalloc(sizeof(*dev->raw), GFP_KERNEL); if (!dev->raw) return -ENOMEM; dev->raw->dev = dev; dev->change_protocol = change_protocol; - INIT_KFIFO(dev->raw->kfifo); + + rc = kfifo_alloc(&dev->raw->kfifo, fifo_size, GFP_KERNEL); + if (rc) + goto out; spin_lock_init(&dev->raw->lock); dev->raw->thread = kthread_run(ir_raw_event_thread, dev->raw, @@ -279,7 +286,7 @@ int ir_raw_event_register(struct rc_dev *dev) if (IS_ERR(dev->raw->thread)) { rc = PTR_ERR(dev->raw->thread); - goto out; + goto out_kfifo; } mutex_lock(&ir_raw_handler_lock); @@ -291,6 +298,8 @@ int ir_raw_event_register(struct rc_dev *dev) return 0; +out_kfifo: + kfifo_free(&dev->raw->kfifo); out: kfree(dev->raw); dev->raw = NULL; @@ -313,6 +322,7 @@ void ir_raw_event_unregister(struct rc_dev *dev) handler->raw_unregister(dev); mutex_unlock(&ir_raw_handler_lock); + kfifo_free(&dev->raw->kfifo); kfree(dev->raw); dev->raw = NULL; } diff --git a/include/media/rc-core.h b/include/media/rc-core.h index f6f55b7..07e096b 100644 --- a/include/media/rc-core.h +++ b/include/media/rc-core.h @@ -72,6 +72,7 @@ enum rc_filter_type { * anyone can call show_protocols or store_protocols * @minor: unique minor remote control device number * @raw: additional data for raw pulse/space devices + * @raw_fifo_size: size of fifo for raw events * @input_dev: the input child device used to communicate events to userspace * @driver_type: specifies if protocol decoding is done in hardware or software * @idle: used to keep track of RX state @@ -133,6 +134,7 @@ struct rc_dev { struct mutex lock; unsigned int minor; struct ir_raw_event_ctrl *raw; + unsigned raw_fifo_size; struct input_dev *input_dev; enum rc_driver_type driver_type; bool idle;