From patchwork Fri Jun 8 19:12:24 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 10455047 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 199EE60318 for ; Fri, 8 Jun 2018 19:12:32 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E4EC9295F7 for ; Fri, 8 Jun 2018 19:12:31 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E1DB229698; Fri, 8 Jun 2018 19:12:31 +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=-7.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI, T_DKIM_INVALID autolearn=ham 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 2534B296FD for ; Fri, 8 Jun 2018 19:12:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752624AbeFHTML (ORCPT ); Fri, 8 Jun 2018 15:12:11 -0400 Received: from perceval.ideasonboard.com ([213.167.242.64]:32836 "EHLO perceval.ideasonboard.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751719AbeFHTML (ORCPT ); Fri, 8 Jun 2018 15:12:11 -0400 Received: from avalon.bb.dnainternet.fi (dfj612ybrt5fhg77mgycy-3.rev.dnainternet.fi [IPv6:2001:14ba:21f5:5b00:2e86:4862:ef6a:2804]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 237B157; Fri, 8 Jun 2018 21:12:10 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1528485130; bh=EbF69cH82WS1HIw5WiCYWx7li27H90WdZhuMUMFiOrU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=rOmhb3Rfb9PG/Pf78vfN73trpSJHgrWeO/kuzc35bPlTowpXMj49eMnk/WRFRdyKk cpDHLQGOO4kv7ooS19PB3aLUmlOnbfrrbNAwhIRWvbRFwPiD0ZbRG+L1zbIq4txUMd TszYeNa7xLrVuzFszO9RHEo6cKs/Uh+HTDU2zoDc= From: Laurent Pinchart To: linux-usb@vger.kernel.org Cc: Joel Pepper , Felipe Balbi , Paul Elder Subject: [PATCH 1/2] usb: gadget: uvc: configfs: add UVCG_FRAME_ATTR_RO Date: Fri, 8 Jun 2018 22:12:24 +0300 Message-Id: <20180608191224.628-1-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.16.4 In-Reply-To: <1819956.5cdldLK3cV@avalon> References: <1819956.5cdldLK3cV@avalon> Sender: linux-usb-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Paul Elder Some attributes of the UVC frame descriptors should be read-only in configfs, such as bFrameIndex. Add a read-only version of UVCG_FRAME_ATTR to achieve this. Signed-off-by: Paul Elder --- drivers/usb/gadget/function/uvc_configfs.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/drivers/usb/gadget/function/uvc_configfs.c b/drivers/usb/gadget/function/uvc_configfs.c index 90de6418209b..0ad6ea57d0b7 100644 --- a/drivers/usb/gadget/function/uvc_configfs.c +++ b/drivers/usb/gadget/function/uvc_configfs.c @@ -1067,6 +1067,30 @@ static struct uvcg_frame *to_uvcg_frame(struct config_item *item) return container_of(item, struct uvcg_frame, item); } +#define UVCG_FRAME_ATTR_RO(cname, aname, to_cpu_endian, to_little_endian, bits) \ +static ssize_t uvcg_frame_##cname##_show(struct config_item *item, char *page)\ +{ \ + struct uvcg_frame *f = to_uvcg_frame(item); \ + struct f_uvc_opts *opts; \ + struct config_item *opts_item; \ + struct mutex *su_mutex = &f->item.ci_group->cg_subsys->su_mutex;\ + int result; \ + \ + mutex_lock(su_mutex); /* for navigating configfs hierarchy */ \ + \ + opts_item = f->item.ci_parent->ci_parent->ci_parent->ci_parent; \ + opts = to_f_uvc_opts(opts_item); \ + \ + mutex_lock(&opts->lock); \ + result = sprintf(page, "%d\n", to_cpu_endian(f->frame.cname)); \ + mutex_unlock(&opts->lock); \ + \ + mutex_unlock(su_mutex); \ + return result; \ +} \ + \ +UVC_ATTR_RO(uvcg_frame_, cname, aname); + #define UVCG_FRAME_ATTR(cname, aname, to_cpu_endian, to_little_endian, bits) \ static ssize_t uvcg_frame_##cname##_show(struct config_item *item, char *page)\ { \