From patchwork Wed Aug 1 00:29:02 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 10551583 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id C707113B8 for ; Wed, 1 Aug 2018 00:28:44 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B27E32AFB3 for ; Wed, 1 Aug 2018 00:28:44 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A694B2AFEA; Wed, 1 Aug 2018 00:28: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=-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 74EF12AFB3 for ; Wed, 1 Aug 2018 00:28:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732920AbeHACLc (ORCPT ); Tue, 31 Jul 2018 22:11:32 -0400 Received: from perceval.ideasonboard.com ([213.167.242.64]:33698 "EHLO perceval.ideasonboard.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732892AbeHACLc (ORCPT ); Tue, 31 Jul 2018 22:11:32 -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 66AAB1AB6; Wed, 1 Aug 2018 02:28:37 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1533083318; bh=R/2omJ0cG5chLgQEHp6sB6Wf5VZwweD78r5TI3F/M58=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=mF4B8zkHQX9GUvBEcn/X/kZUZ9oExii2u/sRCr6L0lc6AF0y/mHqI5JHYziEyJFZd yBuOONK3aKNWi3k9k/A66hEtSvY0NmCVE7JVdlHLXP4bc0b6V6/dH4x08uvUpFxm2S B1WPoe2mHBR7BagUrEQ+kGgcwryTykxE+qkyqayk= From: Laurent Pinchart To: linux-usb@vger.kernel.org Cc: Felipe Balbi , Joel Pepper , Kieran Bingham , Andrzej Pietrasiewicz Subject: [PATCH 1/8] usb: gadget: uvc: configfs: Don't wrap groups unnecessarily Date: Wed, 1 Aug 2018 03:29:02 +0300 Message-Id: <20180801002909.2890-2-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.16.4 In-Reply-To: <20180801002909.2890-1-laurent.pinchart@ideasonboard.com> References: <20180801002909.2890-1-laurent.pinchart@ideasonboard.com> 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 Various configfs groups (represented by config_group) as wrapped in structures that they're the only member of. This allows adding other data fields to groups, but is unnecessarily makes the code more complex. Remove the outter structures and use config_group directly to simplify the code. Groups can still be wrapped individually in the future if other data fields need to be added. Signed-off-by: Laurent Pinchart Reviewed-by: Kieran Bingham --- drivers/usb/gadget/function/uvc_configfs.c | 302 +++++++++++------------------ 1 file changed, 117 insertions(+), 185 deletions(-) diff --git a/drivers/usb/gadget/function/uvc_configfs.c b/drivers/usb/gadget/function/uvc_configfs.c index b51f0d278826..1df94b25abe1 100644 --- a/drivers/usb/gadget/function/uvc_configfs.c +++ b/drivers/usb/gadget/function/uvc_configfs.c @@ -162,9 +162,7 @@ static void uvcg_control_header_drop(struct config_group *group, } /* control/header */ -static struct uvcg_control_header_grp { - struct config_group group; -} uvcg_control_header_grp; +static struct config_group uvcg_control_header_grp; static struct configfs_group_operations uvcg_control_header_grp_ops = { .make_item = uvcg_control_header_make, @@ -177,31 +175,22 @@ static const struct config_item_type uvcg_control_header_grp_type = { }; /* control/processing/default */ -static struct uvcg_default_processing { - struct config_group group; -} uvcg_default_processing; - -static inline struct uvcg_default_processing -*to_uvcg_default_processing(struct config_item *item) -{ - return container_of(to_config_group(item), - struct uvcg_default_processing, group); -} +static struct config_group uvcg_default_processing_grp; #define UVCG_DEFAULT_PROCESSING_ATTR(cname, aname, conv) \ static ssize_t uvcg_default_processing_##cname##_show( \ struct config_item *item, char *page) \ { \ - struct uvcg_default_processing *dp = to_uvcg_default_processing(item); \ + struct config_group *group = to_config_group(item); \ struct f_uvc_opts *opts; \ struct config_item *opts_item; \ - struct mutex *su_mutex = &dp->group.cg_subsys->su_mutex; \ + struct mutex *su_mutex = &group->cg_subsys->su_mutex; \ struct uvc_processing_unit_descriptor *pd; \ int result; \ \ mutex_lock(su_mutex); /* for navigating configfs hierarchy */ \ \ - opts_item = dp->group.cg_item.ci_parent->ci_parent->ci_parent; \ + opts_item = group->cg_item.ci_parent->ci_parent->ci_parent; \ opts = to_f_uvc_opts(opts_item); \ pd = &opts->uvc_processing; \ \ @@ -229,17 +218,17 @@ UVCG_DEFAULT_PROCESSING_ATTR(i_processing, iProcessing, identity_conv); static ssize_t uvcg_default_processing_bm_controls_show( struct config_item *item, char *page) { - struct uvcg_default_processing *dp = to_uvcg_default_processing(item); + struct config_group *group = to_config_group(item); struct f_uvc_opts *opts; struct config_item *opts_item; - struct mutex *su_mutex = &dp->group.cg_subsys->su_mutex; + struct mutex *su_mutex = &group->cg_subsys->su_mutex; struct uvc_processing_unit_descriptor *pd; int result, i; char *pg = page; mutex_lock(su_mutex); /* for navigating configfs hierarchy */ - opts_item = dp->group.cg_item.ci_parent->ci_parent->ci_parent; + opts_item = group->cg_item.ci_parent->ci_parent->ci_parent; opts = to_f_uvc_opts(opts_item); pd = &opts->uvc_processing; @@ -274,40 +263,29 @@ static const struct config_item_type uvcg_default_processing_type = { /* struct uvcg_processing {}; */ /* control/processing */ -static struct uvcg_processing_grp { - struct config_group group; -} uvcg_processing_grp; +static struct config_group uvcg_processing_grp; static const struct config_item_type uvcg_processing_grp_type = { .ct_owner = THIS_MODULE, }; /* control/terminal/camera/default */ -static struct uvcg_default_camera { - struct config_group group; -} uvcg_default_camera; - -static inline struct uvcg_default_camera -*to_uvcg_default_camera(struct config_item *item) -{ - return container_of(to_config_group(item), - struct uvcg_default_camera, group); -} +static struct config_group uvcg_default_camera_grp; #define UVCG_DEFAULT_CAMERA_ATTR(cname, aname, conv) \ static ssize_t uvcg_default_camera_##cname##_show( \ struct config_item *item, char *page) \ { \ - struct uvcg_default_camera *dc = to_uvcg_default_camera(item); \ + struct config_group *group = to_config_group(item); \ struct f_uvc_opts *opts; \ struct config_item *opts_item; \ - struct mutex *su_mutex = &dc->group.cg_subsys->su_mutex; \ + struct mutex *su_mutex = &group->cg_subsys->su_mutex; \ struct uvc_camera_terminal_descriptor *cd; \ int result; \ \ mutex_lock(su_mutex); /* for navigating configfs hierarchy */ \ \ - opts_item = dc->group.cg_item.ci_parent->ci_parent->ci_parent-> \ + opts_item = group->cg_item.ci_parent->ci_parent->ci_parent-> \ ci_parent; \ opts = to_f_uvc_opts(opts_item); \ cd = &opts->uvc_camera_terminal; \ @@ -343,17 +321,17 @@ UVCG_DEFAULT_CAMERA_ATTR(w_ocular_focal_length, wOcularFocalLength, static ssize_t uvcg_default_camera_bm_controls_show( struct config_item *item, char *page) { - struct uvcg_default_camera *dc = to_uvcg_default_camera(item); + struct config_group *group = to_config_group(item); struct f_uvc_opts *opts; struct config_item *opts_item; - struct mutex *su_mutex = &dc->group.cg_subsys->su_mutex; + struct mutex *su_mutex = &group->cg_subsys->su_mutex; struct uvc_camera_terminal_descriptor *cd; int result, i; char *pg = page; mutex_lock(su_mutex); /* for navigating configfs hierarchy */ - opts_item = dc->group.cg_item.ci_parent->ci_parent->ci_parent-> + opts_item = group->cg_item.ci_parent->ci_parent->ci_parent-> ci_parent; opts = to_f_uvc_opts(opts_item); cd = &opts->uvc_camera_terminal; @@ -391,40 +369,29 @@ static const struct config_item_type uvcg_default_camera_type = { /* struct uvcg_camera {}; */ /* control/terminal/camera */ -static struct uvcg_camera_grp { - struct config_group group; -} uvcg_camera_grp; +static struct config_group uvcg_camera_grp; static const struct config_item_type uvcg_camera_grp_type = { .ct_owner = THIS_MODULE, }; /* control/terminal/output/default */ -static struct uvcg_default_output { - struct config_group group; -} uvcg_default_output; - -static inline struct uvcg_default_output -*to_uvcg_default_output(struct config_item *item) -{ - return container_of(to_config_group(item), - struct uvcg_default_output, group); -} +static struct config_group uvcg_default_output_grp; #define UVCG_DEFAULT_OUTPUT_ATTR(cname, aname, conv) \ static ssize_t uvcg_default_output_##cname##_show( \ - struct config_item *item, char *page) \ + struct config_item *item, char *page) \ { \ - struct uvcg_default_output *dout = to_uvcg_default_output(item); \ + struct config_group *group = to_config_group(item); \ struct f_uvc_opts *opts; \ struct config_item *opts_item; \ - struct mutex *su_mutex = &dout->group.cg_subsys->su_mutex; \ + struct mutex *su_mutex = &group->cg_subsys->su_mutex; \ struct uvc_output_terminal_descriptor *cd; \ int result; \ \ mutex_lock(su_mutex); /* for navigating configfs hierarchy */ \ \ - opts_item = dout->group.cg_item.ci_parent->ci_parent-> \ + opts_item = group->cg_item.ci_parent->ci_parent-> \ ci_parent->ci_parent; \ opts = to_f_uvc_opts(opts_item); \ cd = &opts->uvc_output_terminal; \ @@ -469,39 +436,32 @@ static const struct config_item_type uvcg_default_output_type = { /* struct uvcg_output {}; */ /* control/terminal/output */ -static struct uvcg_output_grp { - struct config_group group; -} uvcg_output_grp; +static struct config_group uvcg_output_grp; static const struct config_item_type uvcg_output_grp_type = { .ct_owner = THIS_MODULE, }; /* control/terminal */ -static struct uvcg_terminal_grp { - struct config_group group; -} uvcg_terminal_grp; +static struct config_group uvcg_terminal_grp; static const struct config_item_type uvcg_terminal_grp_type = { .ct_owner = THIS_MODULE, }; /* control/class/{fs} */ -static struct uvcg_control_class { - struct config_group group; -} uvcg_control_class_fs, uvcg_control_class_ss; - +static struct config_group uvcg_control_class_fs_grp; +static struct config_group uvcg_control_class_ss_grp; static inline struct uvc_descriptor_header **uvcg_get_ctl_class_arr(struct config_item *i, struct f_uvc_opts *o) { - struct uvcg_control_class *cl = container_of(to_config_group(i), - struct uvcg_control_class, group); + struct config_group *group = to_config_group(i); - if (cl == &uvcg_control_class_fs) + if (group == &uvcg_control_class_fs_grp) return o->uvc_fs_control_cls; - if (cl == &uvcg_control_class_ss) + if (group == &uvcg_control_class_ss_grp) return o->uvc_ss_control_cls; return NULL; @@ -593,36 +553,28 @@ static const struct config_item_type uvcg_control_class_type = { }; /* control/class */ -static struct uvcg_control_class_grp { - struct config_group group; -} uvcg_control_class_grp; +static struct config_group uvcg_control_class_grp; static const struct config_item_type uvcg_control_class_grp_type = { .ct_owner = THIS_MODULE, }; /* control */ -static struct uvcg_control_grp { - struct config_group group; -} uvcg_control_grp; +static struct config_group uvcg_control_grp; static const struct config_item_type uvcg_control_grp_type = { .ct_owner = THIS_MODULE, }; /* streaming/uncompressed */ -static struct uvcg_uncompressed_grp { - struct config_group group; -} uvcg_uncompressed_grp; +static struct config_group uvcg_uncompressed_grp; /* streaming/mjpeg */ -static struct uvcg_mjpeg_grp { - struct config_group group; -} uvcg_mjpeg_grp; +static struct config_group uvcg_mjpeg_grp; static struct config_item *fmt_parent[] = { - &uvcg_uncompressed_grp.group.cg_item, - &uvcg_mjpeg_grp.group.cg_item, + &uvcg_uncompressed_grp.cg_item, + &uvcg_mjpeg_grp.cg_item, }; enum uvcg_format_type { @@ -893,9 +845,7 @@ static void uvcg_streaming_header_drop(struct config_group *group, } /* streaming/header */ -static struct uvcg_streaming_header_grp { - struct config_group group; -} uvcg_streaming_header_grp; +static struct config_group uvcg_streaming_header_grp; static struct configfs_group_operations uvcg_streaming_header_grp_ops = { .make_item = uvcg_streaming_header_make, @@ -1670,32 +1620,22 @@ static const struct config_item_type uvcg_mjpeg_grp_type = { }; /* streaming/color_matching/default */ -static struct uvcg_default_color_matching { - struct config_group group; -} uvcg_default_color_matching; - -static inline struct uvcg_default_color_matching -*to_uvcg_default_color_matching(struct config_item *item) -{ - return container_of(to_config_group(item), - struct uvcg_default_color_matching, group); -} +static struct config_group uvcg_default_color_matching_grp; #define UVCG_DEFAULT_COLOR_MATCHING_ATTR(cname, aname, conv) \ static ssize_t uvcg_default_color_matching_##cname##_show( \ - struct config_item *item, char *page) \ + struct config_item *item, char *page) \ { \ - struct uvcg_default_color_matching *dc = \ - to_uvcg_default_color_matching(item); \ + struct config_group *group = to_config_group(item); \ struct f_uvc_opts *opts; \ struct config_item *opts_item; \ - struct mutex *su_mutex = &dc->group.cg_subsys->su_mutex; \ + struct mutex *su_mutex = &group->cg_subsys->su_mutex; \ struct uvc_color_matching_descriptor *cd; \ int result; \ \ mutex_lock(su_mutex); /* for navigating configfs hierarchy */ \ \ - opts_item = dc->group.cg_item.ci_parent->ci_parent->ci_parent; \ + opts_item = group->cg_item.ci_parent->ci_parent->ci_parent; \ opts = to_f_uvc_opts(opts_item); \ cd = &opts->uvc_color_matching; \ \ @@ -1737,33 +1677,29 @@ static const struct config_item_type uvcg_default_color_matching_type = { /* struct uvcg_color_matching {}; */ /* streaming/color_matching */ -static struct uvcg_color_matching_grp { - struct config_group group; -} uvcg_color_matching_grp; +static struct config_group uvcg_color_matching_grp; static const struct config_item_type uvcg_color_matching_grp_type = { .ct_owner = THIS_MODULE, }; /* streaming/class/{fs|hs|ss} */ -static struct uvcg_streaming_class { - struct config_group group; -} uvcg_streaming_class_fs, uvcg_streaming_class_hs, uvcg_streaming_class_ss; - +static struct config_group uvcg_streaming_class_fs_grp; +static struct config_group uvcg_streaming_class_hs_grp; +static struct config_group uvcg_streaming_class_ss_grp; static inline struct uvc_descriptor_header ***__uvcg_get_stream_class_arr(struct config_item *i, struct f_uvc_opts *o) { - struct uvcg_streaming_class *cl = container_of(to_config_group(i), - struct uvcg_streaming_class, group); + struct config_group *group = to_config_group(i); - if (cl == &uvcg_streaming_class_fs) + if (group == &uvcg_streaming_class_fs_grp) return &o->uvc_fs_streaming_cls; - if (cl == &uvcg_streaming_class_hs) + if (group == &uvcg_streaming_class_hs_grp) return &o->uvc_hs_streaming_cls; - if (cl == &uvcg_streaming_class_ss) + if (group == &uvcg_streaming_class_ss_grp) return &o->uvc_ss_streaming_cls; return NULL; @@ -2092,18 +2028,14 @@ static const struct config_item_type uvcg_streaming_class_type = { }; /* streaming/class */ -static struct uvcg_streaming_class_grp { - struct config_group group; -} uvcg_streaming_class_grp; +static struct config_group uvcg_streaming_class_grp; static const struct config_item_type uvcg_streaming_class_grp_type = { .ct_owner = THIS_MODULE, }; /* streaming */ -static struct uvcg_streaming_grp { - struct config_group group; -} uvcg_streaming_grp; +static struct config_group uvcg_streaming_grp; static const struct config_item_type uvcg_streaming_grp_type = { .ct_owner = THIS_MODULE, @@ -2193,114 +2125,114 @@ static const struct config_item_type uvc_func_type = { int uvcg_attach_configfs(struct f_uvc_opts *opts) { - config_group_init_type_name(&uvcg_control_header_grp.group, + config_group_init_type_name(&uvcg_control_header_grp, "header", &uvcg_control_header_grp_type); - config_group_init_type_name(&uvcg_default_processing.group, + config_group_init_type_name(&uvcg_default_processing_grp, "default", &uvcg_default_processing_type); - config_group_init_type_name(&uvcg_processing_grp.group, + config_group_init_type_name(&uvcg_processing_grp, "processing", &uvcg_processing_grp_type); - configfs_add_default_group(&uvcg_default_processing.group, - &uvcg_processing_grp.group); + configfs_add_default_group(&uvcg_default_processing_grp, + &uvcg_processing_grp); - config_group_init_type_name(&uvcg_default_camera.group, + config_group_init_type_name(&uvcg_default_camera_grp, "default", &uvcg_default_camera_type); - config_group_init_type_name(&uvcg_camera_grp.group, + config_group_init_type_name(&uvcg_camera_grp, "camera", &uvcg_camera_grp_type); - configfs_add_default_group(&uvcg_default_camera.group, - &uvcg_camera_grp.group); + configfs_add_default_group(&uvcg_default_camera_grp, + &uvcg_camera_grp); - config_group_init_type_name(&uvcg_default_output.group, + config_group_init_type_name(&uvcg_default_output_grp, "default", &uvcg_default_output_type); - config_group_init_type_name(&uvcg_output_grp.group, + config_group_init_type_name(&uvcg_output_grp, "output", &uvcg_output_grp_type); - configfs_add_default_group(&uvcg_default_output.group, - &uvcg_output_grp.group); + configfs_add_default_group(&uvcg_default_output_grp, + &uvcg_output_grp); - config_group_init_type_name(&uvcg_terminal_grp.group, + config_group_init_type_name(&uvcg_terminal_grp, "terminal", &uvcg_terminal_grp_type); - configfs_add_default_group(&uvcg_camera_grp.group, - &uvcg_terminal_grp.group); - configfs_add_default_group(&uvcg_output_grp.group, - &uvcg_terminal_grp.group); + configfs_add_default_group(&uvcg_camera_grp, + &uvcg_terminal_grp); + configfs_add_default_group(&uvcg_output_grp, + &uvcg_terminal_grp); - config_group_init_type_name(&uvcg_control_class_fs.group, + config_group_init_type_name(&uvcg_control_class_fs_grp, "fs", &uvcg_control_class_type); - config_group_init_type_name(&uvcg_control_class_ss.group, + config_group_init_type_name(&uvcg_control_class_ss_grp, "ss", &uvcg_control_class_type); - config_group_init_type_name(&uvcg_control_class_grp.group, + config_group_init_type_name(&uvcg_control_class_grp, "class", &uvcg_control_class_grp_type); - configfs_add_default_group(&uvcg_control_class_fs.group, - &uvcg_control_class_grp.group); - configfs_add_default_group(&uvcg_control_class_ss.group, - &uvcg_control_class_grp.group); + configfs_add_default_group(&uvcg_control_class_fs_grp, + &uvcg_control_class_grp); + configfs_add_default_group(&uvcg_control_class_ss_grp, + &uvcg_control_class_grp); - config_group_init_type_name(&uvcg_control_grp.group, + config_group_init_type_name(&uvcg_control_grp, "control", &uvcg_control_grp_type); - configfs_add_default_group(&uvcg_control_header_grp.group, - &uvcg_control_grp.group); - configfs_add_default_group(&uvcg_processing_grp.group, - &uvcg_control_grp.group); - configfs_add_default_group(&uvcg_terminal_grp.group, - &uvcg_control_grp.group); - configfs_add_default_group(&uvcg_control_class_grp.group, - &uvcg_control_grp.group); - - config_group_init_type_name(&uvcg_streaming_header_grp.group, + configfs_add_default_group(&uvcg_control_header_grp, + &uvcg_control_grp); + configfs_add_default_group(&uvcg_processing_grp, + &uvcg_control_grp); + configfs_add_default_group(&uvcg_terminal_grp, + &uvcg_control_grp); + configfs_add_default_group(&uvcg_control_class_grp, + &uvcg_control_grp); + + config_group_init_type_name(&uvcg_streaming_header_grp, "header", &uvcg_streaming_header_grp_type); - config_group_init_type_name(&uvcg_uncompressed_grp.group, + config_group_init_type_name(&uvcg_uncompressed_grp, "uncompressed", &uvcg_uncompressed_grp_type); - config_group_init_type_name(&uvcg_mjpeg_grp.group, + config_group_init_type_name(&uvcg_mjpeg_grp, "mjpeg", &uvcg_mjpeg_grp_type); - config_group_init_type_name(&uvcg_default_color_matching.group, + config_group_init_type_name(&uvcg_default_color_matching_grp, "default", &uvcg_default_color_matching_type); - config_group_init_type_name(&uvcg_color_matching_grp.group, + config_group_init_type_name(&uvcg_color_matching_grp, "color_matching", &uvcg_color_matching_grp_type); - configfs_add_default_group(&uvcg_default_color_matching.group, - &uvcg_color_matching_grp.group); + configfs_add_default_group(&uvcg_default_color_matching_grp, + &uvcg_color_matching_grp); - config_group_init_type_name(&uvcg_streaming_class_fs.group, + config_group_init_type_name(&uvcg_streaming_class_fs_grp, "fs", &uvcg_streaming_class_type); - config_group_init_type_name(&uvcg_streaming_class_hs.group, + config_group_init_type_name(&uvcg_streaming_class_hs_grp, "hs", &uvcg_streaming_class_type); - config_group_init_type_name(&uvcg_streaming_class_ss.group, + config_group_init_type_name(&uvcg_streaming_class_ss_grp, "ss", &uvcg_streaming_class_type); - config_group_init_type_name(&uvcg_streaming_class_grp.group, + config_group_init_type_name(&uvcg_streaming_class_grp, "class", &uvcg_streaming_class_grp_type); - configfs_add_default_group(&uvcg_streaming_class_fs.group, - &uvcg_streaming_class_grp.group); - configfs_add_default_group(&uvcg_streaming_class_hs.group, - &uvcg_streaming_class_grp.group); - configfs_add_default_group(&uvcg_streaming_class_ss.group, - &uvcg_streaming_class_grp.group); - - config_group_init_type_name(&uvcg_streaming_grp.group, + configfs_add_default_group(&uvcg_streaming_class_fs_grp, + &uvcg_streaming_class_grp); + configfs_add_default_group(&uvcg_streaming_class_hs_grp, + &uvcg_streaming_class_grp); + configfs_add_default_group(&uvcg_streaming_class_ss_grp, + &uvcg_streaming_class_grp); + + config_group_init_type_name(&uvcg_streaming_grp, "streaming", &uvcg_streaming_grp_type); - configfs_add_default_group(&uvcg_streaming_header_grp.group, - &uvcg_streaming_grp.group); - configfs_add_default_group(&uvcg_uncompressed_grp.group, - &uvcg_streaming_grp.group); - configfs_add_default_group(&uvcg_mjpeg_grp.group, - &uvcg_streaming_grp.group); - configfs_add_default_group(&uvcg_color_matching_grp.group, - &uvcg_streaming_grp.group); - configfs_add_default_group(&uvcg_streaming_class_grp.group, - &uvcg_streaming_grp.group); + configfs_add_default_group(&uvcg_streaming_header_grp, + &uvcg_streaming_grp); + configfs_add_default_group(&uvcg_uncompressed_grp, + &uvcg_streaming_grp); + configfs_add_default_group(&uvcg_mjpeg_grp, + &uvcg_streaming_grp); + configfs_add_default_group(&uvcg_color_matching_grp, + &uvcg_streaming_grp); + configfs_add_default_group(&uvcg_streaming_class_grp, + &uvcg_streaming_grp); config_group_init_type_name(&opts->func_inst.group, "", &uvc_func_type); - configfs_add_default_group(&uvcg_control_grp.group, + configfs_add_default_group(&uvcg_control_grp, &opts->func_inst.group); - configfs_add_default_group(&uvcg_streaming_grp.group, + configfs_add_default_group(&uvcg_streaming_grp, &opts->func_inst.group); return 0; From patchwork Wed Aug 1 00:29:03 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 10551581 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 3C1001708 for ; Wed, 1 Aug 2018 00:28:43 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2BB7C2AFB3 for ; Wed, 1 Aug 2018 00:28:43 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1FEA72AFEA; Wed, 1 Aug 2018 00:28:43 +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 731DC2AFB3 for ; Wed, 1 Aug 2018 00:28:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732918AbeHACLb (ORCPT ); Tue, 31 Jul 2018 22:11:31 -0400 Received: from perceval.ideasonboard.com ([213.167.242.64]:33704 "EHLO perceval.ideasonboard.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732880AbeHACLb (ORCPT ); Tue, 31 Jul 2018 22:11:31 -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 6A6ED1AB8; Wed, 1 Aug 2018 02:28:38 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1533083318; bh=Vnh+qWm20QFvZO1cnIKpeuLn7Rad59efvz5oTI7fWZw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=L/u9SHzZQvDnVVDYaXyd/ZZ8MgLUOhGwtNsn+FfT8SSLyRCW/RPqezGDdEaZ2YiYD uqfNhfWz5lNYEYgC9Bj53CLLvLRR1sW8Frf5mcBsCqDDA8o2AfAFHK2Iyrp7DI/olX juXugnp/cohC4ipDyi3ie6/4WzT7aZbuuIZYBIaA= From: Laurent Pinchart To: linux-usb@vger.kernel.org Cc: Felipe Balbi , Joel Pepper , Kieran Bingham , Andrzej Pietrasiewicz Subject: [PATCH 2/8] usb: gadget: uvc: configfs: Add section header comments Date: Wed, 1 Aug 2018 03:29:03 +0300 Message-Id: <20180801002909.2890-3-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.16.4 In-Reply-To: <20180801002909.2890-1-laurent.pinchart@ideasonboard.com> References: <20180801002909.2890-1-laurent.pinchart@ideasonboard.com> 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 The UVC configfs implementation is large and difficult to navigate. Add a bit more air to the code to make it easier to read. Signed-off-by: Laurent Pinchart Acked-by: Kieran Bingham --- drivers/usb/gadget/function/uvc_configfs.c | 120 ++++++++++++++++++++++------- 1 file changed, 91 insertions(+), 29 deletions(-) diff --git a/drivers/usb/gadget/function/uvc_configfs.c b/drivers/usb/gadget/function/uvc_configfs.c index 1df94b25abe1..dbc95c9558de 100644 --- a/drivers/usb/gadget/function/uvc_configfs.c +++ b/drivers/usb/gadget/function/uvc_configfs.c @@ -12,6 +12,10 @@ #include "u_uvc.h" #include "uvc_configfs.h" +/* ----------------------------------------------------------------------------- + * Global Utility Structures and Macros + */ + #define UVCG_STREAMING_CONTROL_SIZE 1 #define UVC_ATTR(prefix, cname, aname) \ @@ -37,7 +41,11 @@ static inline struct f_uvc_opts *to_f_uvc_opts(struct config_item *item) func_inst.group); } -/* control/header/ */ +/* ----------------------------------------------------------------------------- + * control/header/ + * control/header + */ + DECLARE_UVC_HEADER_DESCRIPTOR(1); struct uvcg_control_header { @@ -161,7 +169,6 @@ static void uvcg_control_header_drop(struct config_group *group, kfree(h); } -/* control/header */ static struct config_group uvcg_control_header_grp; static struct configfs_group_operations uvcg_control_header_grp_ops = { @@ -174,7 +181,10 @@ static const struct config_item_type uvcg_control_header_grp_type = { .ct_owner = THIS_MODULE, }; -/* control/processing/default */ +/* ----------------------------------------------------------------------------- + * control/processing/default + */ + static struct config_group uvcg_default_processing_grp; #define UVCG_DEFAULT_PROCESSING_ATTR(cname, aname, conv) \ @@ -260,16 +270,20 @@ static const struct config_item_type uvcg_default_processing_type = { .ct_owner = THIS_MODULE, }; -/* struct uvcg_processing {}; */ +/* ----------------------------------------------------------------------------- + * control/processing + */ -/* control/processing */ static struct config_group uvcg_processing_grp; static const struct config_item_type uvcg_processing_grp_type = { .ct_owner = THIS_MODULE, }; -/* control/terminal/camera/default */ +/* ----------------------------------------------------------------------------- + * control/terminal/camera/default + */ + static struct config_group uvcg_default_camera_grp; #define UVCG_DEFAULT_CAMERA_ATTR(cname, aname, conv) \ @@ -366,16 +380,20 @@ static const struct config_item_type uvcg_default_camera_type = { .ct_owner = THIS_MODULE, }; -/* struct uvcg_camera {}; */ +/* ----------------------------------------------------------------------------- + * control/terminal/camera + */ -/* control/terminal/camera */ static struct config_group uvcg_camera_grp; static const struct config_item_type uvcg_camera_grp_type = { .ct_owner = THIS_MODULE, }; -/* control/terminal/output/default */ +/* ----------------------------------------------------------------------------- + * control/terminal/output/default + */ + static struct config_group uvcg_default_output_grp; #define UVCG_DEFAULT_OUTPUT_ATTR(cname, aname, conv) \ @@ -433,23 +451,30 @@ static const struct config_item_type uvcg_default_output_type = { .ct_owner = THIS_MODULE, }; -/* struct uvcg_output {}; */ +/* ----------------------------------------------------------------------------- + * control/terminal/output + */ -/* control/terminal/output */ static struct config_group uvcg_output_grp; static const struct config_item_type uvcg_output_grp_type = { .ct_owner = THIS_MODULE, }; -/* control/terminal */ +/* ----------------------------------------------------------------------------- + * control/terminal + */ + static struct config_group uvcg_terminal_grp; static const struct config_item_type uvcg_terminal_grp_type = { .ct_owner = THIS_MODULE, }; -/* control/class/{fs} */ +/* ----------------------------------------------------------------------------- + * control/class/{fs|ss} + */ + static struct config_group uvcg_control_class_fs_grp; static struct config_group uvcg_control_class_ss_grp; @@ -552,24 +577,32 @@ static const struct config_item_type uvcg_control_class_type = { .ct_owner = THIS_MODULE, }; -/* control/class */ +/* ----------------------------------------------------------------------------- + * control/class + */ + static struct config_group uvcg_control_class_grp; static const struct config_item_type uvcg_control_class_grp_type = { .ct_owner = THIS_MODULE, }; -/* control */ +/* ----------------------------------------------------------------------------- + * control + */ + static struct config_group uvcg_control_grp; static const struct config_item_type uvcg_control_grp_type = { .ct_owner = THIS_MODULE, }; -/* streaming/uncompressed */ -static struct config_group uvcg_uncompressed_grp; +/* ----------------------------------------------------------------------------- + * streaming/uncompressed + * streaming/mjpeg + */ -/* streaming/mjpeg */ +static struct config_group uvcg_uncompressed_grp; static struct config_group uvcg_mjpeg_grp; static struct config_item *fmt_parent[] = { @@ -658,7 +691,11 @@ struct uvcg_format_ptr { struct list_head entry; }; -/* streaming/header/ */ +/* ----------------------------------------------------------------------------- + * streaming/header/ + * streaming/header + */ + struct uvcg_streaming_header { struct config_item item; struct uvc_input_header_descriptor desc; @@ -844,7 +881,6 @@ static void uvcg_streaming_header_drop(struct config_group *group, kfree(h); } -/* streaming/header */ static struct config_group uvcg_streaming_header_grp; static struct configfs_group_operations uvcg_streaming_header_grp_ops = { @@ -857,7 +893,10 @@ static const struct config_item_type uvcg_streaming_header_grp_type = { .ct_owner = THIS_MODULE, }; -/* streaming/// */ +/* ----------------------------------------------------------------------------- + * streaming/// + */ + struct uvcg_frame { struct { u8 b_length; @@ -1168,7 +1207,10 @@ static void uvcg_frame_drop(struct config_group *group, struct config_item *item mutex_unlock(&opts->lock); } -/* streaming/uncompressed/ */ +/* ----------------------------------------------------------------------------- + * streaming/uncompressed/ + */ + struct uvcg_uncompressed { struct uvcg_format fmt; struct uvc_format_uncompressed desc; @@ -1425,7 +1467,10 @@ static const struct config_item_type uvcg_uncompressed_grp_type = { .ct_owner = THIS_MODULE, }; -/* streaming/mjpeg/ */ +/* ----------------------------------------------------------------------------- + * streaming/mjpeg/ + */ + struct uvcg_mjpeg { struct uvcg_format fmt; struct uvc_format_mjpeg desc; @@ -1619,7 +1664,10 @@ static const struct config_item_type uvcg_mjpeg_grp_type = { .ct_owner = THIS_MODULE, }; -/* streaming/color_matching/default */ +/* ----------------------------------------------------------------------------- + * streaming/color_matching/default + */ + static struct config_group uvcg_default_color_matching_grp; #define UVCG_DEFAULT_COLOR_MATCHING_ATTR(cname, aname, conv) \ @@ -1674,16 +1722,20 @@ static const struct config_item_type uvcg_default_color_matching_type = { .ct_owner = THIS_MODULE, }; -/* struct uvcg_color_matching {}; */ +/* ----------------------------------------------------------------------------- + * streaming/color_matching + */ -/* streaming/color_matching */ static struct config_group uvcg_color_matching_grp; static const struct config_item_type uvcg_color_matching_grp_type = { .ct_owner = THIS_MODULE, }; -/* streaming/class/{fs|hs|ss} */ +/* ----------------------------------------------------------------------------- + * streaming/class/{fs|hs|ss} + */ + static struct config_group uvcg_streaming_class_fs_grp; static struct config_group uvcg_streaming_class_hs_grp; static struct config_group uvcg_streaming_class_ss_grp; @@ -2027,20 +2079,30 @@ static const struct config_item_type uvcg_streaming_class_type = { .ct_owner = THIS_MODULE, }; -/* streaming/class */ +/* ----------------------------------------------------------------------------- + * streaming/class + */ + static struct config_group uvcg_streaming_class_grp; static const struct config_item_type uvcg_streaming_class_grp_type = { .ct_owner = THIS_MODULE, }; -/* streaming */ +/* ----------------------------------------------------------------------------- + * streaming + */ + static struct config_group uvcg_streaming_grp; static const struct config_item_type uvcg_streaming_grp_type = { .ct_owner = THIS_MODULE, }; +/* ----------------------------------------------------------------------------- + * UVC function + */ + static void uvc_attr_release(struct config_item *item) { struct f_uvc_opts *opts = to_f_uvc_opts(item); From patchwork Wed Aug 1 00:29:04 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 10551591 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 5A30A13B8 for ; Wed, 1 Aug 2018 00:28:50 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 484882AFB3 for ; Wed, 1 Aug 2018 00:28:50 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3C18C2AFDF; Wed, 1 Aug 2018 00:28:50 +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 EE0292AFEA for ; Wed, 1 Aug 2018 00:28:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732926AbeHACLh (ORCPT ); Tue, 31 Jul 2018 22:11:37 -0400 Received: from perceval.ideasonboard.com ([213.167.242.64]:33704 "EHLO perceval.ideasonboard.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732880AbeHACLh (ORCPT ); Tue, 31 Jul 2018 22:11:37 -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 138451ABC; Wed, 1 Aug 2018 02:28:39 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1533083320; bh=RaIWs9UbcpjvNxyHYjfb0FjZdoMb7W+J/TXBylACvF0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=R9u9V7BEQC/WcD+c3xJhOGxDiNBxOQC4qCyU/10XKiOtOeNw6wtc27vkowhdt3ri4 7h2jNBCtnkcXxPIQFtDjx/HApdF+MXU+9xWlz/l99pSZl2DrAQRgK+MFUdqWbgZfj0 BBw9PTGJ5DPwLuIRNhCutG8c7IoGnkJlrDQlYzPI= From: Laurent Pinchart To: linux-usb@vger.kernel.org Cc: Felipe Balbi , Joel Pepper , Kieran Bingham , Andrzej Pietrasiewicz Subject: [PATCH 3/8] usb: gadget: uvc: configfs: Allocate groups dynamically Date: Wed, 1 Aug 2018 03:29:04 +0300 Message-Id: <20180801002909.2890-4-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.16.4 In-Reply-To: <20180801002909.2890-1-laurent.pinchart@ideasonboard.com> References: <20180801002909.2890-1-laurent.pinchart@ideasonboard.com> 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 The UVC configfs implementation creates all groups as global static variables. This prevents creationg of multiple UVC function instances, as they would all require their own configfs group instances. Fix this by allocating all groups dynamically. To avoid duplicating code around, extend the config_item_type structure with group name and children, and implement helper functions to create children automatically for most groups. Signed-off-by: Laurent Pinchart --- drivers/usb/gadget/function/f_uvc.c | 8 +- drivers/usb/gadget/function/uvc_configfs.c | 480 +++++++++++++++++------------ 2 files changed, 282 insertions(+), 206 deletions(-) diff --git a/drivers/usb/gadget/function/f_uvc.c b/drivers/usb/gadget/function/f_uvc.c index d8ce7868fe22..95cb1b5f5ffe 100644 --- a/drivers/usb/gadget/function/f_uvc.c +++ b/drivers/usb/gadget/function/f_uvc.c @@ -792,6 +792,7 @@ static struct usb_function_instance *uvc_alloc_inst(void) struct uvc_output_terminal_descriptor *od; struct uvc_color_matching_descriptor *md; struct uvc_descriptor_header **ctl_cls; + int ret; opts = kzalloc(sizeof(*opts), GFP_KERNEL); if (!opts) @@ -868,7 +869,12 @@ static struct usb_function_instance *uvc_alloc_inst(void) opts->streaming_interval = 1; opts->streaming_maxpacket = 1024; - uvcg_attach_configfs(opts); + ret = uvcg_attach_configfs(opts); + if (ret < 0) { + kfree(opts); + return ERR_PTR(ret); + } + return &opts->func_inst; } diff --git a/drivers/usb/gadget/function/uvc_configfs.c b/drivers/usb/gadget/function/uvc_configfs.c index dbc95c9558de..e019ea317c7a 100644 --- a/drivers/usb/gadget/function/uvc_configfs.c +++ b/drivers/usb/gadget/function/uvc_configfs.c @@ -41,6 +41,49 @@ static inline struct f_uvc_opts *to_f_uvc_opts(struct config_item *item) func_inst.group); } +struct uvcg_config_group_type { + struct config_item_type type; + const char *name; + const struct uvcg_config_group_type **children; + int (*create_children)(struct config_group *group); +}; + +static int uvcg_config_create_group(struct config_group *parent, + const struct uvcg_config_group_type *type); + +static int uvcg_config_create_children(struct config_group *group, + const struct uvcg_config_group_type *type) +{ + const struct uvcg_config_group_type **child; + int ret; + + if (type->create_children) + return type->create_children(group); + + for (child = type->children; child && *child; ++child) { + ret = uvcg_config_create_group(group, *child); + if (ret < 0) + return ret; + } + + return 0; +} + +static int uvcg_config_create_group(struct config_group *parent, + const struct uvcg_config_group_type *type) +{ + struct config_group *group; + + group = kzalloc(sizeof(*group), GFP_KERNEL); + if (!group) + return -ENOMEM; + + config_group_init_type_name(group, type->name, &type->type); + configfs_add_default_group(group, parent); + + return uvcg_config_create_children(group, type); +} + /* ----------------------------------------------------------------------------- * control/header/ * control/header @@ -169,24 +212,23 @@ static void uvcg_control_header_drop(struct config_group *group, kfree(h); } -static struct config_group uvcg_control_header_grp; - static struct configfs_group_operations uvcg_control_header_grp_ops = { .make_item = uvcg_control_header_make, .drop_item = uvcg_control_header_drop, }; -static const struct config_item_type uvcg_control_header_grp_type = { - .ct_group_ops = &uvcg_control_header_grp_ops, - .ct_owner = THIS_MODULE, +static const struct uvcg_config_group_type uvcg_control_header_grp_type = { + .type = { + .ct_group_ops = &uvcg_control_header_grp_ops, + .ct_owner = THIS_MODULE, + }, + .name = "header", }; /* ----------------------------------------------------------------------------- * control/processing/default */ -static struct config_group uvcg_default_processing_grp; - #define UVCG_DEFAULT_PROCESSING_ATTR(cname, aname, conv) \ static ssize_t uvcg_default_processing_##cname##_show( \ struct config_item *item, char *page) \ @@ -265,27 +307,33 @@ static struct configfs_attribute *uvcg_default_processing_attrs[] = { NULL, }; -static const struct config_item_type uvcg_default_processing_type = { - .ct_attrs = uvcg_default_processing_attrs, - .ct_owner = THIS_MODULE, +static const struct uvcg_config_group_type uvcg_default_processing_type = { + .type = { + .ct_attrs = uvcg_default_processing_attrs, + .ct_owner = THIS_MODULE, + }, + .name = "default", }; /* ----------------------------------------------------------------------------- * control/processing */ -static struct config_group uvcg_processing_grp; - -static const struct config_item_type uvcg_processing_grp_type = { - .ct_owner = THIS_MODULE, +static const struct uvcg_config_group_type uvcg_processing_grp_type = { + .type = { + .ct_owner = THIS_MODULE, + }, + .name = "processing", + .children = (const struct uvcg_config_group_type*[]) { + &uvcg_default_processing_type, + NULL, + }, }; /* ----------------------------------------------------------------------------- * control/terminal/camera/default */ -static struct config_group uvcg_default_camera_grp; - #define UVCG_DEFAULT_CAMERA_ATTR(cname, aname, conv) \ static ssize_t uvcg_default_camera_##cname##_show( \ struct config_item *item, char *page) \ @@ -375,27 +423,33 @@ static struct configfs_attribute *uvcg_default_camera_attrs[] = { NULL, }; -static const struct config_item_type uvcg_default_camera_type = { - .ct_attrs = uvcg_default_camera_attrs, - .ct_owner = THIS_MODULE, +static const struct uvcg_config_group_type uvcg_default_camera_type = { + .type = { + .ct_attrs = uvcg_default_camera_attrs, + .ct_owner = THIS_MODULE, + }, + .name = "default", }; /* ----------------------------------------------------------------------------- * control/terminal/camera */ -static struct config_group uvcg_camera_grp; - -static const struct config_item_type uvcg_camera_grp_type = { - .ct_owner = THIS_MODULE, +static const struct uvcg_config_group_type uvcg_camera_grp_type = { + .type = { + .ct_owner = THIS_MODULE, + }, + .name = "camera", + .children = (const struct uvcg_config_group_type*[]) { + &uvcg_default_camera_type, + NULL, + }, }; /* ----------------------------------------------------------------------------- * control/terminal/output/default */ -static struct config_group uvcg_default_output_grp; - #define UVCG_DEFAULT_OUTPUT_ATTR(cname, aname, conv) \ static ssize_t uvcg_default_output_##cname##_show( \ struct config_item *item, char *page) \ @@ -446,47 +500,65 @@ static struct configfs_attribute *uvcg_default_output_attrs[] = { NULL, }; -static const struct config_item_type uvcg_default_output_type = { - .ct_attrs = uvcg_default_output_attrs, - .ct_owner = THIS_MODULE, +static const struct uvcg_config_group_type uvcg_default_output_type = { + .type = { + .ct_attrs = uvcg_default_output_attrs, + .ct_owner = THIS_MODULE, + }, + .name = "default", }; /* ----------------------------------------------------------------------------- * control/terminal/output */ -static struct config_group uvcg_output_grp; - -static const struct config_item_type uvcg_output_grp_type = { - .ct_owner = THIS_MODULE, +static const struct uvcg_config_group_type uvcg_output_grp_type = { + .type = { + .ct_owner = THIS_MODULE, + }, + .name = "output", + .children = (const struct uvcg_config_group_type*[]) { + &uvcg_default_output_type, + NULL, + }, }; /* ----------------------------------------------------------------------------- * control/terminal */ -static struct config_group uvcg_terminal_grp; - -static const struct config_item_type uvcg_terminal_grp_type = { - .ct_owner = THIS_MODULE, +static const struct uvcg_config_group_type uvcg_terminal_grp_type = { + .type = { + .ct_owner = THIS_MODULE, + }, + .name = "terminal", + .children = (const struct uvcg_config_group_type*[]) { + &uvcg_camera_grp_type, + &uvcg_output_grp_type, + NULL, + }, }; /* ----------------------------------------------------------------------------- * control/class/{fs|ss} */ -static struct config_group uvcg_control_class_fs_grp; -static struct config_group uvcg_control_class_ss_grp; +struct uvcg_control_class_group { + struct config_group group; + const char *name; +}; static inline struct uvc_descriptor_header **uvcg_get_ctl_class_arr(struct config_item *i, struct f_uvc_opts *o) { - struct config_group *group = to_config_group(i); + struct uvcg_control_class_group *group = + container_of(i, struct uvcg_control_class_group, + group.cg_item); - if (group == &uvcg_control_class_fs_grp) + if (!strcmp(group->name, "fs")) return o->uvc_fs_control_cls; - if (group == &uvcg_control_class_ss_grp) + if (!strcmp(group->name, "ss")) return o->uvc_ss_control_cls; return NULL; @@ -581,20 +653,52 @@ static const struct config_item_type uvcg_control_class_type = { * control/class */ -static struct config_group uvcg_control_class_grp; +static int uvcg_control_class_create_children(struct config_group *parent) +{ + static const char * const names[] = { "fs", "ss" }; + unsigned int i; + + for (i = 0; i < ARRAY_SIZE(names); ++i) { + struct uvcg_control_class_group *group; + + group = kzalloc(sizeof(*group), GFP_KERNEL); + if (!group) + return -ENOMEM; + + group->name = names[i]; -static const struct config_item_type uvcg_control_class_grp_type = { - .ct_owner = THIS_MODULE, + config_group_init_type_name(&group->group, group->name, + &uvcg_control_class_type); + configfs_add_default_group(&group->group, parent); + } + + return 0; +} + +static const struct uvcg_config_group_type uvcg_control_class_grp_type = { + .type = { + .ct_owner = THIS_MODULE, + }, + .name = "class", + .create_children = uvcg_control_class_create_children, }; /* ----------------------------------------------------------------------------- * control */ -static struct config_group uvcg_control_grp; - -static const struct config_item_type uvcg_control_grp_type = { - .ct_owner = THIS_MODULE, +static const struct uvcg_config_group_type uvcg_control_grp_type = { + .type = { + .ct_owner = THIS_MODULE, + }, + .name = "control", + .children = (const struct uvcg_config_group_type*[]) { + &uvcg_control_header_grp_type, + &uvcg_processing_grp_type, + &uvcg_terminal_grp_type, + &uvcg_control_class_grp_type, + NULL, + }, }; /* ----------------------------------------------------------------------------- @@ -602,12 +706,9 @@ static const struct config_item_type uvcg_control_grp_type = { * streaming/mjpeg */ -static struct config_group uvcg_uncompressed_grp; -static struct config_group uvcg_mjpeg_grp; - -static struct config_item *fmt_parent[] = { - &uvcg_uncompressed_grp.cg_item, - &uvcg_mjpeg_grp.cg_item, +static const char * const uvcg_format_names[] = { + "uncompressed", + "mjpeg", }; enum uvcg_format_type { @@ -733,10 +834,22 @@ static int uvcg_streaming_header_allow_link(struct config_item *src, goto out; } - for (i = 0; i < ARRAY_SIZE(fmt_parent); ++i) - if (target->ci_parent == fmt_parent[i]) + /* + * Linking is only allowed to direct children of the format nodes + * (streaming/uncompressed or streaming/mjpeg nodes). First check that + * the grand-parent of the target matches the grand-parent of the source + * (the streaming node), and then verify that the target parent is a + * format node. + */ + if (src->ci_parent->ci_parent != target->ci_parent->ci_parent) + goto out; + + for (i = 0; i < ARRAY_SIZE(uvcg_format_names); ++i) { + if (!strcmp(target->ci_parent->ci_name, uvcg_format_names[i])) break; - if (i == ARRAY_SIZE(fmt_parent)) + } + + if (i == ARRAY_SIZE(uvcg_format_names)) goto out; target_fmt = container_of(to_config_group(target), struct uvcg_format, @@ -881,16 +994,17 @@ static void uvcg_streaming_header_drop(struct config_group *group, kfree(h); } -static struct config_group uvcg_streaming_header_grp; - static struct configfs_group_operations uvcg_streaming_header_grp_ops = { .make_item = uvcg_streaming_header_make, .drop_item = uvcg_streaming_header_drop, }; -static const struct config_item_type uvcg_streaming_header_grp_type = { - .ct_group_ops = &uvcg_streaming_header_grp_ops, - .ct_owner = THIS_MODULE, +static const struct uvcg_config_group_type uvcg_streaming_header_grp_type = { + .type = { + .ct_group_ops = &uvcg_streaming_header_grp_ops, + .ct_owner = THIS_MODULE, + }, + .name = "header", }; /* ----------------------------------------------------------------------------- @@ -1462,9 +1576,12 @@ static struct configfs_group_operations uvcg_uncompressed_grp_ops = { .drop_item = uvcg_uncompressed_drop, }; -static const struct config_item_type uvcg_uncompressed_grp_type = { - .ct_group_ops = &uvcg_uncompressed_grp_ops, - .ct_owner = THIS_MODULE, +static const struct uvcg_config_group_type uvcg_uncompressed_grp_type = { + .type = { + .ct_group_ops = &uvcg_uncompressed_grp_ops, + .ct_owner = THIS_MODULE, + }, + .name = "uncompressed", }; /* ----------------------------------------------------------------------------- @@ -1659,17 +1776,18 @@ static struct configfs_group_operations uvcg_mjpeg_grp_ops = { .drop_item = uvcg_mjpeg_drop, }; -static const struct config_item_type uvcg_mjpeg_grp_type = { - .ct_group_ops = &uvcg_mjpeg_grp_ops, - .ct_owner = THIS_MODULE, +static const struct uvcg_config_group_type uvcg_mjpeg_grp_type = { + .type = { + .ct_group_ops = &uvcg_mjpeg_grp_ops, + .ct_owner = THIS_MODULE, + }, + .name = "mjpeg", }; /* ----------------------------------------------------------------------------- * streaming/color_matching/default */ -static struct config_group uvcg_default_color_matching_grp; - #define UVCG_DEFAULT_COLOR_MATCHING_ATTR(cname, aname, conv) \ static ssize_t uvcg_default_color_matching_##cname##_show( \ struct config_item *item, char *page) \ @@ -1717,41 +1835,52 @@ static struct configfs_attribute *uvcg_default_color_matching_attrs[] = { NULL, }; -static const struct config_item_type uvcg_default_color_matching_type = { - .ct_attrs = uvcg_default_color_matching_attrs, - .ct_owner = THIS_MODULE, +static const struct uvcg_config_group_type uvcg_default_color_matching_type = { + .type = { + .ct_attrs = uvcg_default_color_matching_attrs, + .ct_owner = THIS_MODULE, + }, + .name = "default", }; /* ----------------------------------------------------------------------------- * streaming/color_matching */ -static struct config_group uvcg_color_matching_grp; - -static const struct config_item_type uvcg_color_matching_grp_type = { - .ct_owner = THIS_MODULE, +static const struct uvcg_config_group_type uvcg_color_matching_grp_type = { + .type = { + .ct_owner = THIS_MODULE, + }, + .name = "color_matching", + .children = (const struct uvcg_config_group_type*[]) { + &uvcg_default_color_matching_type, + NULL, + }, }; /* ----------------------------------------------------------------------------- * streaming/class/{fs|hs|ss} */ -static struct config_group uvcg_streaming_class_fs_grp; -static struct config_group uvcg_streaming_class_hs_grp; -static struct config_group uvcg_streaming_class_ss_grp; +struct uvcg_streaming_class_group { + struct config_group group; + const char *name; +}; static inline struct uvc_descriptor_header ***__uvcg_get_stream_class_arr(struct config_item *i, struct f_uvc_opts *o) { - struct config_group *group = to_config_group(i); + struct uvcg_streaming_class_group *group = + container_of(i, struct uvcg_streaming_class_group, + group.cg_item); - if (group == &uvcg_streaming_class_fs_grp) + if (!strcmp(group->name, "fs")) return &o->uvc_fs_streaming_cls; - if (group == &uvcg_streaming_class_hs_grp) + if (!strcmp(group->name, "hs")) return &o->uvc_hs_streaming_cls; - if (group == &uvcg_streaming_class_ss_grp) + if (!strcmp(group->name, "ss")) return &o->uvc_ss_streaming_cls; return NULL; @@ -2083,20 +2212,53 @@ static const struct config_item_type uvcg_streaming_class_type = { * streaming/class */ -static struct config_group uvcg_streaming_class_grp; +static int uvcg_streaming_class_create_children(struct config_group *parent) +{ + static const char * const names[] = { "fs", "hs", "ss" }; + unsigned int i; + + for (i = 0; i < ARRAY_SIZE(names); ++i) { + struct uvcg_streaming_class_group *group; + + group = kzalloc(sizeof(*group), GFP_KERNEL); + if (!group) + return -ENOMEM; + + group->name = names[i]; + + config_group_init_type_name(&group->group, group->name, + &uvcg_streaming_class_type); + configfs_add_default_group(&group->group, parent); + } + + return 0; +} -static const struct config_item_type uvcg_streaming_class_grp_type = { - .ct_owner = THIS_MODULE, +static const struct uvcg_config_group_type uvcg_streaming_class_grp_type = { + .type = { + .ct_owner = THIS_MODULE, + }, + .name = "class", + .create_children = uvcg_streaming_class_create_children, }; /* ----------------------------------------------------------------------------- * streaming */ -static struct config_group uvcg_streaming_grp; - -static const struct config_item_type uvcg_streaming_grp_type = { - .ct_owner = THIS_MODULE, +static const struct uvcg_config_group_type uvcg_streaming_grp_type = { + .type = { + .ct_owner = THIS_MODULE, + }, + .name = "streaming", + .children = (const struct uvcg_config_group_type*[]) { + &uvcg_streaming_header_grp_type, + &uvcg_uncompressed_grp_type, + &uvcg_mjpeg_grp_type, + &uvcg_color_matching_grp_type, + &uvcg_streaming_class_grp_type, + NULL, + }, }; /* ----------------------------------------------------------------------------- @@ -2179,123 +2341,31 @@ static struct configfs_attribute *uvc_attrs[] = { NULL, }; -static const struct config_item_type uvc_func_type = { - .ct_item_ops = &uvc_item_ops, - .ct_attrs = uvc_attrs, - .ct_owner = THIS_MODULE, +static const struct uvcg_config_group_type uvc_func_type = { + .type = { + .ct_item_ops = &uvc_item_ops, + .ct_attrs = uvc_attrs, + .ct_owner = THIS_MODULE, + }, + .name = "", + .children = (const struct uvcg_config_group_type*[]) { + &uvcg_control_grp_type, + &uvcg_streaming_grp_type, + NULL, + }, }; int uvcg_attach_configfs(struct f_uvc_opts *opts) { - config_group_init_type_name(&uvcg_control_header_grp, - "header", - &uvcg_control_header_grp_type); - - config_group_init_type_name(&uvcg_default_processing_grp, - "default", &uvcg_default_processing_type); - config_group_init_type_name(&uvcg_processing_grp, - "processing", &uvcg_processing_grp_type); - configfs_add_default_group(&uvcg_default_processing_grp, - &uvcg_processing_grp); - - config_group_init_type_name(&uvcg_default_camera_grp, - "default", &uvcg_default_camera_type); - config_group_init_type_name(&uvcg_camera_grp, - "camera", &uvcg_camera_grp_type); - configfs_add_default_group(&uvcg_default_camera_grp, - &uvcg_camera_grp); - - config_group_init_type_name(&uvcg_default_output_grp, - "default", &uvcg_default_output_type); - config_group_init_type_name(&uvcg_output_grp, - "output", &uvcg_output_grp_type); - configfs_add_default_group(&uvcg_default_output_grp, - &uvcg_output_grp); - - config_group_init_type_name(&uvcg_terminal_grp, - "terminal", &uvcg_terminal_grp_type); - configfs_add_default_group(&uvcg_camera_grp, - &uvcg_terminal_grp); - configfs_add_default_group(&uvcg_output_grp, - &uvcg_terminal_grp); - - config_group_init_type_name(&uvcg_control_class_fs_grp, - "fs", &uvcg_control_class_type); - config_group_init_type_name(&uvcg_control_class_ss_grp, - "ss", &uvcg_control_class_type); - config_group_init_type_name(&uvcg_control_class_grp, - "class", - &uvcg_control_class_grp_type); - configfs_add_default_group(&uvcg_control_class_fs_grp, - &uvcg_control_class_grp); - configfs_add_default_group(&uvcg_control_class_ss_grp, - &uvcg_control_class_grp); - - config_group_init_type_name(&uvcg_control_grp, - "control", - &uvcg_control_grp_type); - configfs_add_default_group(&uvcg_control_header_grp, - &uvcg_control_grp); - configfs_add_default_group(&uvcg_processing_grp, - &uvcg_control_grp); - configfs_add_default_group(&uvcg_terminal_grp, - &uvcg_control_grp); - configfs_add_default_group(&uvcg_control_class_grp, - &uvcg_control_grp); - - config_group_init_type_name(&uvcg_streaming_header_grp, - "header", - &uvcg_streaming_header_grp_type); - config_group_init_type_name(&uvcg_uncompressed_grp, - "uncompressed", - &uvcg_uncompressed_grp_type); - config_group_init_type_name(&uvcg_mjpeg_grp, - "mjpeg", - &uvcg_mjpeg_grp_type); - config_group_init_type_name(&uvcg_default_color_matching_grp, - "default", - &uvcg_default_color_matching_type); - config_group_init_type_name(&uvcg_color_matching_grp, - "color_matching", - &uvcg_color_matching_grp_type); - configfs_add_default_group(&uvcg_default_color_matching_grp, - &uvcg_color_matching_grp); - - config_group_init_type_name(&uvcg_streaming_class_fs_grp, - "fs", &uvcg_streaming_class_type); - config_group_init_type_name(&uvcg_streaming_class_hs_grp, - "hs", &uvcg_streaming_class_type); - config_group_init_type_name(&uvcg_streaming_class_ss_grp, - "ss", &uvcg_streaming_class_type); - config_group_init_type_name(&uvcg_streaming_class_grp, - "class", &uvcg_streaming_class_grp_type); - configfs_add_default_group(&uvcg_streaming_class_fs_grp, - &uvcg_streaming_class_grp); - configfs_add_default_group(&uvcg_streaming_class_hs_grp, - &uvcg_streaming_class_grp); - configfs_add_default_group(&uvcg_streaming_class_ss_grp, - &uvcg_streaming_class_grp); - - config_group_init_type_name(&uvcg_streaming_grp, - "streaming", &uvcg_streaming_grp_type); - configfs_add_default_group(&uvcg_streaming_header_grp, - &uvcg_streaming_grp); - configfs_add_default_group(&uvcg_uncompressed_grp, - &uvcg_streaming_grp); - configfs_add_default_group(&uvcg_mjpeg_grp, - &uvcg_streaming_grp); - configfs_add_default_group(&uvcg_color_matching_grp, - &uvcg_streaming_grp); - configfs_add_default_group(&uvcg_streaming_class_grp, - &uvcg_streaming_grp); - - config_group_init_type_name(&opts->func_inst.group, - "", - &uvc_func_type); - configfs_add_default_group(&uvcg_control_grp, - &opts->func_inst.group); - configfs_add_default_group(&uvcg_streaming_grp, - &opts->func_inst.group); + int ret; - return 0; + config_group_init_type_name(&opts->func_inst.group, uvc_func_type.name, + &uvc_func_type.type); + + ret = uvcg_config_create_children(&opts->func_inst.group, + &uvc_func_type); + if (ret < 0) + config_group_put(&opts->func_inst.group); + + return ret; } From patchwork Wed Aug 1 00:29:05 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 10551585 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 12F4E13B8 for ; Wed, 1 Aug 2018 00:28:46 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 02B332AFB3 for ; Wed, 1 Aug 2018 00:28:46 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id EA4642AFEA; Wed, 1 Aug 2018 00:28:45 +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 773902AFB3 for ; Wed, 1 Aug 2018 00:28:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732921AbeHACLe (ORCPT ); Tue, 31 Jul 2018 22:11:34 -0400 Received: from perceval.ideasonboard.com ([213.167.242.64]:33732 "EHLO perceval.ideasonboard.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732892AbeHACLe (ORCPT ); Tue, 31 Jul 2018 22:11:34 -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 1F39A1BE5; Wed, 1 Aug 2018 02:28:41 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1533083321; bh=m0ACL1kwcC+bvzNFGZbzL6SPU6UOUlwZp1AxtzyXbqQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=HeLkN4ypKZuJBRTT5rM+uq0iwVvp+2W/EfSrKbTevE6zBwL2xYNb8PvhsRsunxoVB YaIjIjRxujwtxSFP/fLDlu1n1y9lg7oDm6vTHEBo2d7NfOFtcBGJkb4Nc/foUCSqEr PsYtmPszixGToZbHzv77MyPjGpwfrjgcqYw9YjN8= From: Laurent Pinchart To: linux-usb@vger.kernel.org Cc: Felipe Balbi , Joel Pepper , Kieran Bingham , Andrzej Pietrasiewicz Subject: [PATCH 4/8] usb: gadget: uvc: configfs: Add interface number attributes Date: Wed, 1 Aug 2018 03:29:05 +0300 Message-Id: <20180801002909.2890-5-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.16.4 In-Reply-To: <20180801002909.2890-1-laurent.pinchart@ideasonboard.com> References: <20180801002909.2890-1-laurent.pinchart@ideasonboard.com> 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 The video control and video streaming interface numbers are needed in the UVC gadget userspace stack to reply to UVC requests. They are hardcoded to fixed values at the moment, preventing configurations with multiple functions. To fix this, make them dynamically discoverable by userspace through read-only configfs attributes in /control/bInterfaceNumber and /streaming/bInterfaceNumber respectively. Signed-off-by: Laurent Pinchart --- drivers/usb/gadget/function/f_uvc.c | 2 + drivers/usb/gadget/function/u_uvc.h | 3 ++ drivers/usb/gadget/function/uvc_configfs.c | 62 ++++++++++++++++++++++++++++++ 3 files changed, 67 insertions(+) diff --git a/drivers/usb/gadget/function/f_uvc.c b/drivers/usb/gadget/function/f_uvc.c index 95cb1b5f5ffe..4ea987741e6e 100644 --- a/drivers/usb/gadget/function/f_uvc.c +++ b/drivers/usb/gadget/function/f_uvc.c @@ -699,12 +699,14 @@ uvc_function_bind(struct usb_configuration *c, struct usb_function *f) uvc_iad.bFirstInterface = ret; uvc_control_intf.bInterfaceNumber = ret; uvc->control_intf = ret; + opts->control_interface = ret; if ((ret = usb_interface_id(c, f)) < 0) goto error; uvc_streaming_intf_alt0.bInterfaceNumber = ret; uvc_streaming_intf_alt1.bInterfaceNumber = ret; uvc->streaming_intf = ret; + opts->streaming_interface = ret; /* Copy descriptors */ f->fs_descriptors = uvc_copy_descriptors(uvc, USB_SPEED_FULL); diff --git a/drivers/usb/gadget/function/u_uvc.h b/drivers/usb/gadget/function/u_uvc.h index 2ed292e94fbc..5242d489e20a 100644 --- a/drivers/usb/gadget/function/u_uvc.h +++ b/drivers/usb/gadget/function/u_uvc.h @@ -25,6 +25,9 @@ struct f_uvc_opts { unsigned int streaming_maxpacket; unsigned int streaming_maxburst; + unsigned int control_interface; + unsigned int streaming_interface; + /* * Control descriptors array pointers for full-/high-speed and * super-speed. They point by default to the uvc_fs_control_cls and diff --git a/drivers/usb/gadget/function/uvc_configfs.c b/drivers/usb/gadget/function/uvc_configfs.c index e019ea317c7a..801117686108 100644 --- a/drivers/usb/gadget/function/uvc_configfs.c +++ b/drivers/usb/gadget/function/uvc_configfs.c @@ -687,8 +687,39 @@ static const struct uvcg_config_group_type uvcg_control_class_grp_type = { * control */ +static ssize_t uvcg_default_control_b_interface_number_show( + struct config_item *item, char *page) +{ + struct config_group *group = to_config_group(item); + struct mutex *su_mutex = &group->cg_subsys->su_mutex; + struct config_item *opts_item; + struct f_uvc_opts *opts; + int result = 0; + + mutex_lock(su_mutex); /* for navigating configfs hierarchy */ + + opts_item = item->ci_parent; + opts = to_f_uvc_opts(opts_item); + + mutex_lock(&opts->lock); + result += sprintf(page, "%u\n", opts->control_interface); + mutex_unlock(&opts->lock); + + mutex_unlock(su_mutex); + + return result; +} + +UVC_ATTR_RO(uvcg_default_control_, b_interface_number, bInterfaceNumber); + +static struct configfs_attribute *uvcg_default_control_attrs[] = { + &uvcg_default_control_attr_b_interface_number, + NULL, +}; + static const struct uvcg_config_group_type uvcg_control_grp_type = { .type = { + .ct_attrs = uvcg_default_control_attrs, .ct_owner = THIS_MODULE, }, .name = "control", @@ -2246,8 +2277,39 @@ static const struct uvcg_config_group_type uvcg_streaming_class_grp_type = { * streaming */ +static ssize_t uvcg_default_streaming_b_interface_number_show( + struct config_item *item, char *page) +{ + struct config_group *group = to_config_group(item); + struct mutex *su_mutex = &group->cg_subsys->su_mutex; + struct config_item *opts_item; + struct f_uvc_opts *opts; + int result = 0; + + mutex_lock(su_mutex); /* for navigating configfs hierarchy */ + + opts_item = item->ci_parent; + opts = to_f_uvc_opts(opts_item); + + mutex_lock(&opts->lock); + result += sprintf(page, "%u\n", opts->streaming_interface); + mutex_unlock(&opts->lock); + + mutex_unlock(su_mutex); + + return result; +} + +UVC_ATTR_RO(uvcg_default_streaming_, b_interface_number, bInterfaceNumber); + +static struct configfs_attribute *uvcg_default_streaming_attrs[] = { + &uvcg_default_streaming_attr_b_interface_number, + NULL, +}; + static const struct uvcg_config_group_type uvcg_streaming_grp_type = { .type = { + .ct_attrs = uvcg_default_streaming_attrs, .ct_owner = THIS_MODULE, }, .name = "streaming", From patchwork Wed Aug 1 00:29:06 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 10551587 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 4B30F14E0 for ; Wed, 1 Aug 2018 00:28:47 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3C8B42AFB3 for ; Wed, 1 Aug 2018 00:28:47 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2F7952AFEA; Wed, 1 Aug 2018 00:28:47 +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 B7F252AFB3 for ; Wed, 1 Aug 2018 00:28:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732922AbeHACLg (ORCPT ); Tue, 31 Jul 2018 22:11:36 -0400 Received: from perceval.ideasonboard.com ([213.167.242.64]:33732 "EHLO perceval.ideasonboard.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732892AbeHACLg (ORCPT ); Tue, 31 Jul 2018 22:11:36 -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 BC8BD1C88; Wed, 1 Aug 2018 02:28:41 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1533083322; bh=ee5dKCt8XEja4mpoLJhQPI/rGvmMafIZ0jmW5MRIJ1o=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ZmfzEeqj4gK4greSDsvkE80t5zy2J54XSDhoY/kCTtpcXxcK+VmlEnaoqqv3yhGM+ ngCFBBkpHbC0/GJypYFQGshEXS5TrzADsrI/RTEsoxIzxSGCW2ZnASs2FBXHjez0VU q/O3UqC+Mqq50f0D3p7zQXNjkTlhwTGKARSJgCKk= From: Laurent Pinchart To: linux-usb@vger.kernel.org Cc: Felipe Balbi , Joel Pepper , Kieran Bingham , Andrzej Pietrasiewicz Subject: [PATCH 5/8] usb: gadget: uvc: configfs: Add bFormatIndex attributes Date: Wed, 1 Aug 2018 03:29:06 +0300 Message-Id: <20180801002909.2890-6-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.16.4 In-Reply-To: <20180801002909.2890-1-laurent.pinchart@ideasonboard.com> References: <20180801002909.2890-1-laurent.pinchart@ideasonboard.com> 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 The UVC format description are numbered using the descriptor's bFormatIndex field. The index is used in UVC requests, and is thus needed to handle requests in userspace. Make it dynamically discoverable by exposing it in a bFormatIndex configfs attribute of the uncompressed and mjpeg format config items. The bFormatIndex value exposed through the attribute is stored in the config item private data. However, that value is never set: the driver instead computes the bFormatIndex value when linking the stream class header in the configfs hierarchy and stores it directly in the class descriptors in a separate structure. In order to expose the value through the configfs attribute, store it in the config item private data as well. This results in a small code simplification. Signed-off-by: Laurent Pinchart --- drivers/usb/gadget/function/uvc_configfs.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/drivers/usb/gadget/function/uvc_configfs.c b/drivers/usb/gadget/function/uvc_configfs.c index 801117686108..90de6418209b 100644 --- a/drivers/usb/gadget/function/uvc_configfs.c +++ b/drivers/usb/gadget/function/uvc_configfs.c @@ -1517,6 +1517,7 @@ UVC_ATTR(uvcg_uncompressed_, cname, aname); #define identity_conv(x) (x) +UVCG_UNCOMPRESSED_ATTR_RO(b_format_index, bFormatIndex, identity_conv); UVCG_UNCOMPRESSED_ATTR(b_bits_per_pixel, bBitsPerPixel, identity_conv); UVCG_UNCOMPRESSED_ATTR(b_default_frame_index, bDefaultFrameIndex, identity_conv); @@ -1547,6 +1548,7 @@ uvcg_uncompressed_bma_controls_store(struct config_item *item, UVC_ATTR(uvcg_uncompressed_, bma_controls, bmaControls); static struct configfs_attribute *uvcg_uncompressed_attrs[] = { + &uvcg_uncompressed_attr_b_format_index, &uvcg_uncompressed_attr_guid_format, &uvcg_uncompressed_attr_b_bits_per_pixel, &uvcg_uncompressed_attr_b_default_frame_index, @@ -1724,6 +1726,7 @@ UVC_ATTR(uvcg_mjpeg_, cname, aname) #define identity_conv(x) (x) +UVCG_MJPEG_ATTR_RO(b_format_index, bFormatIndex, identity_conv); UVCG_MJPEG_ATTR(b_default_frame_index, bDefaultFrameIndex, identity_conv); UVCG_MJPEG_ATTR_RO(bm_flags, bmFlags, identity_conv); @@ -1754,6 +1757,7 @@ uvcg_mjpeg_bma_controls_store(struct config_item *item, UVC_ATTR(uvcg_mjpeg_, bma_controls, bmaControls); static struct configfs_attribute *uvcg_mjpeg_attrs[] = { + &uvcg_mjpeg_attr_b_format_index, &uvcg_mjpeg_attr_b_default_frame_index, &uvcg_mjpeg_attr_bm_flags, &uvcg_mjpeg_attr_b_aspect_ratio_x, @@ -2070,24 +2074,22 @@ static int __uvcg_fill_strm(void *priv1, void *priv2, void *priv3, int n, struct uvcg_format *fmt = priv1; if (fmt->type == UVCG_UNCOMPRESSED) { - struct uvc_format_uncompressed *unc = *dest; struct uvcg_uncompressed *u = container_of(fmt, struct uvcg_uncompressed, fmt); + u->desc.bFormatIndex = n + 1; + u->desc.bNumFrameDescriptors = fmt->num_frames; memcpy(*dest, &u->desc, sizeof(u->desc)); *dest += sizeof(u->desc); - unc->bNumFrameDescriptors = fmt->num_frames; - unc->bFormatIndex = n + 1; } else if (fmt->type == UVCG_MJPEG) { - struct uvc_format_mjpeg *mjp = *dest; struct uvcg_mjpeg *m = container_of(fmt, struct uvcg_mjpeg, fmt); + m->desc.bFormatIndex = n + 1; + m->desc.bNumFrameDescriptors = fmt->num_frames; memcpy(*dest, &m->desc, sizeof(m->desc)); *dest += sizeof(m->desc); - mjp->bNumFrameDescriptors = fmt->num_frames; - mjp->bFormatIndex = n + 1; } else { return -EINVAL; } From patchwork Wed Aug 1 00:29:07 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 10551589 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id CA3F014E0 for ; Wed, 1 Aug 2018 00:28:48 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id BC7202AFB3 for ; Wed, 1 Aug 2018 00:28:48 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B0AB02B098; Wed, 1 Aug 2018 00:28:48 +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 5F48C2AFB3 for ; Wed, 1 Aug 2018 00:28:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732925AbeHACLh (ORCPT ); Tue, 31 Jul 2018 22:11:37 -0400 Received: from perceval.ideasonboard.com ([213.167.242.64]:33732 "EHLO perceval.ideasonboard.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732923AbeHACLh (ORCPT ); Tue, 31 Jul 2018 22:11:37 -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 55F2DB86; Wed, 1 Aug 2018 02:28:42 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1533083322; bh=Xr2bkd1P4ayGi51RxxwJFBOZ2dLkVPoN75IrwPfJFQE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=CjT7ZVBIsIoRbkrqN1/MVNSRCe7s3eUL/nunMEWBmJaepxBH3XXffAc1HrOhYFJfl 3AdC5RNgrxYG0t0Lo5jBIFcAity2q4HUCBKKuYuHp5aBDKNvXcJ8VXCfdaS4/36I0O HULLpCAaSUHASYrF0/gDWYwk2lLLH/aKF+U8o0i8= From: Laurent Pinchart To: linux-usb@vger.kernel.org Cc: Felipe Balbi , Joel Pepper , Kieran Bingham , Andrzej Pietrasiewicz Subject: [PATCH 6/8] usb: gadget: uvc: configfs: Document the bFormatIndex attribute Date: Wed, 1 Aug 2018 03:29:07 +0300 Message-Id: <20180801002909.2890-7-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.16.4 In-Reply-To: <20180801002909.2890-1-laurent.pinchart@ideasonboard.com> References: <20180801002909.2890-1-laurent.pinchart@ideasonboard.com> 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 Document for the bFormatIndex attribute of the format descriptors is missing. Add it. Signed-off-by: Laurent Pinchart --- Documentation/ABI/testing/configfs-usb-gadget-uvc | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/Documentation/ABI/testing/configfs-usb-gadget-uvc b/Documentation/ABI/testing/configfs-usb-gadget-uvc index 9281e2aa38df..9896c8aa0e14 100644 --- a/Documentation/ABI/testing/configfs-usb-gadget-uvc +++ b/Documentation/ABI/testing/configfs-usb-gadget-uvc @@ -160,6 +160,10 @@ Description: Specific MJPEG format descriptors All attributes read only, except bmaControls and bDefaultFrameIndex: + bFormatIndex - unique id for this format descriptor; + only defined after parent header is + linked into the streaming class; + read-only bmaControls - this format's data for bmaControls in the streaming header bmInterfaceFlags - specifies interlace information, @@ -204,6 +208,10 @@ Date: Dec 2014 KernelVersion: 4.0 Description: Specific uncompressed format descriptors + bFormatIndex - unique id for this format descriptor; + only defined after parent header is + linked into the streaming class; + read-only bmaControls - this format's data for bmaControls in the streaming header bmInterfaceFlags - specifies interlace information, From patchwork Wed Aug 1 00:29:08 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 10551595 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 422A81708 for ; Wed, 1 Aug 2018 00:28:51 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 328D62AFB3 for ; Wed, 1 Aug 2018 00:28:51 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 23BA72B041; Wed, 1 Aug 2018 00:28:51 +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 9B2512AFDF for ; Wed, 1 Aug 2018 00:28:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732930AbeHACLj (ORCPT ); Tue, 31 Jul 2018 22:11:39 -0400 Received: from perceval.ideasonboard.com ([213.167.242.64]:33732 "EHLO perceval.ideasonboard.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732927AbeHACLj (ORCPT ); Tue, 31 Jul 2018 22:11:39 -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 E70D21AB6; Wed, 1 Aug 2018 02:28:42 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1533083323; bh=wiY1X6BlOV6DKGd2MsAyv9pHgxqpYi9gZHFjBw/lVJ4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=jjXp3eiRFEr4a1VDZmLr3DDfGLNcPm2eR/Ak7W6nyWOWWciwR4kHrdHifr6Pp2l9M hSyn22/DGhP5MyYbwOW6XqZfn0lmcKJe5wUEcOJ5YlNT6TUd7i/+WVd03Kd34i3JT3 4TwRjCDbmYI+WKOKMJGCxm49MC+4Wrw80bjTE0E4= From: Laurent Pinchart To: linux-usb@vger.kernel.org Cc: Felipe Balbi , Joel Pepper , Kieran Bingham , Andrzej Pietrasiewicz Subject: [PATCH 7/8] usb: gadget: uvc: configfs: Add bFrameIndex attributes Date: Wed, 1 Aug 2018 03:29:08 +0300 Message-Id: <20180801002909.2890-8-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.16.4 In-Reply-To: <20180801002909.2890-1-laurent.pinchart@ideasonboard.com> References: <20180801002909.2890-1-laurent.pinchart@ideasonboard.com> 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: Joel Pepper - Add bFrameIndex as a UVCG_FRAME_ATTR_RO for each frame size. - Automatically assign ascending bFrameIndex to each frame in a format. Before all "bFrameindex" attributes were set to "1" with no way to configure the gadget otherwise. This resulted in the host always negotiating for bFrameIndex 1 (i.e. the first framesize of the gadget). After the negotiation the host driver will set the user or application selected framesize, while the gadget is actually set to the first framesize. Now, when the containing format is linked into the streaming header, iterate over all child frame descriptors and assign ascending indices. The automatically assigned indices can be read from the new read only bFrameIndex configsfs attribute in each frame descriptor item. Signed-off-by: Joel Pepper [Simplified documentation, renamed function, blank space update] Signed-off-by: Laurent Pinchart --- Documentation/ABI/testing/configfs-usb-gadget-uvc | 8 ++++ drivers/usb/gadget/function/uvc_configfs.c | 56 +++++++++++++++++++++++ 2 files changed, 64 insertions(+) diff --git a/Documentation/ABI/testing/configfs-usb-gadget-uvc b/Documentation/ABI/testing/configfs-usb-gadget-uvc index 9896c8aa0e14..1efeb2e835ea 100644 --- a/Documentation/ABI/testing/configfs-usb-gadget-uvc +++ b/Documentation/ABI/testing/configfs-usb-gadget-uvc @@ -181,6 +181,10 @@ Date: Dec 2014 KernelVersion: 4.0 Description: Specific MJPEG frame descriptors + bFrameIndex - unique id for this framedescriptor; + only defined after parent format is + linked into the streaming header; + read-only dwFrameInterval - indicates how frame interval can be programmed; a number of values separated by newline can be specified @@ -232,6 +236,10 @@ Date: Dec 2014 KernelVersion: 4.0 Description: Specific uncompressed frame descriptors + bFrameIndex - unique id for this framedescriptor; + only defined after parent format is + linked into the streaming header; + read-only dwFrameInterval - indicates how frame interval can be programmed; a number of values separated by newline can be specified diff --git a/drivers/usb/gadget/function/uvc_configfs.c b/drivers/usb/gadget/function/uvc_configfs.c index 90de6418209b..9af4cda27865 100644 --- a/drivers/usb/gadget/function/uvc_configfs.c +++ b/drivers/usb/gadget/function/uvc_configfs.c @@ -841,6 +841,8 @@ static struct uvcg_streaming_header *to_uvcg_streaming_header(struct config_item return container_of(item, struct uvcg_streaming_header, item); } +static void uvcg_format_set_indices(struct config_group *fmt); + static int uvcg_streaming_header_allow_link(struct config_item *src, struct config_item *target) { @@ -888,6 +890,8 @@ static int uvcg_streaming_header_allow_link(struct config_item *src, if (!target_fmt) goto out; + uvcg_format_set_indices(to_config_group(target)); + format_ptr = kzalloc(sizeof(*format_ptr), GFP_KERNEL); if (!format_ptr) { ret = -ENOMEM; @@ -1126,6 +1130,41 @@ end: \ \ UVC_ATTR(uvcg_frame_, cname, aname); +static ssize_t uvcg_frame_b_frame_index_show(struct config_item *item, + char *page) +{ + struct uvcg_frame *f = to_uvcg_frame(item); + struct uvcg_format *fmt; + struct f_uvc_opts *opts; + struct config_item *opts_item; + struct config_item *fmt_item; + struct mutex *su_mutex = &f->item.ci_group->cg_subsys->su_mutex; + int result; + + mutex_lock(su_mutex); /* for navigating configfs hierarchy */ + + fmt_item = f->item.ci_parent; + fmt = to_uvcg_format(fmt_item); + + if (!fmt->linked) { + result = -EBUSY; + goto out; + } + + opts_item = fmt_item->ci_parent->ci_parent->ci_parent; + opts = to_f_uvc_opts(opts_item); + + mutex_lock(&opts->lock); + result = sprintf(page, "%d\n", f->frame.b_frame_index); + mutex_unlock(&opts->lock); + +out: + mutex_unlock(su_mutex); + return result; +} + +UVC_ATTR_RO(uvcg_frame_, b_frame_index, bFrameIndex); + #define noop_conversion(x) (x) UVCG_FRAME_ATTR(bm_capabilities, bmCapabilities, noop_conversion, @@ -1274,6 +1313,7 @@ static ssize_t uvcg_frame_dw_frame_interval_store(struct config_item *item, UVC_ATTR(uvcg_frame_, dw_frame_interval, dwFrameInterval); static struct configfs_attribute *uvcg_frame_attrs[] = { + &uvcg_frame_attr_b_frame_index, &uvcg_frame_attr_bm_capabilities, &uvcg_frame_attr_w_width, &uvcg_frame_attr_w_height, @@ -1352,6 +1392,22 @@ static void uvcg_frame_drop(struct config_group *group, struct config_item *item mutex_unlock(&opts->lock); } +static void uvcg_format_set_indices(struct config_group *fmt) +{ + struct config_item *ci; + unsigned int i = 1; + + list_for_each_entry(ci, &fmt->cg_children, ci_entry) { + struct uvcg_frame *frm; + + if (ci->ci_type != &uvcg_frame_type) + continue; + + frm = to_uvcg_frame(ci); + frm->frame.b_frame_index = i++; + } +} + /* ----------------------------------------------------------------------------- * streaming/uncompressed/ */ From patchwork Wed Aug 1 00:29:09 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 10551593 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 28E7D14E0 for ; Wed, 1 Aug 2018 00:28:51 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1A1BF2AFB3 for ; Wed, 1 Aug 2018 00:28:51 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0EACF2B019; Wed, 1 Aug 2018 00:28:51 +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 78E0F2AFB3 for ; Wed, 1 Aug 2018 00:28:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732929AbeHACLj (ORCPT ); Tue, 31 Jul 2018 22:11:39 -0400 Received: from perceval.ideasonboard.com ([213.167.242.64]:33704 "EHLO perceval.ideasonboard.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732880AbeHACLi (ORCPT ); Tue, 31 Jul 2018 22:11:38 -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 1290C1C8D; Wed, 1 Aug 2018 02:28:44 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1533083324; bh=kBvZxpQcV5ujxF1/OQ0sNBvqpQIG8QPHn3x8ypvomHA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=VodqG2WCoHu/dDkgyZpgt526QOAEuGbsbFgMotqhtNb7DLuQ+TqCXOFXF4xR0gkVj KIZf60AO2fzhXkRQv87A0U34HhCDNKb5I8Cy8Egrf/PMfCj4tWhb0BdCU/cRC8cVnS VWLya5rIJS/ZRWKRYEPeOXVe9DOE11VSxzvN3hsw= From: Laurent Pinchart To: linux-usb@vger.kernel.org Cc: Felipe Balbi , Joel Pepper , Kieran Bingham , Andrzej Pietrasiewicz Subject: [PATCH 8/8] usb: gadget: uvc: configfs: Prevent format changes after linking header Date: Wed, 1 Aug 2018 03:29:09 +0300 Message-Id: <20180801002909.2890-9-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.16.4 In-Reply-To: <20180801002909.2890-1-laurent.pinchart@ideasonboard.com> References: <20180801002909.2890-1-laurent.pinchart@ideasonboard.com> 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: Joel Pepper While checks are in place to avoid attributes and children of a format being manipulated after the format is linked into the streaming header, the linked flag was never actually set, invalidating the protections. Signed-off-by: Joel Pepper --- drivers/usb/gadget/function/uvc_configfs.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/drivers/usb/gadget/function/uvc_configfs.c b/drivers/usb/gadget/function/uvc_configfs.c index 9af4cda27865..cac249e8a7ec 100644 --- a/drivers/usb/gadget/function/uvc_configfs.c +++ b/drivers/usb/gadget/function/uvc_configfs.c @@ -901,6 +901,7 @@ static int uvcg_streaming_header_allow_link(struct config_item *src, format_ptr->fmt = target_fmt; list_add_tail(&format_ptr->entry, &src_hdr->formats); ++src_hdr->num_fmt; + ++target_fmt->linked; out: mutex_unlock(&opts->lock); @@ -938,6 +939,8 @@ static void uvcg_streaming_header_drop_link(struct config_item *src, break; } + --target_fmt->linked; + out: mutex_unlock(&opts->lock); mutex_unlock(su_mutex);