From patchwork Wed Jul 6 09:01:13 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andi Shyti X-Patchwork-Id: 9215951 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 A82FE60467 for ; Wed, 6 Jul 2016 09:48:44 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 98BF1287D9 for ; Wed, 6 Jul 2016 09:48:44 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8D80E287DC; Wed, 6 Jul 2016 09:48: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 DF7FD287D9 for ; Wed, 6 Jul 2016 09:48:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753985AbcGFJrV (ORCPT ); Wed, 6 Jul 2016 05:47:21 -0400 Received: from mailout2.samsung.com ([203.254.224.25]:56504 "EHLO mailout2.samsung.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752823AbcGFJn4 (ORCPT ); Wed, 6 Jul 2016 05:43:56 -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 <0O9W01R4Q0D50E60@mailout2.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 F8.69.05161.9D2DC775; Wed, 6 Jul 2016 18:43:53 +0900 (KST) X-AuditID: cbfee68f-f79476d000001429-2d-577cd2d9c97a Received: from epmmp2 ( [203.254.227.17]) by epcpsbgm2new.samsung.com (EPCPMTA) with SMTP id 3A.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:52 +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 01/15] [media] lirc_dev: place buffer allocation on separate function Date: Wed, 06 Jul 2016 18:01:13 +0900 Message-id: <1467795687-10737-2-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+NgFnrBLMWRmVeSWpSXmKPExsWyRsSkQPfmpZpwg9+T+C22H3nGarH4x3Mm i1OTnzFZzL7/mMXi8q45bBY9G7ayWqx+VmGx8Ol3FgcOj+tLPjF7LHlj7bGl/y67x5dV15g9 +rasYvT4vEnO49TXz+wB7FFcNimpOZllqUX6dglcGa0LF7AXLBeq2Huqi6mB8QxfFyMnh4SA icT2V09ZIWwxiQv31rN1MXJxCAmsYJT4sQ3EgSja+ekBI0RiFqPE9Udv2CGcj4wSc65dYwSp YhPQlGi6/QOog4NDRMBY4twPdZAaZoGnjBL7ps5lAqkRFoiS2L32NTuIzSKgKvFjJUScV8BN YtmEjewQ2+QkLk9/ADaHU8Bd4upyJZCwEFDJ/m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NzQwsjY3Mlcd7H /9eFCQmkJ5akZqemFqQWwfQxcXBKNTCmNPGln5my6I+Kb8mFAy+WJTtn58uKzM3U1agx+NX1 7fytrPaUE+7XcydJ39hSYfhMVVvVIqTuwPu4dancZ14t59N6aZ4SltHHbyczZ8I1n/mPP6xS Wp//mInT5cKv1o+BmTNPvrgU7XVZ7kUa/4Fwq5dJRgVx+vdOVwtu2njU2XYKk4xdSqYSS3FG oqEWc1FxIgDeo3PjyAIAAA== 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;