From patchwork Wed May 4 11:20:52 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sakari Ailus X-Patchwork-Id: 9012391 Return-Path: X-Original-To: patchwork-linux-media@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id B51E2BF29F for ; Wed, 4 May 2016 11:24:18 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id D08CD2039D for ; Wed, 4 May 2016 11:24:17 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id C848C2039C for ; Wed, 4 May 2016 11:24:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752403AbcEDLYP (ORCPT ); Wed, 4 May 2016 07:24:15 -0400 Received: from mga11.intel.com ([192.55.52.93]:3545 "EHLO mga11.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752367AbcEDLYO (ORCPT ); Wed, 4 May 2016 07:24:14 -0400 Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by fmsmga102.fm.intel.com with ESMTP; 04 May 2016 04:24:05 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.24,576,1455004800"; d="scan'208";a="958631449" Received: from paasikivi.fi.intel.com ([10.237.72.42]) by fmsmga001.fm.intel.com with ESMTP; 04 May 2016 04:24:04 -0700 Received: from nauris.fi.intel.com (nauris.localdomain [192.168.240.2]) by paasikivi.fi.intel.com (Postfix) with ESMTP id 4A32820CF4; Wed, 4 May 2016 14:24:03 +0300 (EEST) Received: by nauris.fi.intel.com (Postfix, from userid 1000) id D4E42201F3; Wed, 4 May 2016 14:21:05 +0300 (EEST) From: Sakari Ailus To: linux-media@vger.kernel.org Cc: laurent.pinchart@ideasonboard.com, hverkuil@xs4all.nl, mchehab@osg.samsung.com Subject: [PATCH v2 2/5] media: Unify IOCTL handler calling Date: Wed, 4 May 2016 14:20:52 +0300 Message-Id: <1462360855-23354-3-git-send-email-sakari.ailus@linux.intel.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1462360855-23354-1-git-send-email-sakari.ailus@linux.intel.com> References: <1462360855-23354-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=-9.0 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 Each IOCTL handler can be listed in an array instead of using a large and cumbersome switch. Do that. Signed-off-by: Sakari Ailus Reviewed-by: Laurent Pinchart --- drivers/media/media-device.c | 89 ++++++++++++-------------------------------- 1 file changed, 23 insertions(+), 66 deletions(-) diff --git a/drivers/media/media-device.c b/drivers/media/media-device.c index c24149d..9b5a88d 100644 --- a/drivers/media/media-device.c +++ b/drivers/media/media-device.c @@ -419,12 +419,16 @@ static long media_device_get_topology(struct media_device *mdev, return 0; } -#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 __user *))func, \ + } /* the table is indexed by _IOC_NR(cmd) */ struct media_ioctl_info { unsigned int cmd; + long (*fn)(struct media_device *dev, void __user *arg); }; static inline long is_valid_ioctl(const struct media_ioctl_info *info, @@ -440,53 +444,28 @@ static long __media_device_ioctl( { struct media_devnode *devnode = media_devnode_data(filp); struct media_device *dev = to_media_device(devnode); + const struct media_ioctl_info *info; long ret; ret = is_valid_ioctl(info_array, info_array_len, cmd); if (ret) return ret; + info = &info_array[_IOC_NR(cmd)]; + mutex_lock(&dev->graph_mutex); - switch (cmd) { - case MEDIA_IOC_DEVICE_INFO: - ret = media_device_get_info(dev, - (struct media_device_info __user *)arg); - break; - - case MEDIA_IOC_ENUM_ENTITIES: - ret = media_device_enum_entities(dev, - (struct media_entity_desc __user *)arg); - break; - - case MEDIA_IOC_ENUM_LINKS: - ret = media_device_enum_links(dev, - (struct media_links_enum __user *)arg); - break; - - case MEDIA_IOC_SETUP_LINK: - ret = media_device_setup_link(dev, - (struct media_link_desc __user *)arg); - break; - - case MEDIA_IOC_G_TOPOLOGY: - ret = media_device_get_topology(dev, - (struct media_v2_topology __user *)arg); - break; - - default: - ret = -ENOIOCTLCMD; - } + ret = info->fn(dev, arg); mutex_unlock(&dev->graph_mutex); return ret; } static const struct media_ioctl_info 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 long media_device_ioctl(struct file *filp, unsigned int cmd, @@ -528,41 +507,19 @@ static long media_device_enum_links32(struct media_device *mdev, #define MEDIA_IOC_ENUM_LINKS32 _IOWR('|', 0x02, struct media_links_enum32) static const struct media_ioctl_info compat_ioctl_info[] = { - MEDIA_IOC(DEVICE_INFO), - MEDIA_IOC(ENUM_ENTITIES), - MEDIA_IOC(ENUM_LINKS32), - 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_LINKS32, media_device_enum_links32), + MEDIA_IOC(SETUP_LINK, media_device_setup_link), + MEDIA_IOC(G_TOPOLOGY, media_device_get_topology), }; static long media_device_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg) { - struct media_devnode *devnode = media_devnode_data(filp); - struct media_device *dev = to_media_device(devnode); - long ret; - - switch (cmd) { - case MEDIA_IOC_DEVICE_INFO: - case MEDIA_IOC_ENUM_ENTITIES: - case MEDIA_IOC_SETUP_LINK: - case MEDIA_IOC_G_TOPOLOGY: - return __media_device_ioctl( - filp, cmd, (void __user *)arg, - compat_ioctl_info, ARRAY_SIZE(compat_ioctl_info)); - - case MEDIA_IOC_ENUM_LINKS32: - mutex_lock(&dev->graph_mutex); - ret = media_device_enum_links32(dev, - (struct media_links_enum32 __user *)arg); - mutex_unlock(&dev->graph_mutex); - break; - - default: - ret = -ENOIOCTLCMD; - } - - return ret; + return __media_device_ioctl( + filp, cmd, (void __user *)arg, + compat_ioctl_info, ARRAY_SIZE(compat_ioctl_info)); } #endif /* CONFIG_COMPAT */