diff --git a/drivers/base/firmware_class.c b/drivers/base/firmware_class.c index 4f64410fe7e65c0c27e2d88e544bdc18ba0e57fa..aba3f2cbe2f4b6fb6b40d83c09b4b446dbe0e0a0 100644 --- a/drivers/base/firmware_class.c +++ b/drivers/base/firmware_class.c @@ -146,6 +146,14 @@ static struct firmware_cache fw_cache; extern struct builtin_fw __start_builtin_fw[]; extern struct builtin_fw __end_builtin_fw[]; +static void fw_copy_to_prealloc_buf(struct firmware *fw, + void *buf, size_t size) +{ + if (!buf || size < fw->size) + return; + memcpy(buf, fw->data, fw->size); +} + static bool fw_get_builtin_firmware(struct firmware *fw, const char *name, void *buf, size_t size) { @@ -155,9 +163,8 @@ static bool fw_get_builtin_firmware(struct firmware *fw, const char *name, if (strcmp(name, b_fw->name) == 0) { fw->size = b_fw->size; fw->data = b_fw->data; + fw_copy_to_prealloc_buf(fw, buf, size); - if (buf && fw->size <= size) - memcpy(buf, fw->data, fw->size); return true; } }