greybus: Avoid fake flexible array for response data
Subsystems (3)
PATCH 1/1 greybus: Avoid fake flexible array for response data
As https://lore.kernel.org/all/[email protected]/
pointed out, to enforce the 0-sized destinations, the remaining 0-sized destinations need to be handled. Thus the struct gb_control_get_manifest_response and struct gb_i2c_transfer_response are removed.
--- drivers/staging/greybus/i2c.c | 9 ++++----- include/linux/greybus/greybus_protocols.h | 9 --------- 2 files changed, 4 insertions(+), 14 deletions(-)
drivers/staging/greybus/i2c.c +4 -5
@@ -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,7 +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; +u8 *response; response = operation->response->payload;gb_i2c_decode_response (msgs, msg_count, response);
include/linux/greybus/greybus_protocols.h +0 -9
@@ -110,11 +110,6 @@ struct gb_control_get_manifest_size_response {__le16 size; } __packed; -/* Control protocol manifest get request has no payload */ -struct gb_control_get_manifest_response { -__u8 data[0 ]; -} __packed; -/* Control protocol [dis]connected request */ struct gb_control_connected_request {__le16 cport_id;
@@ -678,10 +673,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
Quoted 1 line · clingfei
I don't want to have to read a link to understand the commit message.
Does this change really affect anything in terms of "enforce the 0-sized destinations" rule? I don't think this is a destination. I think Kees enabled the checking he wanted. You should probably CC him since we're refering to his email.
Quoted 4 lines
pointed out, to enforce the 0-sized destinations, the remaining 0-sized destinations need to be handled. Thus the struct
gb_control_get_manifest_responseand structgb_i2c_transfer_responseare removed.
Here is a better commit message;
"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 char pointer instead."
I would have ignored it, probably but actually the gb_control_get_manifest_response struct is not used so put that in a separate commit. That's a simpler commit to review.
"The gb_control_get_manifest_response struct is not used. Delete it."
Quoted 31 lines
Signed-off-by clingfei <[email protected]>--- drivers/staging/greybus/i2c.c | 9 ++++----- include/linux/greybus/greybus_protocols.h | 9 --------- 2 files changed, 4 insertions(+), 14 deletions(-)drivers/staging/greybus/i2c.c +3
-4@@ -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);
drivers/staging/greybus/i2c.c static int gb_i2c_transfer_operation(struct gb_i2c_device *gb_i2c_dev, · line 193
Quoted 8 lines
drivers/staging/greybus/i2c.c +1
-1@@ -188,7 +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; +u8 *response; response = operation->response->payload;gb_i2c_decode_response (msgs, msg_count, response);
I like when parameters are called the same thing on both sides. The name "response" adds no value. Instead get rid of that variable and pass operation->response->payload directly.
gb_i2c_decode_response(msgs, msg_count, operation->response->payload);
regards,
dan carpenter
Quoted 9 lines · Dan Carpenter
Quoted 1 line · clingfei
I don't want to have to read a link to understand the commit message.
Does this change really affect anything in terms of "enforce the 0-sized destinations" rule? I don't think this is a destination. I think Kees enabled the checking he wanted. You should probably CC him since we're refering to his email.
FWIW, the above patch became commit 7ba59ac7da2a ("greybus: Avoid fake flexible array for response data").
Quoted 11 lines
Quoted 4 lines
pointed out, to enforce the 0-sized destinations, the remaining 0-sized destinations need to be handled. Thus the struct
gb_control_get_manifest_responseand structgb_i2c_transfer_responseare removed.Here is a better commit message;
"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 char pointer instead."
Quoted 5 lines
I would have ignored it, probably but actually the
gb_control_get_manifest_responsestruct is not used so put that in a separate commit. That's a simpler commit to review."The
gb_control_get_manifest_responsestruct is not used. Delete it."
The patch content itself looks mechanically correct. I think Dan's style suggestions would be good to see. Can you send a v2?
-Kees
Quoted 51 lines
Quoted 32 lines
Signed-off-by clingfei <[email protected]>--- drivers/staging/greybus/i2c.c | 9 ++++----- include/linux/greybus/greybus_protocols.h | 9 --------- 2 files changed, 4 insertions(+), 14 deletions(-)drivers/staging/greybus/i2c.c +3
-4@@ -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);drivers/staging/greybus/i2c.c static int gb_i2c_transfer_operation(struct gb_i2c_device *gb_i2c_dev, · line 193
Quoted 8 lines
drivers/staging/greybus/i2c.c +1
-1@@ -188,7 +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; +u8 *response; response = operation->response->payload;gb_i2c_decode_response (msgs, msg_count, response);I like when parameters are called the same thing on both sides. The name "response" adds no value. Instead get rid of that variable and pass
operation->response->payloaddirectly.gb_i2c_decode_response(msgs, msg_count, operation->response->payload);regards,
dan carpenter
Signature · 1 line
Kees Cook
Greg KH
maintainerQuoted 17 lines · clingfei
include/linux/greybus/greybus_protocols.h +0
-5@@ -110,11 +110,6 @@ struct gb_control_get_manifest_size_response {__le16 size; } __packed; -/* Control protocol manifest get request has no payload */ -struct gb_control_get_manifest_response { -__u8 data[0 ]; -} __packed; -/* Control protocol [dis]connected request */ struct gb_control_connected_request {__le16 cport_id;
include/linux/greybus/greybus_protocols.h struct gb_i2c_transfer_request { · line 678
Quoted 10 lines
include/linux/greybus/greybus_protocols.h +0
-4@@ -678,10 +673,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 */
Why are you deleting these structures that userspace uses? Are you sure you can do this? How was this tested?
thanks,
greg k-h