Skip to contentSkip to conversation

usb: video: fix descriptor structures macros

PATCH In review Sylvain Pelissier 2 participants 6 messages Jan 28, 2021 – Feb 11, 2021 1 message not in the archive USB

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 usb: video: fix descriptor structures macros

The macros defining structures for descriptors use token pasting incorrectly. For example, the macro UVC_EXTENSION_UNIT_DESCRIPTOR(1, 2) defines a structure named uvc_extension_unit_descriptor_p_2 which should be uvc_extension_unit_descriptor_1_2 instead.

---
 include/uapi/linux/usb/video.h | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
include/uapi/linux/usb/video.h +3 -3
index d854cb19c42c..1eb982df87a0 100644
@@ -324,7 +324,7 @@ struct uvc_extension_unit_descriptor {
 #define UVC_DT_EXTENSION_UNIT_SIZE(p, n)		(24+(p)+(n))
 
 #define UVC_EXTENSION_UNIT_DESCRIPTOR(p, n) \
-	uvc_extension_unit_descriptor_##p_##n
+	uvc_extension_unit_descriptor_##p##_##n
 
 #define DECLARE_UVC_EXTENSION_UNIT_DESCRIPTOR(p, n)	\
 struct UVC_EXTENSION_UNIT_DESCRIPTOR(p, n) {		\
@@ -371,7 +371,7 @@ struct uvc_input_header_descriptor {
 #define UVC_DT_INPUT_HEADER_SIZE(n, p)			(13+(n*p))
 
 #define UVC_INPUT_HEADER_DESCRIPTOR(n, p) \
-	uvc_input_header_descriptor_##n_##p
+	uvc_input_header_descriptor_##n##_##p
 
 #define DECLARE_UVC_INPUT_HEADER_DESCRIPTOR(n, p)	\
 struct UVC_INPUT_HEADER_DESCRIPTOR(n, p) {		\
@@ -406,7 +406,7 @@ struct uvc_output_header_descriptor {
 #define UVC_DT_OUTPUT_HEADER_SIZE(n, p)			(9+(n*p))
 
 #define UVC_OUTPUT_HEADER_DESCRIPTOR(n, p) \
-	uvc_output_header_descriptor_##n_##p
+	uvc_output_header_descriptor_##n##_##p
 
 #define DECLARE_UVC_OUTPUT_HEADER_DESCRIPTOR(n, p)	\
 struct UVC_OUTPUT_HEADER_DESCRIPTOR(n, p) {		\
Signature · 1 line
2.25.1
maintainer
#1 lore raw
Quoted 45 lines · Sylvain Pelissier

The macros defining structures for descriptors use token pasting incorrectly. For example, the macro UVC_EXTENSION_UNIT_DESCRIPTOR(1, 2) defines a structure named uvc_extension_unit_descriptor_p_2 which should be uvc_extension_unit_descriptor_1_2 instead.

---
 include/uapi/linux/usb/video.h | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
include/uapi/linux/usb/video.h +3 -3
index d854cb19c42c..1eb982df87a0 100644
@@ -324,7 +324,7 @@ struct uvc_extension_unit_descriptor {
 #define UVC_DT_EXTENSION_UNIT_SIZE(p, n)		(24+(p)+(n))
 
 #define UVC_EXTENSION_UNIT_DESCRIPTOR(p, n) \
-	uvc_extension_unit_descriptor_##p_##n
+	uvc_extension_unit_descriptor_##p##_##n
 
 #define DECLARE_UVC_EXTENSION_UNIT_DESCRIPTOR(p, n)	\
 struct UVC_EXTENSION_UNIT_DESCRIPTOR(p, n) {		\
@@ -371,7 +371,7 @@ struct uvc_input_header_descriptor {
 #define UVC_DT_INPUT_HEADER_SIZE(n, p)			(13+(n*p))
 
 #define UVC_INPUT_HEADER_DESCRIPTOR(n, p) \
-	uvc_input_header_descriptor_##n_##p
+	uvc_input_header_descriptor_##n##_##p
 
 #define DECLARE_UVC_INPUT_HEADER_DESCRIPTOR(n, p)	\
 struct UVC_INPUT_HEADER_DESCRIPTOR(n, p) {		\
@@ -406,7 +406,7 @@ struct uvc_output_header_descriptor {
 #define UVC_DT_OUTPUT_HEADER_SIZE(n, p)			(9+(n*p))
 
 #define UVC_OUTPUT_HEADER_DESCRIPTOR(n, p) \
-	uvc_output_header_descriptor_##n_##p
+	uvc_output_header_descriptor_##n##_##p
 
 #define DECLARE_UVC_OUTPUT_HEADER_DESCRIPTOR(n, p)	\
 struct UVC_OUTPUT_HEADER_DESCRIPTOR(n, p) {		\
Signature · 1 line
2.25.1

And no one noticed this? If not, then why do we have these defines at all, as obviously they are not used :)

thanks,

greg k-h

#2 lore raw
Quoted 42 lines · Greg KH
Quoted 40 lines · Sylvain Pelissier

The macros defining structures for descriptors use token pasting incorrectly. For example, the macro UVC_EXTENSION_UNIT_DESCRIPTOR(1, 2) defines a structure named uvc_extension_unit_descriptor_p_2 which should be uvc_extension_unit_descriptor_1_2 instead.

---
 include/uapi/linux/usb/video.h | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
include/uapi/linux/usb/video.h +3 -3
index d854cb19c42c..1eb982df87a0 100644
@@ -324,7 +324,7 @@ struct uvc_extension_unit_descriptor {
 #define UVC_DT_EXTENSION_UNIT_SIZE(p, n)             (24+(p)+(n))
 
 #define UVC_EXTENSION_UNIT_DESCRIPTOR(p, n) \
-     uvc_extension_unit_descriptor_##p_##n
+     uvc_extension_unit_descriptor_##p##_##n
 
 #define DECLARE_UVC_EXTENSION_UNIT_DESCRIPTOR(p, n)  \
 struct UVC_EXTENSION_UNIT_DESCRIPTOR(p, n) {         \
@@ -371,7 +371,7 @@ struct uvc_input_header_descriptor {
 #define UVC_DT_INPUT_HEADER_SIZE(n, p)                       (13+(n*p))
 
 #define UVC_INPUT_HEADER_DESCRIPTOR(n, p) \
-     uvc_input_header_descriptor_##n_##p
+     uvc_input_header_descriptor_##n##_##p
 
 #define DECLARE_UVC_INPUT_HEADER_DESCRIPTOR(n, p)    \
 struct UVC_INPUT_HEADER_DESCRIPTOR(n, p) {           \
@@ -406,7 +406,7 @@ struct uvc_output_header_descriptor {
 #define UVC_DT_OUTPUT_HEADER_SIZE(n, p)                      (9+(n*p))
 
 #define UVC_OUTPUT_HEADER_DESCRIPTOR(n, p) \
-     uvc_output_header_descriptor_##n_##p
+     uvc_output_header_descriptor_##n##_##p
 
Quoted 8 lines
Quoted 5 lines
include/uapi/linux/usb/video.h +0 -1
 #define DECLARE_UVC_OUTPUT_HEADER_DESCRIPTOR(n, p)   \
 struct UVC_OUTPUT_HEADER_DESCRIPTOR(n, p) {          \
--

2.25.1

And no one noticed this? If not, then why do we have these defines at all, as obviously they are not used :)

The problem is not detected if you have descriptors with the second argument different each time since the structure name will change. It is maybe why it was not noticed. Nevertheless, the extension unit, the input header and the output header descriptors are part of the USB video class specification and are often used by devices. We have detected the problem while implementing a usb gadget having such descriptors.

Quoted 4 lines

thanks,

greg k-h

#3 lore raw
Quoted 53 lines · Sylvain Pelissier
Quoted 42 lines · Greg KH
Quoted 40 lines · Sylvain Pelissier

The macros defining structures for descriptors use token pasting incorrectly. For example, the macro UVC_EXTENSION_UNIT_DESCRIPTOR(1, 2) defines a structure named uvc_extension_unit_descriptor_p_2 which should be uvc_extension_unit_descriptor_1_2 instead.

---
 include/uapi/linux/usb/video.h | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
include/uapi/linux/usb/video.h +3 -3
index d854cb19c42c..1eb982df87a0 100644
@@ -324,7 +324,7 @@ struct uvc_extension_unit_descriptor {
 #define UVC_DT_EXTENSION_UNIT_SIZE(p, n)             (24+(p)+(n))
 
 #define UVC_EXTENSION_UNIT_DESCRIPTOR(p, n) \
-     uvc_extension_unit_descriptor_##p_##n
+     uvc_extension_unit_descriptor_##p##_##n
 
 #define DECLARE_UVC_EXTENSION_UNIT_DESCRIPTOR(p, n)  \
 struct UVC_EXTENSION_UNIT_DESCRIPTOR(p, n) {         \
@@ -371,7 +371,7 @@ struct uvc_input_header_descriptor {
 #define UVC_DT_INPUT_HEADER_SIZE(n, p)                       (13+(n*p))
 
 #define UVC_INPUT_HEADER_DESCRIPTOR(n, p) \
-     uvc_input_header_descriptor_##n_##p
+     uvc_input_header_descriptor_##n##_##p
 
 #define DECLARE_UVC_INPUT_HEADER_DESCRIPTOR(n, p)    \
 struct UVC_INPUT_HEADER_DESCRIPTOR(n, p) {           \
@@ -406,7 +406,7 @@ struct uvc_output_header_descriptor {
 #define UVC_DT_OUTPUT_HEADER_SIZE(n, p)                      (9+(n*p))
 
 #define UVC_OUTPUT_HEADER_DESCRIPTOR(n, p) \
-     uvc_output_header_descriptor_##n_##p
+     uvc_output_header_descriptor_##n##_##p
 
Quoted 8 lines
Quoted 5 lines
include/uapi/linux/usb/video.h +0 -1
 #define DECLARE_UVC_OUTPUT_HEADER_DESCRIPTOR(n, p)   \
 struct UVC_OUTPUT_HEADER_DESCRIPTOR(n, p) {          \
--

2.25.1

And no one noticed this? If not, then why do we have these defines at all, as obviously they are not used :)

Quoted 8 lines

The problem is not detected if you have descriptors with the second argument different each time since the structure name will change. It is maybe why it was not noticed. Nevertheless, the extension unit, the input header and the output header descriptors are part of the USB video class specification and are often used by devices. We have detected the problem while implementing a usb gadget having such descriptors.

Hi,
Do I need to change something for this patch ?
Thanks,

Sylvain

Quoted 4 lines
Quoted 4 lines

thanks,

greg k-h

maintainer
#4 lore raw
Quoted 63 lines · Sylvain Pelissier
Quoted 53 lines · Sylvain Pelissier
Quoted 42 lines · Greg KH
Quoted 40 lines · Sylvain Pelissier

The macros defining structures for descriptors use token pasting incorrectly. For example, the macro UVC_EXTENSION_UNIT_DESCRIPTOR(1, 2) defines a structure named uvc_extension_unit_descriptor_p_2 which should be uvc_extension_unit_descriptor_1_2 instead.

---
 include/uapi/linux/usb/video.h | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
include/uapi/linux/usb/video.h +3 -3
index d854cb19c42c..1eb982df87a0 100644
@@ -324,7 +324,7 @@ struct uvc_extension_unit_descriptor {
 #define UVC_DT_EXTENSION_UNIT_SIZE(p, n)             (24+(p)+(n))
 
 #define UVC_EXTENSION_UNIT_DESCRIPTOR(p, n) \
-     uvc_extension_unit_descriptor_##p_##n
+     uvc_extension_unit_descriptor_##p##_##n
 
 #define DECLARE_UVC_EXTENSION_UNIT_DESCRIPTOR(p, n)  \
 struct UVC_EXTENSION_UNIT_DESCRIPTOR(p, n) {         \
@@ -371,7 +371,7 @@ struct uvc_input_header_descriptor {
 #define UVC_DT_INPUT_HEADER_SIZE(n, p)                       (13+(n*p))
 
 #define UVC_INPUT_HEADER_DESCRIPTOR(n, p) \
-     uvc_input_header_descriptor_##n_##p
+     uvc_input_header_descriptor_##n##_##p
 
 #define DECLARE_UVC_INPUT_HEADER_DESCRIPTOR(n, p)    \
 struct UVC_INPUT_HEADER_DESCRIPTOR(n, p) {           \
@@ -406,7 +406,7 @@ struct uvc_output_header_descriptor {
 #define UVC_DT_OUTPUT_HEADER_SIZE(n, p)                      (9+(n*p))
 
 #define UVC_OUTPUT_HEADER_DESCRIPTOR(n, p) \
-     uvc_output_header_descriptor_##n_##p
+     uvc_output_header_descriptor_##n##_##p
 
Quoted 8 lines
Quoted 5 lines
include/uapi/linux/usb/video.h +0 -1
 #define DECLARE_UVC_OUTPUT_HEADER_DESCRIPTOR(n, p)   \
 struct UVC_OUTPUT_HEADER_DESCRIPTOR(n, p) {          \
--

2.25.1

And no one noticed this? If not, then why do we have these defines at all, as obviously they are not used :)

Quoted 8 lines

The problem is not detected if you have descriptors with the second argument different each time since the structure name will change. It is maybe why it was not noticed. Nevertheless, the extension unit, the input header and the output header descriptors are part of the USB video class specification and are often used by devices. We have detected the problem while implementing a usb gadget having such descriptors.

Quoted 2 lines

Hi,
Do I need to change something for this patch ?

I need an ack from the v4l maintainers before I can take it...

A message that is not in the archive (sent off-list or not yet received): CAOkUe-D2vCFiCp6qqvTTxgi5it+W2rEeXzf3-zu4rji7Cc106w@mail.gmail.com

maintainer
#6 lore raw
Quoted 72 lines · Sylvain Pelissier

Le jeu. 11 févr. 2021 à 13:48, Greg KH <[email protected]> a écrit :

Quoted 69 lines · Sylvain Pelissier
Quoted 4 lines
Quoted 2 lines · Sylvain Pelissier

On Thu, 28 Jan 2021 at 09:22, Greg KH <[email protected]>

Quoted 8 lines · wrote:
Quoted 8 lines
Quoted 8 lines · Sylvain Pelissier
Quoted 6 lines

The macros defining structures for descriptors use token pasting incorrectly. For example, the macro UVC_EXTENSION_UNIT_DESCRIPTOR(1, 2) defines a structure named uvc_extension_unit_descriptor_p_2 which should be uvc_extension_unit_descriptor_1_2 instead.

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines

Review

Quoted 6 lines
---
 include/uapi/linux/usb/video.h | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
(quoted diff) +0 -0

b/include/uapi/linux/usb/video.h

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines

index d854cb19c42c..1eb982df87a0 100644

include/uapi/linux/usb/video.h +0 -0
@@ -324,7 +324,7 @@ struct uvc_extension_unit_descriptor {
 #define UVC_DT_EXTENSION_UNIT_SIZE(p, n)             (24+(p)+(n))
 
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

include/uapi/linux/usb/video.h struct uvc_input_header_descriptor { · line 371

Quoted 8 lines
include/uapi/linux/usb/video.h +1 -1
 #define UVC_EXTENSION_UNIT_DESCRIPTOR(p, n) \
-     uvc_extension_unit_descriptor_##p_##n
+     uvc_extension_unit_descriptor_##p##_##n
 
 #define DECLARE_UVC_EXTENSION_UNIT_DESCRIPTOR(p, n)  \
 struct UVC_EXTENSION_UNIT_DESCRIPTOR(p, n) {         \
@@ -371,7 +371,7 @@ struct uvc_input_header_descriptor {
 #define UVC_DT_INPUT_HEADER_SIZE(n, p)

(13+(n*p))

Quoted 9 lines
Quoted 9 lines
Quoted 9 lines

include/uapi/linux/usb/video.h struct uvc_output_header_descriptor { · line 406

Quoted 9 lines
include/uapi/linux/usb/video.h +1 -1
 #define UVC_INPUT_HEADER_DESCRIPTOR(n, p) \
-     uvc_input_header_descriptor_##n_##p
+     uvc_input_header_descriptor_##n##_##p
 
 #define DECLARE_UVC_INPUT_HEADER_DESCRIPTOR(n, p)    \
 struct UVC_INPUT_HEADER_DESCRIPTOR(n, p) {           \
@@ -406,7 +406,7 @@ struct uvc_output_header_descriptor {
 #define UVC_DT_OUTPUT_HEADER_SIZE(n, p)

(9+(n*p))

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
include/uapi/linux/usb/video.h +1 -1
 #define UVC_OUTPUT_HEADER_DESCRIPTOR(n, p) \
-     uvc_output_header_descriptor_##n_##p
+     uvc_output_header_descriptor_##n##_##p
 
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 5 lines
include/uapi/linux/usb/video.h +0 -1
 #define DECLARE_UVC_OUTPUT_HEADER_DESCRIPTOR(n, p)   \
 struct UVC_OUTPUT_HEADER_DESCRIPTOR(n, p) {          \
--

2.25.1

And no one noticed this? If not, then why do we have these defines

at

Quoted 10 lines
Quoted 10 lines
Quoted 1 line

all, as obviously they are not used :)

The problem is not detected if you have descriptors with the second argument different each time since the structure name will change. It is maybe why it was not noticed. Nevertheless, the extension unit, the input header and the output header descriptors are part of the USB video class specification and are often used by devices. We have detected the problem while implementing a usb gadget having such descriptors.

Quoted 7 lines
Quoted 5 lines
Quoted 2 lines

Hi,
Do I need to change something for this patch ?

I need an ack from the v4l maintainers before I can take it...

Do I need to add someone in cc in particular?

I think Laurent is the proper one here as he's the maintainer for the usb v4l driver, right?

thanks,

greg k-h