From: Markus Elfring <elfring(a)users.sourceforge.net>
Date: Fri, 31 Oct 2025 19:50:39 +0100
A pointer was assigned to a variable. The same pointer was used for
the destination parameter of a memcpy() call.
This function is documented in the way that the same value is returned.
Thus convert two separate statements into a direct variable assignment for
the return value from a memory copy action.
The source code was transformed by using the Coccinelle software.
Signed-off-by: Markus Elfring <elfring(a)users.sourceforge.net>
---
drivers/greybus/es2.c | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/drivers/greybus/es2.c b/drivers/greybus/es2.c
index 7630a36ecf81..d71d37b41a66 100644
--- a/drivers/greybus/es2.c
+++ b/drivers/greybus/es2.c
@@ -194,8 +194,7 @@ static int output_async(struct es2_ap_dev *es2, void *req, u16 size, u8 cmd)
return -ENOMEM;
}
- buf = (u8 *)dr + sizeof(*dr);
- memcpy(buf, req, size);
+ buf = memcpy((u8 *)dr + sizeof(*dr), req, size);
dr->bRequest = cmd;
dr->bRequestType = USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_INTERFACE;
--
2.51.1
According to the Greybus Spec published here [0], the Greybus firmware
download find firmware request should have both tag and format as
request arguments. However, currently, the linux kernel seems to have
defined this request incorrectly since format is missing.
The patch adds format to request and am using it as the file extension of
the firmware.
[0]: https://github.com/projectara/greybus-spec/blob/ac47bc32dce1256489a82ff1f46…
Signed-off-by: Ayush Singh <ayush(a)beagleboard.org>
---
According to the Greybus Spec published here [0], the Greybus firmware
download find firmware request should have both tag and format as
request arguments. However, currently, the linux kernel seems to have
defined this request incorrectly since format is missing.
The patch adds format to request and am using it as the file extension of
the firmware.
I came across the bug while working on greybus-for-zephyr [1], to get it
ready for upstreaming as zephyr module.
Open Questions
***************
1. Handle empty format
Not sure what to do in case format is just NULL. Should the request
fail? There is no reason to not support firmware without extension. So
personally, I don't think it should be treated as error.
[0]: https://github.com/projectara/greybus-spec/blob/ac47bc32dce1256489a82ff1f46…
[1]: https://github.com/Ayush1325/greybus-for-zephyr
---
drivers/staging/greybus/fw-download.c | 31 ++++++++++++++++++++++++-------
include/linux/greybus/greybus_protocols.h | 2 ++
2 files changed, 26 insertions(+), 7 deletions(-)
diff --git a/drivers/staging/greybus/fw-download.c b/drivers/staging/greybus/fw-download.c
index 9a09bd3af79ba0dcf7efa683f4e86246bcd473a5..06f1be8f3121e29551ea8416d5ee2666339b2fe3 100644
--- a/drivers/staging/greybus/fw-download.c
+++ b/drivers/staging/greybus/fw-download.c
@@ -159,7 +159,7 @@ static int exceeds_release_timeout(struct fw_request *fw_req)
/* This returns path of the firmware blob on the disk */
static struct fw_request *find_firmware(struct fw_download *fw_download,
- const char *tag)
+ const char *tag, const char *format)
{
struct gb_interface *intf = fw_download->connection->bundle->intf;
struct fw_request *fw_req;
@@ -178,10 +178,17 @@ static struct fw_request *find_firmware(struct fw_download *fw_download,
}
fw_req->firmware_id = ret;
- snprintf(fw_req->name, sizeof(fw_req->name),
- FW_NAME_PREFIX "%08x_%08x_%08x_%08x_%s.tftf",
- intf->ddbl1_manufacturer_id, intf->ddbl1_product_id,
- intf->vendor_id, intf->product_id, tag);
+ if (strnlen(format, GB_FIRMWARE_FORMAT_MAX_SIZE) == 0) {
+ snprintf(fw_req->name, sizeof(fw_req->name),
+ FW_NAME_PREFIX "%08x_%08x_%08x_%08x_%s",
+ intf->ddbl1_manufacturer_id, intf->ddbl1_product_id,
+ intf->vendor_id, intf->product_id, tag);
+ } else {
+ snprintf(fw_req->name, sizeof(fw_req->name),
+ FW_NAME_PREFIX "%08x_%08x_%08x_%08x_%s.%s",
+ intf->ddbl1_manufacturer_id, intf->ddbl1_product_id,
+ intf->vendor_id, intf->product_id, tag, format);
+ }
dev_info(fw_download->parent, "Requested firmware package '%s'\n",
fw_req->name);
@@ -225,7 +232,7 @@ static int fw_download_find_firmware(struct gb_operation *op)
struct gb_fw_download_find_firmware_request *request;
struct gb_fw_download_find_firmware_response *response;
struct fw_request *fw_req;
- const char *tag;
+ const char *tag, *format;
if (op->request->payload_size != sizeof(*request)) {
dev_err(fw_download->parent,
@@ -245,7 +252,17 @@ static int fw_download_find_firmware(struct gb_operation *op)
return -EINVAL;
}
- fw_req = find_firmware(fw_download, tag);
+ format = (const char *)request->format;
+
+ /* firmware_format must be null-terminated */
+ if (strnlen(format, GB_FIRMWARE_FORMAT_MAX_SIZE) ==
+ GB_FIRMWARE_FORMAT_MAX_SIZE) {
+ dev_err(fw_download->parent,
+ "firmware-format is not null-terminated\n");
+ return -EINVAL;
+ }
+
+ fw_req = find_firmware(fw_download, tag, format);
if (IS_ERR(fw_req))
return PTR_ERR(fw_req);
diff --git a/include/linux/greybus/greybus_protocols.h b/include/linux/greybus/greybus_protocols.h
index 820134b0105c2caf8cea3ff0985c92d48d3a2d4c..48d91154847dbc7d3c01081eadc69f96dbe41a9f 100644
--- a/include/linux/greybus/greybus_protocols.h
+++ b/include/linux/greybus/greybus_protocols.h
@@ -214,10 +214,12 @@ struct gb_apb_request_cport_flags {
#define GB_FW_DOWNLOAD_TYPE_RELEASE_FIRMWARE 0x03
#define GB_FIRMWARE_TAG_MAX_SIZE 10
+#define GB_FIRMWARE_FORMAT_MAX_SIZE 10
/* firmware download find firmware request/response */
struct gb_fw_download_find_firmware_request {
__u8 firmware_tag[GB_FIRMWARE_TAG_MAX_SIZE];
+ __u8 format[GB_FIRMWARE_FORMAT_MAX_SIZE];
} __packed;
struct gb_fw_download_find_firmware_response {
---
base-commit: aaa9c3550b60d6259d6ea8b1175ade8d1242444e
change-id: 20251022-gb-fw-a5db68692b5d
Best regards,
--
Ayush Singh <ayush(a)beagleboard.org>