UPSTREAM: usb: gadget: uvc: track frames in format entries
Just like the header is tracking the formats in a linked list, in this patch we track the frames in a linked list of the formats. It simplifies the parsing of the configfs structure. Signed-off-by: Michael Grzeschik <m.grzeschik@pengutronix.de> Link: https://lore.kernel.org/r/20220421211427.3400834-6-m.grzeschik@pengutronix.de Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org> (cherry picked from commit a2673d570bd648851e00ac531bdf695f4ebb4f78) Bug: 242344221 Change-Id: I8d3e4ba5b13cad2f195400ef4de5c8e196e25a8a Signed-off-by: Avichal Rakesh <arakesh@google.com> (cherry picked from commit f58be91ef2c9ec0e286b9dce3c0b3f5f5fd8e4f6)
This commit is contained in:
committed by
Avichal Rakesh
parent
eda3367af0
commit
efcf547e6c
@@ -1262,6 +1262,7 @@ static struct config_item *uvcg_frame_make(struct config_group *group,
|
|||||||
struct uvcg_format *fmt;
|
struct uvcg_format *fmt;
|
||||||
struct f_uvc_opts *opts;
|
struct f_uvc_opts *opts;
|
||||||
struct config_item *opts_item;
|
struct config_item *opts_item;
|
||||||
|
struct uvcg_frame_ptr *frame_ptr;
|
||||||
|
|
||||||
h = kzalloc(sizeof(*h), GFP_KERNEL);
|
h = kzalloc(sizeof(*h), GFP_KERNEL);
|
||||||
if (!h)
|
if (!h)
|
||||||
@@ -1292,6 +1293,16 @@ static struct config_item *uvcg_frame_make(struct config_group *group,
|
|||||||
kfree(h);
|
kfree(h);
|
||||||
return ERR_PTR(-EINVAL);
|
return ERR_PTR(-EINVAL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
frame_ptr = kzalloc(sizeof(*frame_ptr), GFP_KERNEL);
|
||||||
|
if (!frame_ptr) {
|
||||||
|
mutex_unlock(&opts->lock);
|
||||||
|
kfree(h);
|
||||||
|
return ERR_PTR(-ENOMEM);
|
||||||
|
}
|
||||||
|
|
||||||
|
frame_ptr->frm = h;
|
||||||
|
list_add_tail(&frame_ptr->entry, &fmt->frames);
|
||||||
++fmt->num_frames;
|
++fmt->num_frames;
|
||||||
mutex_unlock(&opts->lock);
|
mutex_unlock(&opts->lock);
|
||||||
|
|
||||||
@@ -1305,13 +1316,23 @@ static void uvcg_frame_drop(struct config_group *group, struct config_item *item
|
|||||||
struct uvcg_format *fmt;
|
struct uvcg_format *fmt;
|
||||||
struct f_uvc_opts *opts;
|
struct f_uvc_opts *opts;
|
||||||
struct config_item *opts_item;
|
struct config_item *opts_item;
|
||||||
|
struct uvcg_frame *target_frm = NULL;
|
||||||
|
struct uvcg_frame_ptr *frame_ptr, *tmp;
|
||||||
|
|
||||||
opts_item = 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);
|
opts = to_f_uvc_opts(opts_item);
|
||||||
|
|
||||||
mutex_lock(&opts->lock);
|
mutex_lock(&opts->lock);
|
||||||
|
target_frm = container_of(item, struct uvcg_frame, item);
|
||||||
fmt = to_uvcg_format(&group->cg_item);
|
fmt = to_uvcg_format(&group->cg_item);
|
||||||
--fmt->num_frames;
|
|
||||||
|
list_for_each_entry_safe(frame_ptr, tmp, &fmt->frames, entry)
|
||||||
|
if (frame_ptr->frm == target_frm) {
|
||||||
|
list_del(&frame_ptr->entry);
|
||||||
|
kfree(frame_ptr);
|
||||||
|
--fmt->num_frames;
|
||||||
|
break;
|
||||||
|
}
|
||||||
mutex_unlock(&opts->lock);
|
mutex_unlock(&opts->lock);
|
||||||
|
|
||||||
config_item_put(item);
|
config_item_put(item);
|
||||||
@@ -1556,6 +1577,7 @@ static struct config_group *uvcg_uncompressed_make(struct config_group *group,
|
|||||||
h->desc.bmInterfaceFlags = 0;
|
h->desc.bmInterfaceFlags = 0;
|
||||||
h->desc.bCopyProtect = 0;
|
h->desc.bCopyProtect = 0;
|
||||||
|
|
||||||
|
INIT_LIST_HEAD(&h->fmt.frames);
|
||||||
h->fmt.type = UVCG_UNCOMPRESSED;
|
h->fmt.type = UVCG_UNCOMPRESSED;
|
||||||
config_group_init_type_name(&h->fmt.group, name,
|
config_group_init_type_name(&h->fmt.group, name,
|
||||||
&uvcg_uncompressed_type);
|
&uvcg_uncompressed_type);
|
||||||
@@ -1736,6 +1758,7 @@ static struct config_group *uvcg_mjpeg_make(struct config_group *group,
|
|||||||
h->desc.bmInterfaceFlags = 0;
|
h->desc.bmInterfaceFlags = 0;
|
||||||
h->desc.bCopyProtect = 0;
|
h->desc.bCopyProtect = 0;
|
||||||
|
|
||||||
|
INIT_LIST_HEAD(&h->fmt.frames);
|
||||||
h->fmt.type = UVCG_MJPEG;
|
h->fmt.type = UVCG_MJPEG;
|
||||||
config_group_init_type_name(&h->fmt.group, name,
|
config_group_init_type_name(&h->fmt.group, name,
|
||||||
&uvcg_mjpeg_type);
|
&uvcg_mjpeg_type);
|
||||||
|
|||||||
@@ -46,6 +46,7 @@ struct uvcg_format {
|
|||||||
struct config_group group;
|
struct config_group group;
|
||||||
enum uvcg_format_type type;
|
enum uvcg_format_type type;
|
||||||
unsigned linked;
|
unsigned linked;
|
||||||
|
struct list_head frames;
|
||||||
unsigned num_frames;
|
unsigned num_frames;
|
||||||
__u8 bmaControls[UVCG_STREAMING_CONTROL_SIZE];
|
__u8 bmaControls[UVCG_STREAMING_CONTROL_SIZE];
|
||||||
};
|
};
|
||||||
@@ -73,6 +74,11 @@ static inline struct uvcg_streaming_header *to_uvcg_streaming_header(struct conf
|
|||||||
return container_of(item, struct uvcg_streaming_header, item);
|
return container_of(item, struct uvcg_streaming_header, item);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
struct uvcg_frame_ptr {
|
||||||
|
struct uvcg_frame *frm;
|
||||||
|
struct list_head entry;
|
||||||
|
};
|
||||||
|
|
||||||
struct uvcg_frame {
|
struct uvcg_frame {
|
||||||
struct config_item item;
|
struct config_item item;
|
||||||
enum uvcg_format_type fmt_type;
|
enum uvcg_format_type fmt_type;
|
||||||
|
|||||||
Reference in New Issue
Block a user