From patchwork Wed Jun 29 13:20:30 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andi Shyti X-Patchwork-Id: 9205131 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 A74816075F for ; Wed, 29 Jun 2016 13:25:46 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 98FA5285BA for ; Wed, 29 Jun 2016 13:25:46 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8DEA52860B; Wed, 29 Jun 2016 13:25:46 +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 457E6285BA for ; Wed, 29 Jun 2016 13:25:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752242AbcF2NVA (ORCPT ); Wed, 29 Jun 2016 09:21:00 -0400 Received: from mailout2.samsung.com ([203.254.224.25]:55710 "EHLO mailout2.samsung.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752007AbcF2NU6 (ORCPT ); Wed, 29 Jun 2016 09:20:58 -0400 Received: from epcpsbgr3.samsung.com (u143.gpu120.samsung.co.kr [203.254.230.143]) by mailout2.samsung.com (Oracle Communications Messaging Server 7.0.5.31.0 64bit (built May 5 2014)) with ESMTP id <0O9J00SMGBQWJM20@mailout2.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 FD.5E.05161.83BC3775; Wed, 29 Jun 2016 22:20:56 +0900 (KST) X-AuditID: cbfee68f-f79476d000001429-17-5773cb3828bc Received: from epmmp1.local.host ( [203.254.227.16]) by epcpsbgm2new.samsung.com (EPCPMTA) with SMTP id 70.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 01/15] lirc_dev: place buffer allocation on separate function Date: Wed, 29 Jun 2016 22:20:30 +0900 Message-id: <1467206444-9935-2-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+NgFjrFLMWRmVeSWpSXmKPExsWyRsSkUNfidHG4wcIuaYvtR56xWiz+8ZzJ 4vKuOWwWPRu2slqsflbhwOpxfcknZo8t/XfZPfq2rGL0+LxJLoAlissmJTUnsyy1SN8ugSuj deEC9oLlQhV7T3UxNTCe4eti5OSQEDCR+PDyGBuELSZx4d56IJuLQ0hgBaPE9L497DBFU35M ZoJILGWUmHT7KiOE8xHIOfUdrJ1NQFOi6fYPIJuDQ0TAWOLcD3WQMLNAM6PE7utGILawgK/E nflTmUBsFgFViUffb7CDlPMKuEocOZEKsUtO4vL0B2ATOQXcJJafvwl2gxBQSevT/2BrJQTa 2SX+vVrBAjFHQOLb5EMsIHMkBGQlNh1ghpgjKXFwxQ2WCYzCCxgZVjGKphYkFxQnpRcZ6xUn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G9l3ts3PjwzOHed Lbv4dP2Cgl0nds5X/XVV8YWcsMHG5gN8rbt2LqneI7M2WZIh1fzDjCOXZ/6u+GXD7L2F5eqm ILvP7/9qVdps5Q6qsnrSxKtnvFOJpTgj0VCLuag4EQAgX+uXqgIAAA== 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 During the driver registration, move the buffer allocation on a separate function. Signed-off-by: Andi Shyti --- drivers/media/rc/lirc_dev.c | 57 +++++++++++++++++++++++++++------------------ 1 file changed, 34 insertions(+), 23 deletions(-) diff --git a/drivers/media/rc/lirc_dev.c b/drivers/media/rc/lirc_dev.c index 92ae190..5716978 100644 --- a/drivers/media/rc/lirc_dev.c +++ b/drivers/media/rc/lirc_dev.c @@ -203,13 +203,41 @@ err_out: return retval; } -int lirc_register_driver(struct lirc_driver *d) +static int lirc_allocate_buffer(struct irctl *ir) { - struct irctl *ir; - int minor; + int err; int bytes_in_key; unsigned int chunk_size; unsigned int buffer_size; + struct lirc_driver *d = &ir->d; + + 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; + chunk_size = d->chunk_size ? d->chunk_size : bytes_in_key; + + if (d->rbuf) { + ir->buf = d->rbuf; + } else { + ir->buf = kmalloc(sizeof(struct lirc_buffer), GFP_KERNEL); + if (!ir->buf) + return -ENOMEM; + + err = lirc_buffer_init(ir->buf, chunk_size, buffer_size); + if (err) { + kfree(ir->buf); + return err; + } + } + ir->chunk_size = ir->buf->chunk_size; + + return 0; +} + +int lirc_register_driver(struct lirc_driver *d) +{ + struct irctl *ir; + int minor; int err; if (!d) { @@ -314,26 +342,9 @@ int lirc_register_driver(struct lirc_driver *d) /* some safety check 8-) */ d->name[sizeof(d->name)-1] = '\0'; - 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; - chunk_size = d->chunk_size ? d->chunk_size : bytes_in_key; - - if (d->rbuf) { - ir->buf = d->rbuf; - } else { - ir->buf = kmalloc(sizeof(struct lirc_buffer), GFP_KERNEL); - if (!ir->buf) { - err = -ENOMEM; - goto out_lock; - } - err = lirc_buffer_init(ir->buf, chunk_size, buffer_size); - if (err) { - kfree(ir->buf); - goto out_lock; - } - } - ir->chunk_size = ir->buf->chunk_size; + err = lirc_allocate_buffer(ir); + if (err) + goto out_lock; if (d->features == 0) d->features = LIRC_CAN_REC_LIRCCODE;