diff options
author | Dan Carpenter <dan.carpenter@oracle.com> | 2015-01-14 16:06:35 -0500 |
---|---|---|
committer | Felipe Balbi <balbi@ti.com> | 2015-01-19 13:53:31 -0500 |
commit | 3c4c733ca9e3f88e3107b6e23b9789bf7769e1f4 (patch) | |
tree | 611b1f06e887d87bcbd2e35a4b11b1392a9bb957 /drivers/usb/gadget/function | |
parent | c5b2dc68a7a7e31d8e88b3bf9d45bd9e78e9fb78 (diff) |
usb: gadget: uvc: cleanup UVCG_FRAME_ATTR macro
1) Change "conv" an "vnoc" to "to_cpu_endian" to "to_little_endian".
2) No need to check the "limit" because that is already handled in
kstrtoXX so delete that parameter along with the check.
3) By using a "bits" parameter, we can combine the "uxx" parameter and
the "str2u" parameters.
4) The kstrtou##bits() conversion does not need to be done under the
mutex so move it to the start of the function.
5) Change the name of "identity_conv" to "noop_conversion".
Acked-by: Andrzej Pietrasiewicz <andrzej.p@samsung.com>
Acked-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
Signed-off-by: Felipe Balbi <balbi@ti.com>
Diffstat (limited to 'drivers/usb/gadget/function')
-rw-r--r-- | drivers/usb/gadget/function/uvc_configfs.c | 44 |
1 files changed, 18 insertions, 26 deletions
diff --git a/drivers/usb/gadget/function/uvc_configfs.c b/drivers/usb/gadget/function/uvc_configfs.c index 09028d21a3b6..cc2a6139b2c8 100644 --- a/drivers/usb/gadget/function/uvc_configfs.c +++ b/drivers/usb/gadget/function/uvc_configfs.c | |||
@@ -1030,7 +1030,7 @@ static struct configfs_item_operations uvcg_frame_item_ops = { | |||
1030 | .store_attribute = uvcg_frame_attr_store, | 1030 | .store_attribute = uvcg_frame_attr_store, |
1031 | }; | 1031 | }; |
1032 | 1032 | ||
1033 | #define UVCG_FRAME_ATTR(cname, aname, conv, str2u, uxx, vnoc, limit) \ | 1033 | #define UVCG_FRAME_ATTR(cname, aname, to_cpu_endian, to_little_endian, bits) \ |
1034 | static ssize_t uvcg_frame_##cname##_show(struct uvcg_frame *f, char *page)\ | 1034 | static ssize_t uvcg_frame_##cname##_show(struct uvcg_frame *f, char *page)\ |
1035 | { \ | 1035 | { \ |
1036 | struct f_uvc_opts *opts; \ | 1036 | struct f_uvc_opts *opts; \ |
@@ -1044,7 +1044,7 @@ static ssize_t uvcg_frame_##cname##_show(struct uvcg_frame *f, char *page)\ | |||
1044 | opts = to_f_uvc_opts(opts_item); \ | 1044 | opts = to_f_uvc_opts(opts_item); \ |
1045 | \ | 1045 | \ |
1046 | mutex_lock(&opts->lock); \ | 1046 | mutex_lock(&opts->lock); \ |
1047 | result = sprintf(page, "%d\n", conv(f->frame.cname)); \ | 1047 | result = sprintf(page, "%d\n", to_cpu_endian(f->frame.cname)); \ |
1048 | mutex_unlock(&opts->lock); \ | 1048 | mutex_unlock(&opts->lock); \ |
1049 | \ | 1049 | \ |
1050 | mutex_unlock(su_mutex); \ | 1050 | mutex_unlock(su_mutex); \ |
@@ -1059,7 +1059,11 @@ static ssize_t uvcg_frame_##cname##_store(struct uvcg_frame *f, \ | |||
1059 | struct uvcg_format *fmt; \ | 1059 | struct uvcg_format *fmt; \ |
1060 | struct mutex *su_mutex = &f->item.ci_group->cg_subsys->su_mutex;\ | 1060 | struct mutex *su_mutex = &f->item.ci_group->cg_subsys->su_mutex;\ |
1061 | int ret; \ | 1061 | int ret; \ |
1062 | uxx num; \ | 1062 | u##bits num; \ |
1063 | \ | ||
1064 | ret = kstrtou##bits(page, 0, &num); \ | ||
1065 | if (ret) \ | ||
1066 | return ret; \ | ||
1063 | \ | 1067 | \ |
1064 | mutex_lock(su_mutex); /* for navigating configfs hierarchy */ \ | 1068 | mutex_lock(su_mutex); /* for navigating configfs hierarchy */ \ |
1065 | \ | 1069 | \ |
@@ -1073,15 +1077,7 @@ static ssize_t uvcg_frame_##cname##_store(struct uvcg_frame *f, \ | |||
1073 | goto end; \ | 1077 | goto end; \ |
1074 | } \ | 1078 | } \ |
1075 | \ | 1079 | \ |
1076 | ret = str2u(page, 0, &num); \ | 1080 | f->frame.cname = to_little_endian(num); \ |
1077 | if (ret) \ | ||
1078 | goto end; \ | ||
1079 | \ | ||
1080 | if (num > limit) { \ | ||
1081 | ret = -EINVAL; \ | ||
1082 | goto end; \ | ||
1083 | } \ | ||
1084 | f->frame.cname = vnoc(num); \ | ||
1085 | ret = len; \ | 1081 | ret = len; \ |
1086 | end: \ | 1082 | end: \ |
1087 | mutex_unlock(&opts->lock); \ | 1083 | mutex_unlock(&opts->lock); \ |
@@ -1095,24 +1091,20 @@ static struct uvcg_frame_attribute \ | |||
1095 | uvcg_frame_##cname##_show, \ | 1091 | uvcg_frame_##cname##_show, \ |
1096 | uvcg_frame_##cname##_store) | 1092 | uvcg_frame_##cname##_store) |
1097 | 1093 | ||
1098 | #define identity_conv(x) (x) | 1094 | #define noop_conversion(x) (x) |
1099 | 1095 | ||
1100 | UVCG_FRAME_ATTR(bm_capabilities, bmCapabilities, identity_conv, kstrtou8, u8, | 1096 | UVCG_FRAME_ATTR(bm_capabilities, bmCapabilities, noop_conversion, |
1101 | identity_conv, 0xFF); | 1097 | noop_conversion, 8); |
1102 | UVCG_FRAME_ATTR(w_width, wWidth, le16_to_cpu, kstrtou16, u16, cpu_to_le16, | 1098 | UVCG_FRAME_ATTR(w_width, wWidth, le16_to_cpu, cpu_to_le16, 16); |
1103 | 0xFFFF); | 1099 | UVCG_FRAME_ATTR(w_height, wHeight, le16_to_cpu, cpu_to_le16, 16); |
1104 | UVCG_FRAME_ATTR(w_height, wHeight, le16_to_cpu, kstrtou16, u16, cpu_to_le16, | 1100 | UVCG_FRAME_ATTR(dw_min_bit_rate, dwMinBitRate, le32_to_cpu, cpu_to_le32, 32); |
1105 | 0xFFFF); | 1101 | UVCG_FRAME_ATTR(dw_max_bit_rate, dwMaxBitRate, le32_to_cpu, cpu_to_le32, 32); |
1106 | UVCG_FRAME_ATTR(dw_min_bit_rate, dwMinBitRate, le32_to_cpu, kstrtou32, u32, | ||
1107 | cpu_to_le32, 0xFFFFFFFF); | ||
1108 | UVCG_FRAME_ATTR(dw_max_bit_rate, dwMaxBitRate, le32_to_cpu, kstrtou32, u32, | ||
1109 | cpu_to_le32, 0xFFFFFFFF); | ||
1110 | UVCG_FRAME_ATTR(dw_max_video_frame_buffer_size, dwMaxVideoFrameBufferSize, | 1102 | UVCG_FRAME_ATTR(dw_max_video_frame_buffer_size, dwMaxVideoFrameBufferSize, |
1111 | le32_to_cpu, kstrtou32, u32, cpu_to_le32, 0xFFFFFFFF); | 1103 | le32_to_cpu, cpu_to_le32, 32); |
1112 | UVCG_FRAME_ATTR(dw_default_frame_interval, dwDefaultFrameInterval, | 1104 | UVCG_FRAME_ATTR(dw_default_frame_interval, dwDefaultFrameInterval, |
1113 | le32_to_cpu, kstrtou32, u32, cpu_to_le32, 0xFFFFFFFF); | 1105 | le32_to_cpu, cpu_to_le32, 32); |
1114 | 1106 | ||
1115 | #undef identity_conv | 1107 | #undef noop_conversion |
1116 | 1108 | ||
1117 | #undef UVCG_FRAME_ATTR | 1109 | #undef UVCG_FRAME_ATTR |
1118 | 1110 | ||