summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLuis R. Rodriguez <mcgrof@kernel.org>2017-11-20 21:23:56 +0300
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2017-11-29 13:18:43 +0300
commit5711ae6d3054e13a95858da6df6d142bec90d832 (patch)
tree79b812439129830ac2a8802bf1615e18a8f5a54b
parent942e743b73d0effc65895e4361b04534e24106cb (diff)
downloadlinux-5711ae6d3054e13a95858da6df6d142bec90d832.tar.xz
firmware: add helper to copy built-in data to pre-alloc buffer
This makes it clearer that the parameters passed are only used for the preallocated buffer option, ie, when a caller uses: request_firmware_into_buf() Otherwise this code won't run. We flip the logic just so the actual prellocated buf code is not indented. Signed-off-by: Luis R. Rodriguez <mcgrof@kernel.org> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
-rw-r--r--drivers/base/firmware_class.c11
1 files changed, 9 insertions, 2 deletions
diff --git a/drivers/base/firmware_class.c b/drivers/base/firmware_class.c
index 4f64410fe7e6..aba3f2cbe2f4 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;
}
}