From patchwork Fri Apr 29 08:43:18 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sakari Ailus X-Patchwork-Id: 8978341 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 EB0F5BF29F for ; Fri, 29 Apr 2016 08:46:39 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 06CD320295 for ; Fri, 29 Apr 2016 08:46:39 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id AF8722026C for ; Fri, 29 Apr 2016 08:46:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752240AbcD2IqX (ORCPT ); Fri, 29 Apr 2016 04:46:23 -0400 Received: from mga11.intel.com ([192.55.52.93]:27598 "EHLO mga11.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751169AbcD2IqW (ORCPT ); Fri, 29 Apr 2016 04:46:22 -0400 Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by fmsmga102.fm.intel.com with ESMTP; 29 Apr 2016 01:46:19 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.24,551,1455004800"; d="scan'208";a="694191639" Received: from paasikivi.fi.intel.com ([10.237.72.42]) by FMSMGA003.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 E5907203D9; Fri, 29 Apr 2016 11:46:16 +0300 (EEST) Received: by nauris.fi.intel.com (Postfix, from userid 1000) id A5F9B200FB; 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 1/3] media: Determine early whether an IOCTL is supported Date: Fri, 29 Apr 2016 11:43:18 +0300 Message-Id: <1461919400-2658-2-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 Preparation for refactoring media IOCTL handling to unify common parts. Signed-off-by: Sakari Ailus --- drivers/media/media-device.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/drivers/media/media-device.c b/drivers/media/media-device.c index 898a3cf..6d3ee5c 100644 --- a/drivers/media/media-device.c +++ b/drivers/media/media-device.c @@ -419,6 +419,20 @@ 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 } + +/* the table is indexed by _IOC_NR(cmd) */ +static struct { + unsigned int cmd; +} media_ioctl_info[] = { + MEDIA_IOC(DEVICE_INFO), + MEDIA_IOC(ENUM_ENTITIES), + MEDIA_IOC(ENUM_LINKS), + MEDIA_IOC(SETUP_LINK), + MEDIA_IOC(G_TOPOLOGY), +}; + static long media_device_ioctl(struct file *filp, unsigned int cmd, unsigned long arg) { @@ -426,6 +440,10 @@ static long media_device_ioctl(struct file *filp, unsigned int cmd, struct media_device *dev = to_media_device(devnode); long ret; + if (_IOC_NR(cmd) >= ARRAY_SIZE(media_ioctl_info) + || media_ioctl_info[_IOC_NR(cmd)].cmd != cmd) + return -ENOIOCTLCMD; + mutex_lock(&dev->graph_mutex); switch (cmd) { case MEDIA_IOC_DEVICE_INFO: