From patchwork Fri Apr 29 08:43:20 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sakari Ailus X-Patchwork-Id: 8978351 Return-Path: X-Original-To: patchwork-linux-media@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id B261D9F54E for ; Fri, 29 Apr 2016 08:46:41 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id DDF6720256 for ; Fri, 29 Apr 2016 08:46:40 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id E91C320270 for ; Fri, 29 Apr 2016 08:46:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752166AbcD2Iqb (ORCPT ); Fri, 29 Apr 2016 04:46:31 -0400 Received: from mga01.intel.com ([192.55.52.88]:20616 "EHLO mga01.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751829AbcD2IqU (ORCPT ); Fri, 29 Apr 2016 04:46:20 -0400 Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by fmsmga101.fm.intel.com with ESMTP; 29 Apr 2016 01:46:20 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.24,551,1455004800"; d="scan'208";a="94153584" Received: from paasikivi.fi.intel.com ([10.237.72.42]) by fmsmga004.fm.intel.com with ESMTP; 29 Apr 2016 01:46:17 -0700 Received: from nauris.fi.intel.com (nauris.localdomain [192.168.240.2]) by paasikivi.fi.intel.com (Postfix) with ESMTP id E71EF21627; Fri, 29 Apr 2016 11:46:16 +0300 (EEST) Received: by nauris.fi.intel.com (Postfix, from userid 1000) id C2BB420206; Fri, 29 Apr 2016 11:43:23 +0300 (EEST) From: Sakari Ailus To: linux-media@vger.kernel.org Cc: mchehab@osg.samsung.com, laurent.pinchart@ideasonboard.com, hverkuil@xs4all.nl Subject: [PATCH 3/3] media: Refactor IOCTL handler calling Date: Fri, 29 Apr 2016 11:43:20 +0300 Message-Id: <1461919400-2658-4-git-send-email-sakari.ailus@linux.intel.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1461919400-2658-1-git-send-email-sakari.ailus@linux.intel.com> References: <1461919400-2658-1-git-send-email-sakari.ailus@linux.intel.com> Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org X-Spam-Status: No, score=-7.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Replace the switch by a nice array of supported IOCTLs, just like in V4L2. Signed-off-by: Sakari Ailus --- drivers/media/media-device.c | 58 +++++++++++++++----------------------------- 1 file changed, 19 insertions(+), 39 deletions(-) diff --git a/drivers/media/media-device.c b/drivers/media/media-device.c index 4a66a2d5..8a4daf9 100644 --- a/drivers/media/media-device.c +++ b/drivers/media/media-device.c @@ -363,18 +363,22 @@ static long media_device_get_topology(struct media_device *mdev, return ret; } -#define MEDIA_IOC(__cmd) \ - [_IOC_NR(MEDIA_IOC_##__cmd)] = { .cmd = MEDIA_IOC_##__cmd } +#define MEDIA_IOC(__cmd, func) \ + [_IOC_NR(MEDIA_IOC_##__cmd)] = { \ + .cmd = MEDIA_IOC_##__cmd, \ + .fn = (long (*)(struct media_device *, void *))func, \ + } /* the table is indexed by _IOC_NR(cmd) */ -static const struct { +static const struct media_ioctl_info { unsigned int cmd; + long (*fn)(struct media_device *dev, void *arg); } media_ioctl_info[] = { - MEDIA_IOC(DEVICE_INFO), - MEDIA_IOC(ENUM_ENTITIES), - MEDIA_IOC(ENUM_LINKS), - MEDIA_IOC(SETUP_LINK), - MEDIA_IOC(G_TOPOLOGY), + MEDIA_IOC(DEVICE_INFO, media_device_get_info), + MEDIA_IOC(ENUM_ENTITIES, media_device_enum_entities), + MEDIA_IOC(ENUM_LINKS, media_device_enum_links), + MEDIA_IOC(SETUP_LINK, media_device_setup_link), + MEDIA_IOC(G_TOPOLOGY, media_device_get_topology), }; static unsigned int media_ioctl_max_arg_size(void) { @@ -395,11 +399,15 @@ static long media_device_ioctl(struct file *filp, unsigned int cmd, { struct media_devnode *devnode = media_devnode_data(filp); struct media_device *dev = to_media_device(devnode); + const struct media_ioctl_info *info; char karg[media_ioctl_max_arg_size()]; long ret; - if (_IOC_NR(cmd) >= ARRAY_SIZE(media_ioctl_info) - || media_ioctl_info[_IOC_NR(cmd)].cmd != cmd) + if (_IOC_NR(cmd) >= ARRAY_SIZE(media_ioctl_info)) + return -ENOIOCTLCMD; + + info = &media_ioctl_info[_IOC_NR(cmd)]; + if (info->cmd != cmd) return -ENOIOCTLCMD; /* All media IOCTLs are _IOWR() */ @@ -407,35 +415,7 @@ static long media_device_ioctl(struct file *filp, unsigned int cmd, return -EFAULT; mutex_lock(&dev->graph_mutex); - switch (cmd) { - case MEDIA_IOC_DEVICE_INFO: - ret = media_device_get_info(dev, - (struct media_device_info *)karg); - break; - - case MEDIA_IOC_ENUM_ENTITIES: - ret = media_device_enum_entities(dev, - (struct media_entity_desc *)karg); - break; - - case MEDIA_IOC_ENUM_LINKS: - ret = media_device_enum_links(dev, - (struct media_links_enum *)karg); - break; - - case MEDIA_IOC_SETUP_LINK: - ret = media_device_setup_link(dev, - (struct media_link_desc *)karg); - break; - - case MEDIA_IOC_G_TOPOLOGY: - ret = media_device_get_topology(dev, - (struct media_v2_topology *)karg); - break; - - default: - ret = -ENOIOCTLCMD; - } + ret = info->fn(dev, karg); mutex_unlock(&dev->graph_mutex); if (!ret && copy_to_user((void *)arg, karg, _IOC_SIZE(cmd)))