From patchwork Fri Jul 1 08:01:25 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andi Shyti X-Patchwork-Id: 9209445 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 BA51060221 for ; Fri, 1 Jul 2016 08:17:01 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id ABC042868E for ; Fri, 1 Jul 2016 08:17:01 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A040428695; Fri, 1 Jul 2016 08:17:01 +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.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI 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 25BDB2868E for ; Fri, 1 Jul 2016 08:17:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752017AbcGAIQz (ORCPT ); Fri, 1 Jul 2016 04:16:55 -0400 Received: from mailout3.samsung.com ([203.254.224.33]:58268 "EHLO mailout3.samsung.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752018AbcGAIQs (ORCPT ); Fri, 1 Jul 2016 04:16:48 -0400 Received: from epcpsbgr3.samsung.com (u143.gpu120.samsung.co.kr [203.254.230.143]) by mailout3.samsung.com (Oracle Communications Messaging Server 7.0.5.31.0 64bit (built May 5 2014)) with ESMTP id <0O9M027M6MAZ67A0@mailout3.samsung.com>; Fri, 01 Jul 2016 17:01:47 +0900 (KST) Received: from epcpsbgm1new.samsung.com ( [172.20.52.113]) by epcpsbgr3.samsung.com (EPCPMTA) with SMTP id 49.63.05161.B6326775; Fri, 1 Jul 2016 17:01:47 +0900 (KST) X-AuditID: cbfee68f-f79476d000001429-88-5776236b82c3 Received: from epmmp2 ( [203.254.227.17]) by epcpsbgm1new.samsung.com (EPCPMTA) with SMTP id 19.75.02101.A6326775; Fri, 1 Jul 2016 17:01:46 +0900 (KST) Received: from samsunx.samsung ([10.113.63.54]) by mmp2.samsung.com (Oracle Communications Messaging Server 7.0.5.31.0 64bit (built May 5 2014)) with ESMTPA id <0O9M00G9YMAVFJA0@mmp2.samsung.com>; Fri, 01 Jul 2016 17:01:46 +0900 (KST) From: Andi Shyti To: Mauro Carvalho Chehab Cc: Joe Perches , Sean Young , linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, Andi Shyti , Andi Shyti Subject: [PATCH v2 02/15] [media] lirc_dev: allow bufferless driver registration Date: Fri, 01 Jul 2016 17:01:25 +0900 Message-id: <1467360098-12539-3-git-send-email-andi.shyti@samsung.com> X-Mailer: git-send-email 2.8.1 In-reply-to: <1467360098-12539-1-git-send-email-andi.shyti@samsung.com> References: <1467360098-12539-1-git-send-email-andi.shyti@samsung.com> X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFrrDLMWRmVeSWpSXmKPExsWyRsSkUDdbuSzc4MxRFovtR56xWiz+8ZzJ Yvb9xywWl3fNYbPo2bCV1WL1swqLhU+/sziwe1xf8onZY8kba48t/XfZPb6susbs0bdlFaPH 501yAWxRXDYpqTmZZalF+nYJXBnHN5xnLZgtU/H69lfGBsYXYl2MnBwSAiYSi55NZIawxSQu 3FvP1sXIxSEksIJR4uO2d+wwRS8fHGaFSMxilLiyp58RwvnIKLHu/i6wKjYBTYmm2z+A2jk4 RASMJc79UAcJMwscYJTo7XYBCQsLBEis6M8FCbMIqErsuL2XHSTMK+AmsfmoJMQqOYnL0x+w gdicAu4Sd9/tYgSxhYBK5u66xw6yVUJgGbvE/o997BBzBCS+TT7EAjJHQkBWYtMBqF8kJQ6u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oCDSaIr9YM921qnZku/p3v3cf919fFr0v/ PHnGg4lmD09EG916mm/nvjjWRVv2vu3lGYUs1y9+cRGsMKviUn/6/Yr1WR7nqS9WvNp65e3D Nq2nC886HDufbajrPYvhY2JO0JmTzvuOb1lj5lt1XHOSbwGP9qfT3iqJSizFGYmGWsxFxYkA qAYlDLwCAAA= DLP-Filter: Pass X-MTR: 20000000000000000@CPGS X-CFilter-Loop: Reflected 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 Some drivers don't necessarily need to have a FIFO managed buffer for their transfers. Drivers now should call lirc_register_bufferless_driver in order to handle the buffer themselves. The function works exaclty like lirc_register_driver except of the buffer allocation. Signed-off-by: Andi Shyti --- drivers/media/rc/lirc_dev.c | 44 ++++++++++++++++++++++++++++++++++---------- include/media/lirc_dev.h | 12 ++++++++++++ 2 files changed, 46 insertions(+), 10 deletions(-) diff --git a/drivers/media/rc/lirc_dev.c b/drivers/media/rc/lirc_dev.c index 5716978..fa562a3 100644 --- a/drivers/media/rc/lirc_dev.c +++ b/drivers/media/rc/lirc_dev.c @@ -205,12 +205,14 @@ err_out: static int lirc_allocate_buffer(struct irctl *ir) { - int err; + int err = 0; int bytes_in_key; unsigned int chunk_size; unsigned int buffer_size; struct lirc_driver *d = &ir->d; + mutex_lock(&lirc_dev_lock); + bytes_in_key = BITS_TO_LONGS(d->code_length) + (d->code_length % 8 ? 1 : 0); buffer_size = d->buffer_size ? d->buffer_size : BUFLEN / bytes_in_key; @@ -220,21 +222,26 @@ static int lirc_allocate_buffer(struct irctl *ir) ir->buf = d->rbuf; } else { ir->buf = kmalloc(sizeof(struct lirc_buffer), GFP_KERNEL); - if (!ir->buf) - return -ENOMEM; + if (!ir->buf) { + err = -ENOMEM; + goto out; + } err = lirc_buffer_init(ir->buf, chunk_size, buffer_size); if (err) { kfree(ir->buf); - return err; + goto out; } } ir->chunk_size = ir->buf->chunk_size; - return 0; +out: + mutex_unlock(&lirc_dev_lock); + + return err; } -int lirc_register_driver(struct lirc_driver *d) +static int lirc_allocate_driver(struct lirc_driver *d) { struct irctl *ir; int minor; @@ -342,10 +349,6 @@ int lirc_register_driver(struct lirc_driver *d) /* some safety check 8-) */ d->name[sizeof(d->name)-1] = '\0'; - err = lirc_allocate_buffer(ir); - if (err) - goto out_lock; - if (d->features == 0) d->features = LIRC_CAN_REC_LIRCCODE; @@ -385,8 +388,29 @@ out_lock: out: return err; } + +int lirc_register_driver(struct lirc_driver *d) +{ + int err, minor; + + minor = lirc_allocate_driver(d); + if (minor < 0) + return minor; + + err = lirc_allocate_buffer(irctls[minor]); + if (err) + lirc_unregister_driver(minor); + + return err ? err : minor; +} EXPORT_SYMBOL(lirc_register_driver); +int lirc_register_bufferless_driver(struct lirc_driver *d) +{ + return lirc_allocate_driver(d); +} +EXPORT_SYMBOL(lirc_register_bufferless_driver); + int lirc_unregister_driver(int minor) { struct irctl *ir; diff --git a/include/media/lirc_dev.h b/include/media/lirc_dev.h index 0ab59a5..8bed57a 100644 --- a/include/media/lirc_dev.h +++ b/include/media/lirc_dev.h @@ -214,6 +214,18 @@ struct lirc_driver { */ extern int lirc_register_driver(struct lirc_driver *d); +/* int lirc_register_bufferless_driver - allocates a lirc bufferless driver + * @d: reference to the lirc_driver to initialize + * + * The difference between lirc_register_driver and + * lirc_register_bufferless_driver is that the latter doesn't allocate any + * buffer, which means that the driver using the lirc_driver should take care of + * it by itself. + * + * returns 0 on success or a the negative errno number in case of failure. + */ +extern int lirc_register_bufferless_driver(struct lirc_driver *d); + /* returns negative value on error or 0 if success */ extern int lirc_unregister_driver(int minor);