[PATCH 1/8] usb: gadget: uvc: configfs: Don't wrap groups unnecessarily
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 --- 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_CAM
Re: [PATCH 1/8] usb: gadget: uvc: configfs: Don't wrap groups unnecessarily
Hi Laurent, Thank you for the patch, On 01/08/18 01:29, Laurent Pinchart wrote: > Various configfs groups (represented by config_group) as wrapped in /as wrapped/are wrapped/ > structures that they're the only member of. This allows adding other > data fields to groups, but is unnecessarily makes the code more complex. s/is/it/ > Remove the outter structures and use config_group directly to simplify /outter/outer/ > the code. Groups can still be wrapped individually in the future if > other data fields need to be added. > > Signed-off-by: Laurent Pinchart phew. Well that is some terse reading of macro modifications. But except for the trivial spellings above, I can't see anything wrong. And this definitely moves the right way :D 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