From patchwork Wed Jul 6 09:01:14 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andi Shyti X-Patchwork-Id: 9215937 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 668F060467 for ; Wed, 6 Jul 2016 09:47:16 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 551F9287D6 for ; Wed, 6 Jul 2016 09:47:16 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 46A9B287DA; Wed, 6 Jul 2016 09:47:16 +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 DACE4287D6 for ; Wed, 6 Jul 2016 09:47:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752941AbcGFJn5 (ORCPT ); Wed, 6 Jul 2016 05:43:57 -0400 Received: from mailout4.samsung.com ([203.254.224.34]:46763 "EHLO mailout4.samsung.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752701AbcGFJnz (ORCPT ); Wed, 6 Jul 2016 05:43:55 -0400 Received: from epcpsbgr3.samsung.com (u143.gpu120.samsung.co.kr [203.254.230.143]) by mailout4.samsung.com (Oracle Communications Messaging Server 7.0.5.31.0 64bit (built May 5 2014)) with ESMTP id <0O9W01OE90D52D60@mailout4.samsung.com>; Wed, 06 Jul 2016 18:43:53 +0900 (KST) Received: from epcpsbgm2new.samsung.com ( [172.20.52.112]) by epcpsbgr3.samsung.com (EPCPMTA) with SMTP id 89.69.05161.9D2DC775; Wed, 6 Jul 2016 18:43:53 +0900 (KST) X-AuditID: cbfee68f-f79476d000001429-2f-577cd2d93de8 Received: from epmmp2 ( [203.254.227.17]) by epcpsbgm2new.samsung.com (EPCPMTA) with SMTP id CA.B5.04429.9D2DC775; Wed, 6 Jul 2016 02:43:53 -0700 (MST) 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 <0O9W003BE0D2J600@mmp2.samsung.com>; Wed, 06 Jul 2016 18:43:53 +0900 (KST) From: Andi Shyti To: Mauro Carvalho Chehab Cc: Joe Perches , Sean Young , Hans Verkuil , linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, Andi Shyti , Andi Shyti Subject: [PATCH v3 02/15] [media] lirc_dev: allow bufferless driver registration Date: Wed, 06 Jul 2016 18:01:14 +0900 Message-id: <1467795687-10737-3-git-send-email-andi.shyti@samsung.com> X-Mailer: git-send-email 2.8.1 In-reply-to: <1467795687-10737-1-git-send-email-andi.shyti@samsung.com> References: <1467795687-10737-1-git-send-email-andi.shyti@samsung.com> X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFnrBLMWRmVeSWpSXmKPExsWyRsSkQPfmpZpwg83bxSy2H3nGarH4x3Mm i1OTnzFZzL7/mMXi8q45bBY9G7ayWqx+VmGx8Ol3FgcOj+tLPjF7LHlj7bGl/y67x5dV15g9 +rasYvT4vEnO49TXz+wB7FFcNimpOZllqUX6dglcGZ8OLGUq2Clc8efROZYGxu38XYycHBIC JhLTd7ezQthiEhfurWfrYuTiEBJYwSjx5vkkdpii719fs0AkZjFKbPz2jhnC+cgo8WvZTSaQ KjYBTYmm2z+A2jk4RASMJc79UAepYRZ4yiixb+pcsBphgQCJ24u6wKayCKhK7Lm1nwXE5hVw k/jz+g3UGXISl6c/AJvDKeAucXW5EkhYCKhk/7ab7CAzJQS2sUts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MDI2VxLn ffx/XZiQQHpiSWp2ampBahFMHxMHp1QDY6YBR5K4x788pbdCJ/ezXCjaaam4f8vM2ha/Ce90 F9+b8PeH0MOc4yph00XKBQ4rTpy1YI1ZOcftHUsdbU3/fuFtyT93bNtbtRnKD0/YWFxQqC6/ fXLxK8E8RbPTq7pfX7no2fA2vvdL7ImSX5/S161p9uE4d7f24/NbVWfPrz3SNkMkRUOryEuJ pTgj0VCLuag4EQAj3CfTyAIAAA== 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 Transmitters don't necessarily need to have a FIFO managed buffer for their transfers. When registering the driver, before allocating the buffer, check whether the device is a transmitter or receiver. Allocate the buffer only for receivers. Signed-off-by: Andi Shyti --- drivers/media/rc/lirc_dev.c | 40 ++++++++++++++++++++++++++++++---------- 1 file changed, 30 insertions(+), 10 deletions(-) diff --git a/drivers/media/rc/lirc_dev.c b/drivers/media/rc/lirc_dev.c index 5716978..154e553 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,6 +388,23 @@ out_lock: out: return err; } + +int lirc_register_driver(struct lirc_driver *d) +{ + int minor, err = 0; + + minor = lirc_allocate_driver(d); + if (minor < 0) + return minor; + + if (LIRC_CAN_REC(d->features)) { + err = lirc_allocate_buffer(irctls[minor]); + if (err) + lirc_unregister_driver(minor); + } + + return err ? err : minor; +} EXPORT_SYMBOL(lirc_register_driver); int lirc_unregister_driver(int minor)