Merge tag 'io_uring-5.11-2021-01-16' of git://git.kernel.dk/linux-block
[linux/fpc-iii.git] / drivers / base / firmware_loader / fallback_platform.c
blob00af99f0aff21818d36e6917bedf78866fa376fe
1 // SPDX-License-Identifier: GPL-2.0
3 #include <linux/efi_embedded_fw.h>
4 #include <linux/property.h>
5 #include <linux/security.h>
6 #include <linux/vmalloc.h>
8 #include "fallback.h"
9 #include "firmware.h"
11 int firmware_fallback_platform(struct fw_priv *fw_priv)
13 const u8 *data;
14 size_t size;
15 int rc;
17 if (!(fw_priv->opt_flags & FW_OPT_FALLBACK_PLATFORM))
18 return -ENOENT;
20 rc = security_kernel_load_data(LOADING_FIRMWARE, true);
21 if (rc)
22 return rc;
24 rc = efi_get_embedded_fw(fw_priv->fw_name, &data, &size);
25 if (rc)
26 return rc; /* rc == -ENOENT when the fw was not found */
28 if (fw_priv->data && size > fw_priv->allocated_size)
29 return -ENOMEM;
31 rc = security_kernel_post_load_data((u8 *)data, size, LOADING_FIRMWARE,
32 "platform");
33 if (rc)
34 return rc;
36 if (!fw_priv->data)
37 fw_priv->data = vmalloc(size);
38 if (!fw_priv->data)
39 return -ENOMEM;
41 memcpy(fw_priv->data, data, size);
42 fw_priv->size = size;
43 fw_state_done(fw_priv);
44 return 0;