Skip to contentSkip to conversation

greybus: Avoid fake flexible array for response data

PATCH In review clingfei 2 participants 4 messages May 27, 2025

Subsystems (3)
lore
Share & tools
lore

clingfei

author
#0 lore raw

PATCH v2 1/1 greybus: Avoid fake flexible array for response data

We want to get rid of zero size arrays and use flexible arrays instead. However, in this case the struct is just one flexible array of u8 which adds no value. Just use a pointer instead.

v1: https://lore.kernel.org/all/202505262032.507AD8E0DC@keescook/

---
 drivers/staging/greybus/i2c.c             | 12 ++++--------
 include/linux/greybus/greybus_protocols.h |  3 ---
 2 files changed, 4 insertions(+), 11 deletions(-)
drivers/staging/greybus/i2c.c +4 -8
index 14f1ff6d448c..b248d6717b71 100644
@@ -144,15 +144,14 @@ gb_i2c_operation_create(struct gb_connection *connection,
 }
 
 static void gb_i2c_decode_response(struct i2c_msg *msgs, u32 msg_count,
-				   struct gb_i2c_transfer_response *response)
+				   u8 *data)
 {
 	struct i2c_msg *msg = msgs;
-	u8 *data;
 	u32 i;
 
-	if (!response)
+	if (!data)
 		return;
-	data = response->data;
+
 	for (i = 0; i < msg_count; i++) {
 		if (msg->flags & I2C_M_RD) {
 			memcpy(msg->buf, data, msg->len);
@@ -188,10 +187,7 @@ static int gb_i2c_transfer_operation(struct gb_i2c_device *gb_i2c_dev,
 
 	ret = gb_operation_request_send_sync(operation);
 	if (!ret) {
-		struct gb_i2c_transfer_response *response;
-
-		response = operation->response->payload;
-		gb_i2c_decode_response(msgs, msg_count, response);
+		gb_i2c_decode_response(msgs, msg_count, operation->response->payload);
 		ret = msg_count;
 	} else if (!gb_i2c_expected_transfer_error(ret)) {
 		dev_err(dev, "transfer operation failed (%d)\n", ret);
include/linux/greybus/greybus_protocols.h +0 -3
index 820134b0105c..6a35c78b967b 100644
@@ -678,9 +678,6 @@ struct gb_i2c_transfer_request {
 	__le16				op_count;
 	struct gb_i2c_transfer_op	ops[];		/* op_count of these */
 } __packed;
-struct gb_i2c_transfer_response {
-	__u8				data[0];	/* inbound data */
-} __packed;
 
 
 /* GPIO */
Signature · 1 line
2.34.1
maintainer
#1 lore raw
Quoted 3 lines · clingfei

We want to get rid of zero size arrays and use flexible arrays instead. However, in this case the struct is just one flexible array of u8 which adds no value. Just use a pointer instead.

Not true at all, sorry, it does "add value". Please read the greybus specification if you have questions about this.

Quoted 2 lines

v1: https://lore.kernel.org/all/202505262032.507AD8E0DC@keescook/

Please read our documentation for how to properly version kernel patches

Quoted 2 lines

Also, we need a "full"name, not an email alias.

Quoted 45 lines
---
 drivers/staging/greybus/i2c.c             | 12 ++++--------
 include/linux/greybus/greybus_protocols.h |  3 ---
 2 files changed, 4 insertions(+), 11 deletions(-)
drivers/staging/greybus/i2c.c +4 -8
index 14f1ff6d448c..b248d6717b71 100644
@@ -144,15 +144,14 @@ gb_i2c_operation_create(struct gb_connection *connection,
 }
 
 static void gb_i2c_decode_response(struct i2c_msg *msgs, u32 msg_count,
-				   struct gb_i2c_transfer_response *response)
+				   u8 *data)
 {
 	struct i2c_msg *msg = msgs;
-	u8 *data;
 	u32 i;
 
-	if (!response)
+	if (!data)
 		return;
-	data = response->data;
+
 	for (i = 0; i < msg_count; i++) {
 		if (msg->flags & I2C_M_RD) {
 			memcpy(msg->buf, data, msg->len);
@@ -188,10 +187,7 @@ static int gb_i2c_transfer_operation(struct gb_i2c_device *gb_i2c_dev,
 
 	ret = gb_operation_request_send_sync(operation);
 	if (!ret) {
-		struct gb_i2c_transfer_response *response;
-
-		response = operation->response->payload;
-		gb_i2c_decode_response(msgs, msg_count, response);
+		gb_i2c_decode_response(msgs, msg_count, operation->response->payload);
 		ret = msg_count;
 	} else if (!gb_i2c_expected_transfer_error(ret)) {
 		dev_err(dev, "transfer operation failed (%d)\n", ret);
include/linux/greybus/greybus_protocols.h +0 -0
index 820134b0105c..6a35c78b967b 100644

include/linux/greybus/greybus_protocols.h struct gb_i2c_transfer_request { · line 683

Quoted 6 lines
include/linux/greybus/greybus_protocols.h +0 -3
@@ -678,9 +678,6 @@ struct gb_i2c_transfer_request {
 	__le16				op_count;
 	struct gb_i2c_transfer_op	ops[];		/* op_count of these */
 } __packed;
-struct gb_i2c_transfer_response {
-	__u8				data[0];	/* inbound data */
-} __packed;

As I said before, you can't just delete structures that are exported to userspace without breaking things. Why is this change acceptable to do that?

And how was any of this tested?

greg k-h

author
#2 lore raw
Quoted 6 lines · Greg KH <[email protected]> 于2025年5月27日周二 13:15写道:
Quoted 3 lines · clingfei

We want to get rid of zero size arrays and use flexible arrays instead. However, in this case the struct is just one flexible array of u8 which adds no value. Just use a pointer instead.

Quoted 7 lines

Not true at all, sorry, it does "add value". Please read the greybus specification if you have questions about this.

Quoted 2 lines

v1: https://lore.kernel.org/all/202505262032.507AD8E0DC@keescook/

Please read our documentation for how to properly version kernel patches

Sorry, I will read it.

Quoted 62 lines
Quoted 3 lines

Also, we need a "full"name, not an email alias.

Quoted 45 lines
---
 drivers/staging/greybus/i2c.c             | 12 ++++--------
 include/linux/greybus/greybus_protocols.h |  3 ---
 2 files changed, 4 insertions(+), 11 deletions(-)
drivers/staging/greybus/i2c.c +4 -8
index 14f1ff6d448c..b248d6717b71 100644
@@ -144,15 +144,14 @@ gb_i2c_operation_create(struct gb_connection *connection,
 }
 
 static void gb_i2c_decode_response(struct i2c_msg *msgs, u32 msg_count,
-                                struct gb_i2c_transfer_response *response)
+                                u8 *data)
 {
      struct i2c_msg *msg = msgs;
-     u8 *data;
      u32 i;
 
-     if (!response)
+     if (!data)
              return;
-     data = response->data;
+
      for (i = 0; i < msg_count; i++) {
              if (msg->flags & I2C_M_RD) {
                      memcpy(msg->buf, data, msg->len);
@@ -188,10 +187,7 @@ static int gb_i2c_transfer_operation(struct gb_i2c_device *gb_i2c_dev,
 
      ret = gb_operation_request_send_sync(operation);
      if (!ret) {
-             struct gb_i2c_transfer_response *response;
-
-             response = operation->response->payload;
-             gb_i2c_decode_response(msgs, msg_count, response);
+             gb_i2c_decode_response(msgs, msg_count, operation->response->payload);
              ret = msg_count;
      } else if (!gb_i2c_expected_transfer_error(ret)) {
              dev_err(dev, "transfer operation failed (%d)\n", ret);
include/linux/greybus/greybus_protocols.h +0 -0
index 820134b0105c..6a35c78b967b 100644

include/linux/greybus/greybus_protocols.h struct gb_i2c_transfer_request { · line 683

Quoted 6 lines
include/linux/greybus/greybus_protocols.h +0 -3
@@ -678,9 +678,6 @@ struct gb_i2c_transfer_request {
      __le16                          op_count;
      struct gb_i2c_transfer_op       ops[];          /* op_count of these */
 } __packed;
-struct gb_i2c_transfer_response {
-     __u8                            data[0];        /* inbound data */
-} __packed;

As I said before, you can't just delete structures that are exported to userspace without breaking things. Why is this change acceptable to do that?

Quoted 3 lines

And how was any of this tested?

greg k-h

Could you please give some examples that will be broken by this change? And I am not sure how this should be tested. It seems that it will not have any negative impact on functionality.

maintainer
#3 lore raw
Quoted 78 lines · clingfei
Quoted 6 lines · Greg KH <[email protected]> 于2025年5月27日周二 13:15写道:
Quoted 3 lines · clingfei

We want to get rid of zero size arrays and use flexible arrays instead. However, in this case the struct is just one flexible array of u8 which adds no value. Just use a pointer instead.

Quoted 7 lines

Not true at all, sorry, it does "add value". Please read the greybus specification if you have questions about this.

Quoted 2 lines

v1: https://lore.kernel.org/all/202505262032.507AD8E0DC@keescook/

Please read our documentation for how to properly version kernel patches

Sorry, I will read it.

Quoted 62 lines
Quoted 3 lines

Also, we need a "full"name, not an email alias.

Quoted 45 lines
---
 drivers/staging/greybus/i2c.c             | 12 ++++--------
 include/linux/greybus/greybus_protocols.h |  3 ---
 2 files changed, 4 insertions(+), 11 deletions(-)
drivers/staging/greybus/i2c.c +4 -8
index 14f1ff6d448c..b248d6717b71 100644
@@ -144,15 +144,14 @@ gb_i2c_operation_create(struct gb_connection *connection,
 }
 
 static void gb_i2c_decode_response(struct i2c_msg *msgs, u32 msg_count,
-                                struct gb_i2c_transfer_response *response)
+                                u8 *data)
 {
      struct i2c_msg *msg = msgs;
-     u8 *data;
      u32 i;
 
-     if (!response)
+     if (!data)
              return;
-     data = response->data;
+
      for (i = 0; i < msg_count; i++) {
              if (msg->flags & I2C_M_RD) {
                      memcpy(msg->buf, data, msg->len);
@@ -188,10 +187,7 @@ static int gb_i2c_transfer_operation(struct gb_i2c_device *gb_i2c_dev,
 
      ret = gb_operation_request_send_sync(operation);
      if (!ret) {
-             struct gb_i2c_transfer_response *response;
-
-             response = operation->response->payload;
-             gb_i2c_decode_response(msgs, msg_count, response);
+             gb_i2c_decode_response(msgs, msg_count, operation->response->payload);
              ret = msg_count;
      } else if (!gb_i2c_expected_transfer_error(ret)) {
              dev_err(dev, "transfer operation failed (%d)\n", ret);
include/linux/greybus/greybus_protocols.h +0 -0
index 820134b0105c..6a35c78b967b 100644

include/linux/greybus/greybus_protocols.h struct gb_i2c_transfer_request { · line 683

Quoted 6 lines
include/linux/greybus/greybus_protocols.h +0 -3
@@ -678,9 +678,6 @@ struct gb_i2c_transfer_request {
      __le16                          op_count;
      struct gb_i2c_transfer_op       ops[];          /* op_count of these */
 } __packed;
-struct gb_i2c_transfer_response {
-     __u8                            data[0];        /* inbound data */
-} __packed;

As I said before, you can't just delete structures that are exported to userspace without breaking things. Why is this change acceptable to do that?

Quoted 5 lines
Quoted 3 lines

And how was any of this tested?

greg k-h

Could you please give some examples that will be broken by this change?

Have you searched all userspace tools to verify that they do not use this structure definition? You are removing a user/kernel api here, something that we do not do without researching that no existing user in the world will not break.

Quoted 2 lines

And I am not sure how this should be tested. It seems that it will not have any negative impact on functionality.

I would strongly recommend, that if you can not test this, that you not make the change :)

good luck!

greg k-h