Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 5711ae6d authored by Luis R. Rodriguez's avatar Luis R. Rodriguez Committed by Greg Kroah-Hartman
Browse files

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: default avatarLuis R. Rodriguez <mcgrof@kernel.org>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent 942e743b
Loading
Loading
Loading
Loading
+9 −2
Original line number Diff line number Diff line
@@ -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;
		}
	}