Skip to contentSkip to conversation

mei: Avoid the use of one-element arrays

PATCH In review Gustavo A. R. Silva 4 participants 8 messages Jul 14, 2020 – Jul 22, 2020

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 mei: Avoid the use of one-element arrays

One-element arrays are being deprecated[1]. Replace the one-element arrays with a simple value type u8 reserved, once this is just a placeholder for alignment.

Also, while there, use the preferred form for passing a size of a struct. The alternative form where struct name is spelled out hurts readability and introduces an opportunity for a bug when the variable type is changed but the corresponding sizeof that is passed as argument is not.

[1] https://github.com/KSPP/linux/issues/79

---
Changes in v2:
- Use a more concise changelog text.

 drivers/misc/mei/hbm.c | 4 ++--
 drivers/misc/mei/hw.h  | 6 +++---
 2 files changed, 5 insertions(+), 5 deletions(-)
drivers/misc/mei/hbm.c +2 -2
index a44094cdbc36..f020d5594154 100644
@@ -408,14 +408,14 @@ static int mei_hbm_add_cl_resp(struct mei_device *dev, u8 addr, u8 status)
 {
 	struct mei_msg_hdr mei_hdr;
 	struct hbm_add_client_response resp;
-	const size_t len = sizeof(struct hbm_add_client_response);
+	const size_t len = sizeof(resp);
 	int ret;
 
 	dev_dbg(dev->dev, "adding client response\n");
 
 	mei_hbm_hdr(&mei_hdr, len);
 
-	memset(&resp, 0, sizeof(struct hbm_add_client_response));
+	memset(&resp, 0, len);
 	resp.hbm_cmd = MEI_HBM_ADD_CLIENT_RES_CMD;
 	resp.me_addr = addr;
 	resp.status  = status;
drivers/misc/mei/hw.h +3 -3
index b1a8d5ec88b3..8c0297f0e7f3 100644
@@ -346,13 +346,13 @@ struct hbm_add_client_request {
  * @hbm_cmd: bus message command header
  * @me_addr: address of the client in ME
  * @status: if HBMS_SUCCESS then the client can now accept connections.
- * @reserved: reserved
+ * @reserved: reserved for alignment.
  */
 struct hbm_add_client_response {
 	u8 hbm_cmd;
 	u8 me_addr;
 	u8 status;
-	u8 reserved[1];
+	u8 reserved;
 } __packed;
 
 /**
@@ -461,7 +461,7 @@ struct hbm_notification {
 	u8 hbm_cmd;
 	u8 me_addr;
 	u8 host_addr;
-	u8 reserved[1];
+	u8 reserved;
 } __packed;
 
 /**
Signature · 1 line
2.27.0
#1 lore raw

Hi all,

Friendly ping: who can take this? :)

Thanks
--
Gustavo

Quoted 71 lines · Gustavo A. R. Silva

One-element arrays are being deprecated[1]. Replace the one-element arrays with a simple value type u8 reserved, once this is just a placeholder for alignment.

Also, while there, use the preferred form for passing a size of a struct. The alternative form where struct name is spelled out hurts readability and introduces an opportunity for a bug when the variable type is changed but the corresponding sizeof that is passed as argument is not.

[1] https://github.com/KSPP/linux/issues/79

---
Changes in v2:
- Use a more concise changelog text.

 drivers/misc/mei/hbm.c | 4 ++--
 drivers/misc/mei/hw.h  | 6 +++---
 2 files changed, 5 insertions(+), 5 deletions(-)
drivers/misc/mei/hbm.c +2 -2
index a44094cdbc36..f020d5594154 100644
@@ -408,14 +408,14 @@ static int mei_hbm_add_cl_resp(struct mei_device *dev, u8 addr, u8 status)
 {
 	struct mei_msg_hdr mei_hdr;
 	struct hbm_add_client_response resp;
-	const size_t len = sizeof(struct hbm_add_client_response);
+	const size_t len = sizeof(resp);
 	int ret;
 
 	dev_dbg(dev->dev, "adding client response\n");
 
 	mei_hbm_hdr(&mei_hdr, len);
 
-	memset(&resp, 0, sizeof(struct hbm_add_client_response));
+	memset(&resp, 0, len);
 	resp.hbm_cmd = MEI_HBM_ADD_CLIENT_RES_CMD;
 	resp.me_addr = addr;
 	resp.status  = status;
drivers/misc/mei/hw.h +3 -3
index b1a8d5ec88b3..8c0297f0e7f3 100644
@@ -346,13 +346,13 @@ struct hbm_add_client_request {
  * @hbm_cmd: bus message command header
  * @me_addr: address of the client in ME
  * @status: if HBMS_SUCCESS then the client can now accept connections.
- * @reserved: reserved
+ * @reserved: reserved for alignment.
  */
 struct hbm_add_client_response {
 	u8 hbm_cmd;
 	u8 me_addr;
 	u8 status;
-	u8 reserved[1];
+	u8 reserved;
 } __packed;
 
 /**
@@ -461,7 +461,7 @@ struct hbm_notification {
 	u8 hbm_cmd;
 	u8 me_addr;
 	u8 host_addr;
-	u8 reserved[1];
+	u8 reserved;
 } __packed;
 
 /**
#2 lore raw
Quoted 3 lines · Gustavo A. R. Silva

Hi all,

Friendly ping: who can take this? :)

I will, give me a chance...

#3 lore raw

Hey Greg,

Quoted 7 lines · Greg Kroah-Hartman
Quoted 3 lines · Gustavo A. R. Silva

Hi all,

Friendly ping: who can take this? :)

I will, give me a chance...

Oops, sorry... I just wanted to make sure this makes it to 5.9-rc1. :)

Thanks!
--
Gustavo

#4 lore raw
In reply to Gustavo A. R. Silva
Quoted 46 lines

Hi all,

Friendly ping: who can take this? :)

Thanks
--
Gustavo

Quoted 8 lines · Gustavo A. R. Silva

One-element arrays are being deprecated[1]. Replace the one-element arrays with a simple value type u8 reserved, once this is just a placeholder for alignment.

Also, while there, use the preferred form for passing a size of a struct. The alternative form where struct name is spelled out hurts readability and introduces an opportunity for a bug when the variable type is changed but the corresponding sizeof that is passed as argument is

not.

Quoted 26 lines

[1] https://github.com/KSPP/linux/issues/79

---
Changes in v2:
- Use a more concise changelog text.

 drivers/misc/mei/hbm.c | 4 ++--
 drivers/misc/mei/hw.h  | 6 +++---
 2 files changed, 5 insertions(+), 5 deletions(-)
drivers/misc/mei/hbm.c index renamed from drivers/misc/mei/hbm.c +0 -0

a44094cdbc36..f020d5594154 100644

drivers/misc/mei/hbm.c +1 -1
@@ -408,14 +408,14 @@ static int mei_hbm_add_cl_resp(struct mei_device
 *dev, u8 addr, u8 status)  {
 	struct mei_msg_hdr mei_hdr;
 	struct hbm_add_client_response resp;
-	const size_t len = sizeof(struct hbm_add_client_response);
+	const size_t len = sizeof(resp);
 	int ret;
 
 	dev_dbg(dev->dev, "adding client response\n");
 
Quoted 7 lines

drivers/misc/mei/hbm.c static int mei_hbm_add_cl_resp(struct mei_device *dev, u8 addr, u8 status) · line 421

Quoted 7 lines
drivers/misc/mei/hbm.c +1 -1
 	mei_hbm_hdr(&mei_hdr, len);
 
-	memset(&resp, 0, sizeof(struct hbm_add_client_response));
+	memset(&resp, 0, len);
 	resp.hbm_cmd = MEI_HBM_ADD_CLIENT_RES_CMD;
 	resp.me_addr = addr;
 	resp.status  = status;

This should be probably in a different patch it's not related to the second part.

Quoted 4 lines

drivers/misc/mei/hw.h

Quoted 4 lines
drivers/misc/mei/hw.h index renamed from drivers/misc/mei/hw.h +0 -0

b1a8d5ec88b3..8c0297f0e7f3 100644

drivers/misc/mei/hw.h +0 -0

I have second thoughts of this part as all reserved fields in this file are of form u8 reserved[X], so we will lose that uniformity with this change, you have to look at the file as whole not just at the patch. So I prefer we drop that part of the patch.

Quoted 26 lines
Quoted 26 lines
drivers/misc/mei/hw.h +3 -3
@@ -346,13 +346,13 @@ struct hbm_add_client_request {
  * @hbm_cmd: bus message command header
  * @me_addr: address of the client in ME
  * @status: if HBMS_SUCCESS then the client can now accept connections.
- * @reserved: reserved
+ * @reserved: reserved for alignment.
  */
 struct hbm_add_client_response {
 	u8 hbm_cmd;
 	u8 me_addr;
 	u8 status;
-	u8 reserved[1];
+	u8 reserved;
 } __packed;
 
 /**
@@ -461,7 +461,7 @@ struct hbm_notification {
 	u8 hbm_cmd;
 	u8 me_addr;
 	u8 host_addr;
-	u8 reserved[1];
+	u8 reserved;
 } __packed;
 
 /**
#5 lore raw

Hi Tomas,

Please, see my comments below...

Quoted 56 lines · Tomas
Quoted 46 lines

Hi all,

Friendly ping: who can take this? :)

Thanks
--
Gustavo

Quoted 8 lines · Gustavo A. R. Silva

One-element arrays are being deprecated[1]. Replace the one-element arrays with a simple value type u8 reserved, once this is just a placeholder for alignment.

Also, while there, use the preferred form for passing a size of a struct. The alternative form where struct name is spelled out hurts readability and introduces an opportunity for a bug when the variable type is changed but the corresponding sizeof that is passed as argument is

not.

Quoted 26 lines

[1] https://github.com/KSPP/linux/issues/79

---
Changes in v2:
- Use a more concise changelog text.

 drivers/misc/mei/hbm.c | 4 ++--
 drivers/misc/mei/hw.h  | 6 +++---
 2 files changed, 5 insertions(+), 5 deletions(-)
drivers/misc/mei/hbm.c index renamed from drivers/misc/mei/hbm.c +0 -0

a44094cdbc36..f020d5594154 100644

drivers/misc/mei/hbm.c +1 -1
@@ -408,14 +408,14 @@ static int mei_hbm_add_cl_resp(struct mei_device
 *dev, u8 addr, u8 status)  {
 	struct mei_msg_hdr mei_hdr;
 	struct hbm_add_client_response resp;
-	const size_t len = sizeof(struct hbm_add_client_response);
+	const size_t len = sizeof(resp);
 	int ret;
 
 	dev_dbg(dev->dev, "adding client response\n");
 
Quoted 7 lines

drivers/misc/mei/hbm.c static int mei_hbm_add_cl_resp(struct mei_device *dev, u8 addr, u8 status) · line 421

Quoted 7 lines
drivers/misc/mei/hbm.c +1 -1
 	mei_hbm_hdr(&mei_hdr, len);
 
-	memset(&resp, 0, sizeof(struct hbm_add_client_response));
+	memset(&resp, 0, len);
 	resp.hbm_cmd = MEI_HBM_ADD_CLIENT_RES_CMD;
 	resp.me_addr = addr;
 	resp.status  = status;

This should be probably in a different patch it's not related to the second part.

Quoted 8 lines
Quoted 4 lines

drivers/misc/mei/hw.h

Quoted 4 lines
drivers/misc/mei/hw.h index renamed from drivers/misc/mei/hw.h +0 -0

b1a8d5ec88b3..8c0297f0e7f3 100644

drivers/misc/mei/hw.h +0 -0

I have second thoughts of this part as all reserved fields in this file are of form u8 reserved[X], so we will lose that uniformity with this change, you have to look at the file as whole not just at the patch. So I prefer we drop that part of the patch.

This is actually the main point of this patch: the removal of one-element arrays. And yeah, every place in the kernel that uses the form that you mention will see it's uniformity slightly modified, and that's for a good cause: the removal of one-element arrays, so we can enable bounds checking.

Thanks
--
Gustavo

Quoted 26 lines
Quoted 26 lines
Quoted 26 lines
drivers/misc/mei/hw.h +3 -3
@@ -346,13 +346,13 @@ struct hbm_add_client_request {
  * @hbm_cmd: bus message command header
  * @me_addr: address of the client in ME
  * @status: if HBMS_SUCCESS then the client can now accept connections.
- * @reserved: reserved
+ * @reserved: reserved for alignment.
  */
 struct hbm_add_client_response {
 	u8 hbm_cmd;
 	u8 me_addr;
 	u8 status;
-	u8 reserved[1];
+	u8 reserved;
 } __packed;
 
 /**
@@ -461,7 +461,7 @@ struct hbm_notification {
 	u8 hbm_cmd;
 	u8 me_addr;
 	u8 host_addr;
-	u8 reserved[1];
+	u8 reserved;
 } __packed;
 
 /**
#6 lore raw
Quoted 55 lines

Hi Tomas,

Please, see my comments below...

Quoted 49 lines · Tomas
Quoted 49 lines

Hi all,

Friendly ping: who can take this? :)

Thanks
--
Gustavo

Quoted 9 lines · Gustavo A. R. Silva

One-element arrays are being deprecated[1]. Replace the one-element arrays with a simple value type u8 reserved, once this is just a placeholder for alignment.

Also, while there, use the preferred form for passing a size of a struct. The alternative form where struct name is spelled out hurts readability and introduces an opportunity for a bug when the variable type is changed but the corresponding sizeof that is passed as argument is

not.

Quoted 28 lines

[1] https://github.com/KSPP/linux/issues/79

---
Changes in v2:
- Use a more concise changelog text.

 drivers/misc/mei/hbm.c | 4 ++--
 drivers/misc/mei/hw.h  | 6 +++---
 2 files changed, 5 insertions(+), 5 deletions(-)
drivers/misc/mei/hbm.c index renamed from drivers/misc/mei/hbm.c +0 -0

a44094cdbc36..f020d5594154 100644

drivers/misc/mei/hbm.c +1 -1
@@ -408,14 +408,14 @@ static int mei_hbm_add_cl_resp(struct
 mei_device *dev, u8 addr, u8 status)  {
 	struct mei_msg_hdr mei_hdr;
 	struct hbm_add_client_response resp;
-	const size_t len = sizeof(struct hbm_add_client_response);
+	const size_t len = sizeof(resp);
 	int ret;
 
 	dev_dbg(dev->dev, "adding client response\n");
 
 	mei_hbm_hdr(&mei_hdr, len);
 
Quoted 8 lines
Quoted 7 lines
Quoted 5 lines

drivers/misc/mei/hbm.c static int mei_hbm_add_cl_resp(struct mei_device *dev, u8 addr, u8 status) · line 421

Quoted 5 lines
drivers/misc/mei/hbm.c +1 -1
-	memset(&resp, 0, sizeof(struct hbm_add_client_response));
+	memset(&resp, 0, len);
 	resp.hbm_cmd = MEI_HBM_ADD_CLIENT_RES_CMD;
 	resp.me_addr = addr;
 	resp.status  = status;

This should be probably in a different patch it's not related to the second

part.

Frankly I will post other version of this that cleans the whole file.

Quoted 8 lines
Quoted 8 lines
Quoted 5 lines

drivers/misc/mei/hw.h

Quoted 5 lines
drivers/misc/mei/hw.h index renamed from drivers/misc/mei/hw.h +0 -0

b1a8d5ec88b3..8c0297f0e7f3 100644

drivers/misc/mei/hw.h +0 -0

I have second thoughts of this part as all reserved fields in this file are of form u8 reserved[X], so we will lose that uniformity with this change, you have to look at the file as whole not just at the patch. So I

Quoted 8 lines

prefer we drop that part of the patch.

Quoted 1 line

This is actually the main point of this patch: the removal of one-element arrays.
And yeah, every place in the kernel that uses the form that you mention will see it's uniformity slightly modified, and that's for a good cause: the removal of one-element arrays, so we can enable bounds checking.

I was going over https://github.com/KSPP/linux/issues/79, I'm not sure this all related to flexible arrays,
those are just reserved struct members. So because it's hard to identify a legitimate usage of single element arrays we are going to kill them all? It's more esthetic / readability issue here but there might be some legit use case for one element array, no?

Quoted 32 lines

Thanks
--
Gustavo

Quoted 4 lines
Quoted 4 lines

drivers/misc/mei/hw.h struct hbm_add_client_request { · line 348

Quoted 4 lines
drivers/misc/mei/hw.h +0 -0
@@ -346,13 +346,13 @@ struct hbm_add_client_request {
  * @hbm_cmd: bus message command header
  * @me_addr: address of the client in ME
  * @status: if HBMS_SUCCESS then the client can now accept

connections.

Quoted 22 lines
Quoted 22 lines
Quoted 22 lines
drivers/misc/mei/hw.h +3 -3
- * @reserved: reserved
+ * @reserved: reserved for alignment.
  */
 struct hbm_add_client_response {
 	u8 hbm_cmd;
 	u8 me_addr;
 	u8 status;
-	u8 reserved[1];
+	u8 reserved;
 } __packed;
 
 /**
@@ -461,7 +461,7 @@ struct hbm_notification {
 	u8 hbm_cmd;
 	u8 me_addr;
 	u8 host_addr;
-	u8 reserved[1];
+	u8 reserved;
 } __packed;
 
 /**
#7 lore raw
Quoted 62 lines · Tomas
Quoted 62 lines

Hi Tomas,

Please, see my comments below...

Quoted 56 lines · Tomas
Quoted 47 lines

Hi all,

Friendly ping: who can take this? :)

Thanks
--
Gustavo

Quoted 9 lines · Gustavo A. R. Silva

One-element arrays are being deprecated[1]. Replace the one-element arrays with a simple value type u8 reserved, once this is just a placeholder for alignment.

Also, while there, use the preferred form for passing a size of a struct. The alternative form where struct name is spelled out hurts readability and introduces an opportunity for a bug when the variable type is changed but the corresponding sizeof that is passed as argument is

not.

Quoted 26 lines

[1] https://github.com/KSPP/linux/issues/79

---
Changes in v2:
- Use a more concise changelog text.

 drivers/misc/mei/hbm.c | 4 ++--
 drivers/misc/mei/hw.h  | 6 +++---
 2 files changed, 5 insertions(+), 5 deletions(-)
drivers/misc/mei/hbm.c index renamed from drivers/misc/mei/hbm.c +0 -0

a44094cdbc36..f020d5594154 100644

drivers/misc/mei/hbm.c +1 -1
@@ -408,14 +408,14 @@ static int mei_hbm_add_cl_resp(struct
 mei_device *dev, u8 addr, u8 status)  {
 	struct mei_msg_hdr mei_hdr;
 	struct hbm_add_client_response resp;
-	const size_t len = sizeof(struct hbm_add_client_response);
+	const size_t len = sizeof(resp);
 	int ret;
 
 	dev_dbg(dev->dev, "adding client response\n");
 
Quoted 7 lines

drivers/misc/mei/hbm.c static int mei_hbm_add_cl_resp(struct mei_device *dev, u8 addr, u8 status) · line 421

Quoted 7 lines
drivers/misc/mei/hbm.c +1 -1
 	mei_hbm_hdr(&mei_hdr, len);
 
-	memset(&resp, 0, sizeof(struct hbm_add_client_response));
+	memset(&resp, 0, len);
 	resp.hbm_cmd = MEI_HBM_ADD_CLIENT_RES_CMD;
 	resp.me_addr = addr;
 	resp.status  = status;

This should be probably in a different patch it's not related to the second

Quoted 5 lines
Quoted 1 line

part.

Frankly I will post other version of this that cleans the whole file.

Sounds good. :)

Quoted 11 lines
Quoted 11 lines
Quoted 8 lines
Quoted 5 lines

drivers/misc/mei/hw.h

Quoted 5 lines
drivers/misc/mei/hw.h index renamed from drivers/misc/mei/hw.h +0 -0

b1a8d5ec88b3..8c0297f0e7f3 100644

drivers/misc/mei/hw.h +0 -0

I have second thoughts of this part as all reserved fields in this file are of form u8 reserved[X], so we will lose that uniformity with this change, you have to look at the file as whole not just at the patch. So I

prefer we drop that part of the patch.

Quoted 1 line
Quoted 7 lines
Quoted 5 lines

This is actually the main point of this patch: the removal of one-element arrays.
And yeah, every place in the kernel that uses the form that you mention will see it's uniformity slightly modified, and that's for a good cause: the removal of one-element arrays, so we can enable bounds checking.

I was going over https://github.com/KSPP/linux/issues/79, I'm not sure this all related to flexible arrays,

I've opened a new issue for this:

https://github.com/KSPP/linux/issues/86

And I'm already including the link above in these sorts of patches; please, see:

https://lore.kernel.org/lkml/20200717215500.GA13910@embeddedor/

Quoted 3 lines

those are just reserved struct members. So because it's hard to identify a legitimate usage of single element arrays we are going to kill them all? It's more esthetic / readability issue here but there might be some legit use case for one element array, no?

The code is continuously evolving and, if a one-element array is not intended to be used as a variable-length array at all, I frankly cannot think of any another use that is not merely esthetic/readability. :)

Thanks
--
Gustavo

Quoted 33 lines
Quoted 33 lines

Thanks
--
Gustavo

Quoted 4 lines
Quoted 4 lines

drivers/misc/mei/hw.h struct hbm_add_client_request { · line 348

Quoted 4 lines
drivers/misc/mei/hw.h +0 -0
@@ -346,13 +346,13 @@ struct hbm_add_client_request {
  * @hbm_cmd: bus message command header
  * @me_addr: address of the client in ME
  * @status: if HBMS_SUCCESS then the client can now accept

connections.

Quoted 22 lines
Quoted 22 lines
Quoted 22 lines
drivers/misc/mei/hw.h +3 -3
- * @reserved: reserved
+ * @reserved: reserved for alignment.
  */
 struct hbm_add_client_response {
 	u8 hbm_cmd;
 	u8 me_addr;
 	u8 status;
-	u8 reserved[1];
+	u8 reserved;
 } __packed;
 
 /**
@@ -461,7 +461,7 @@ struct hbm_notification {
 	u8 hbm_cmd;
 	u8 me_addr;
 	u8 host_addr;
-	u8 reserved[1];
+	u8 reserved;
 } __packed;
 
 /**