Skip to contentSkip to conversation

Staging: emxx_udc: Make a read-only structure

PATCH In review Mihaela Muraru 3 participants 7 messages Oct 18, 2016 – Oct 19, 2016 Staging

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 Staging: emxx_udc: Make a read-only structure

This patch add const qualifier at the declaration of the structure, because it contains information about usb hardware device and those values shoud not be overwritten.

The structure become a read-only data, this increase the security and the integrity of the program.

Found with Coccinelle:
@r disable optional_qualifier@
identifier s,i;
@@
* static struct s i ={...};

---
 drivers/staging/emxx_udc/emxx_udc.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/staging/emxx_udc/emxx_udc.c +1 -1
index c3e2988..8b406f3 100644
@@ -1386,7 +1386,7 @@ static void _nbu2ss_set_endpoint_stall(
 
 /*-------------------------------------------------------------------------*/
 /* Device Descriptor */
-static struct usb_device_descriptor device_desc = {
+static const struct usb_device_descriptor device_desc = {
 	.bLength              = sizeof(device_desc),
 	.bDescriptorType      = USB_DT_DEVICE,
 	.bcdUSB               = cpu_to_le16(0x0200),
Signature · 1 line
2.7.4
#1 lore raw
Quoted 3 lines · Mihaela Muraru

This patch add const qualifier at the declaration of the structure, because it contains information about usb hardware device and those values shoud not be overwritten.

This focuses on the intent, which makes sense, but one really wants to be sure that we won't end up with a const value floating into a modification context, which would cause a runtime error. So it would be good to describe how the structure is used. For example, is it only passed to another function where the corresponding parameter is declared as const?

julia

Quoted 38 lines

The structure become a read-only data, this increase the security and the integrity of the program.

Found with Coccinelle:
@r disable optional_qualifier@
identifier s,i;
@@
* static struct s i ={...};

---
 drivers/staging/emxx_udc/emxx_udc.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/staging/emxx_udc/emxx_udc.c +1 -2
index c3e2988..8b406f3 100644
@@ -1386,7 +1386,7 @@ static void _nbu2ss_set_endpoint_stall(
 
 /*-------------------------------------------------------------------------*/
 /* Device Descriptor */
-static struct usb_device_descriptor device_desc = {
+static const struct usb_device_descriptor device_desc = {
 	.bLength              = sizeof(device_desc),
 	.bDescriptorType      = USB_DT_DEVICE,
 	.bcdUSB               = cpu_to_le16(0x0200),
--

2.7.4

--
You received this message because you are subscribed to the Google Groups "outreachy-kernel" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected].
To view this discussion on the web visit https://groups.google.com/d/msgid/outreachy-kernel/20161018204221.GA7799%40domino-MS-16Y1.
For more options, visit https://groups.google.com/d/optout.

#2 lore raw
Quoted 11 lines · Julia Lawall
Quoted 3 lines · Mihaela Muraru

This patch add const qualifier at the declaration of the structure, because it contains information about usb hardware device and those values shoud not be overwritten.

This focuses on the intent, which makes sense, but one really wants to be sure that we won't end up with a const value floating into a modification context, which would cause a runtime error. So it would be good to describe how the structure is used. For example, is it only passed to another function where the corresponding parameter is declared as const?

The structure is declared and used only in emxx_udc.c. I searched it in all staging driver.

And is passed as a patameter only to the sizeof operetor, that doesn't change the variable of the structure.

To be 100% sure I will search on all the files of the kernel, it would take some time, and I will tell you what is the result, if is ok for you.

mihaela

Quoted 39 lines
Quoted 39 lines

The structure become a read-only data, this increase the security and the integrity of the program.

Found with Coccinelle:
@r disable optional_qualifier@
identifier s,i;
@@
* static struct s i ={...};

---
 drivers/staging/emxx_udc/emxx_udc.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/staging/emxx_udc/emxx_udc.c +1 -2
index c3e2988..8b406f3 100644
@@ -1386,7 +1386,7 @@ static void _nbu2ss_set_endpoint_stall(
 
 /*-------------------------------------------------------------------------*/
 /* Device Descriptor */
-static struct usb_device_descriptor device_desc = {
+static const struct usb_device_descriptor device_desc = {
 	.bLength              = sizeof(device_desc),
 	.bDescriptorType      = USB_DT_DEVICE,
 	.bcdUSB               = cpu_to_le16(0x0200),
--

2.7.4

--
You received this message because you are subscribed to the Google Groups "outreachy-kernel" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected].
To view this discussion on the web visit https://groups.google.com/d/msgid/outreachy-kernel/20161018204221.GA7799%40domino-MS-16Y1.
For more options, visit https://groups.google.com/d/optout.

#3 lore raw
Quoted 16 lines · Muraru Mihaela
Quoted 11 lines · Julia Lawall
Quoted 3 lines · Mihaela Muraru

This patch add const qualifier at the declaration of the structure, because it contains information about usb hardware device and those values shoud not be overwritten.

This focuses on the intent, which makes sense, but one really wants to be sure that we won't end up with a const value floating into a modification context, which would cause a runtime error. So it would be good to describe how the structure is used. For example, is it only passed to another function where the corresponding parameter is declared as const?

The structure is declared and used only in emxx_udc.c. I searched it in all staging driver.

Quoted 6 lines

And is passed as a patameter only to the sizeof operetor, that doesn't change the variable of the structure.

To be 100% sure I will search on all the files of the kernel, it would take some time, and I will tell you what is the result, if is ok for you.

If the structure is static, then there is normally no need to check other files. The question though is how is it used in the current file. Sizeof is indeed not an issue, but what are the other ways in which it is used.

julia

#4 lore raw
Quoted 23 lines · Julia Lawall
Quoted 19 lines · Muraru Mihaela
Quoted 11 lines · Julia Lawall
Quoted 3 lines · Mihaela Muraru

This patch add const qualifier at the declaration of the structure, because it contains information about usb hardware device and those values shoud not be overwritten.

This focuses on the intent, which makes sense, but one really wants to be sure that we won't end up with a const value floating into a modification context, which would cause a runtime error. So it would be good to describe how the structure is used. For example, is it only passed to another function where the corresponding parameter is declared as const?

The structure is declared and used only in emxx_udc.c. I searched it in all staging driver.

And is passed as a patameter only to the sizeof operetor, that doesn't change the variable of the structure.

Quoted 7 lines
Quoted 3 lines

To be 100% sure I will search on all the files of the kernel, it would take some time, and I will tell you what is the result, if is ok for you.

If the structure is static, then there is normally no need to check other files. The question though is how is it used in the current file. Sizeof is indeed not an issue, but what are the other ways in which it is used.

As I mentioned it is not used in the current file. Now, I am wondering why is declared.

mihaela

Quoted 1 line

julia

#5 lore raw
Quoted 28 lines · Muraru Mihaela
Quoted 27 lines · Julia Lawall
Quoted 22 lines · Muraru Mihaela
Quoted 11 lines · Julia Lawall
Quoted 3 lines · Mihaela Muraru

This patch add const qualifier at the declaration of the structure, because it contains information about usb hardware device and those values shoud not be overwritten.

This focuses on the intent, which makes sense, but one really wants to be sure that we won't end up with a const value floating into a modification context, which would cause a runtime error. So it would be good to describe how the structure is used. For example, is it only passed to another function where the corresponding parameter is declared as const?

The structure is declared and used only in emxx_udc.c. I searched it in all staging driver.

And is passed as a patameter only to the sizeof operetor, that doesn't change the variable of the structure.

To be 100% sure I will search on all the files of the kernel, it would take some time, and I will tell you what is the result, if is ok for you.

Quoted 6 lines
Quoted 3 lines

If the structure is static, then there is normally no need to check other files. The question though is how is it used in the current file. Sizeof is indeed not an issue, but what are the other ways in which it is used.

As I mentioned it is not used in the current file. Now, I am wondering why is declared.

Yes, that is odd, does the compiler give you a warning about it when you build the code that it's not being used?

thanks,

greg k-h

#6 lore raw
Quoted 33 lines · Greg Kroah-Hartman
Quoted 32 lines · Muraru Mihaela
Quoted 30 lines · Julia Lawall
Quoted 16 lines · Muraru Mihaela
Quoted 11 lines · Julia Lawall
Quoted 3 lines · Mihaela Muraru

This patch add const qualifier at the declaration of the structure, because it contains information about usb hardware device and those values shoud not be overwritten.

This focuses on the intent, which makes sense, but one really wants to be sure that we won't end up with a const value floating into a modification context, which would cause a runtime error. So it would be good to describe how the structure is used. For example, is it only passed to another function where the corresponding parameter is declared as const?

The structure is declared and used only in emxx_udc.c. I searched it in all staging driver.

Quoted 6 lines

And is passed as a patameter only to the sizeof operetor, that doesn't change the variable of the structure.

To be 100% sure I will search on all the files of the kernel, it would take some time, and I will tell you what is the result, if is ok for you.

If the structure is static, then there is normally no need to check other files. The question though is how is it used in the current file. Sizeof is indeed not an issue, but what are the other ways in which it is used.

Quoted 5 lines
Quoted 2 lines

As I mentioned it is not used in the current file. Now, I am wondering why is declared.

Yes, that is odd, does the compiler give you a warning about it when you build the code that it's not being used?

No, I even delete it and is still compile, without errors.

Quoted 3 lines

thanks,

greg k-h