From patchwork Wed Jun 29 13:20:31 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andi Shyti X-Patchwork-Id: 9205103 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 17206607D8 for ; Wed, 29 Jun 2016 13:23:45 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 089D3285BA for ; Wed, 29 Jun 2016 13:23:45 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id F16A928665; Wed, 29 Jun 2016 13:23:44 +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=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 8E780285BA for ; Wed, 29 Jun 2016 13:23:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752539AbcF2NVD (ORCPT ); Wed, 29 Jun 2016 09:21:03 -0400 Received: from mailout1.samsung.com ([203.254.224.24]:57719 "EHLO mailout1.samsung.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752138AbcF2NU7 (ORCPT ); Wed, 29 Jun 2016 09:20:59 -0400 Received: from epcpsbgr3.samsung.com (u143.gpu120.samsung.co.kr [203.254.230.143]) by mailout1.samsung.com (Oracle Communications Messaging Server 7.0.5.31.0 64bit (built May 5 2014)) with ESMTP id <0O9J02CGYBQWFN40@mailout1.samsung.com>; Wed, 29 Jun 2016 22:20:56 +0900 (KST) Received: from epcpsbgm2new.samsung.com ( [172.20.52.113]) by epcpsbgr3.samsung.com (EPCPMTA) with SMTP id 5E.5E.05161.83BC3775; Wed, 29 Jun 2016 22:20:56 +0900 (KST) X-AuditID: cbfee68f-f79476d000001429-18-5773cb388af8 Received: from epmmp1.local.host ( [203.254.227.16]) by epcpsbgm2new.samsung.com (EPCPMTA) with SMTP id D0.6D.04429.83BC3775; Wed, 29 Jun 2016 06:20:56 -0700 (MST) Received: from samsunx.samsung ([10.113.63.54]) by mmp1.samsung.com (Oracle Communications Messaging Server 7.0.5.31.0 64bit (built May 5 2014)) with ESMTPA id <0O9J0087XBQTVM50@mmp1.samsung.com>; Wed, 29 Jun 2016 22:20:56 +0900 (KST) From: Andi Shyti To: Mauro Carvalho Chehab Cc: linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, Andi Shyti , Andi Shyti Subject: [PATCH 02/15] lirc_dev: allow bufferless driver registration Date: Wed, 29 Jun 2016 22:20:31 +0900 Message-id: <1467206444-9935-3-git-send-email-andi.shyti@samsung.com> X-Mailer: git-send-email 2.8.1 In-reply-to: <1467206444-9935-1-git-send-email-andi.shyti@samsung.com> References: <1467206444-9935-1-git-send-email-andi.shyti@samsung.com> X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFjrNLMWRmVeSWpSXmKPExsWyRsSkUNfidHG4wfNvChbbjzxjtVj84zmT xeVdc9gsejZsZbVY/azCgdXj+pJPzB5b+u+ye/RtWcXo8XmTXABLFJdNSmpOZllqkb5dAlfG 8Q3nWQtmy1S8vv2VsYHxhVgXIyeHhICJxO/zb1ggbDGJC/fWs3UxcnEICaxglLi78jgTTNGd w4uYIBJLGSVanm9hhXA+MkpMOvWdDaSKTUBToun2DyCbg0NEwFji3A91kDCzQDOjxO7rRiC2 sICrxKfVs8G2sQioSryccARsAS9QfNXrrYwQy+QkLk9/ADaSU8BNYvn5m+wgthBQTevT/4wg eyUE2tkldh6czAoxSEDi2+RDLCB7JQRkJTYdYIaYIylxcMUNlgmMwgsYGVYxiqYWJBcUJ6UX GesVJ+YWl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au52ZP5yv 5XL8m8gXggf+zzvMfuFtTvrNXTLleVf+/3UQseqYapB9Z4uPzN8t8SslEuUWcuxi2anfv3t5 JHfG7bnzl99KnqB2SqpqYkL57FB9JZbijERDLeai4kQA9Rj/rKsCAAA= 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);