History

efi/random: use arch-independent efi_call_proto()

To handle all arch-specific peculiarities when calling an EFI protocol function, a wrapper efi_call_proto() exists on all relevant architectures. On arm/arm64, this is merely a plain function call. On x86, a special EFI entry stub needs to be used, however, as the calling convention differs. To make the efi/random stub arch-independent, use efi_call_proto() instead of the existing non-portable calls to the EFI get_rng protocol function. This also requires the addition of some typedefs.

Dominik Brodowski committed 7 years ago

Commit 41e8a7c1 parent 8b5c7121 file · +18 −5Browse files

Unified · Split

drivers/firmware/efi/libstub/random.c+18−5
@@ -9,6 +9,18 @@ · 8 unmodified lines
99
1010 #include "efistub.h"
1111
12+typedef struct efi_rng_protocol efi_rng_protocol_t;
13+
14+typedef struct {
15+ u32 get_info;
16+ u32 get_rng;
17+} efi_rng_protocol_32_t;
18+
19+typedef struct {
20+ u64 get_info;
21+ u64 get_rng;
22+} efi_rng_protocol_64_t;
23+
1224 struct efi_rng_protocol {
1325 efi_status_t (*get_info)(struct efi_rng_protocol *,
1426 unsigned long *, efi_guid_t *);
@@ -28,7 +40,7 @@ efi_status_t efi_get_random_bytes(efi_system_table_t *sys_table_arg, · 13 unmodified lines
2840 if (status != EFI_SUCCESS)
2941 return status;
3042
31− return rng->get_rng(rng, NULL, size, out);
43+ return efi_call_proto(efi_rng_protocol, get_rng, rng, NULL, size, out);
3244 }
3345
3446 /*
@@ -161,15 +173,16 @@ efi_status_t efi_random_get_seed(efi_system_table_t *sys_table_arg) · 126 unmodified lines
161173 if (status != EFI_SUCCESS)
162174 return status;
163175
164− status = rng->get_rng(rng, &rng_algo_raw, EFI_RANDOM_SEED_SIZE,
165− seed->bits);
176+ status = efi_call_proto(efi_rng_protocol, get_rng, rng, &rng_algo_raw,
177+ EFI_RANDOM_SEED_SIZE, seed->bits);
178+
166179 if (status == EFI_UNSUPPORTED)
167180 /*
168181 * Use whatever algorithm we have available if the raw algorithm
169182 * is not implemented.
170183 */
171− status = rng->get_rng(rng, NULL, EFI_RANDOM_SEED_SIZE,
172− seed->bits);
184+ status = efi_call_proto(efi_rng_protocol, get_rng, rng, NULL,
185+ EFI_RANDOM_SEED_SIZE, seed->bits);
173186
174187 if (status != EFI_SUCCESS)
175188 goto err_freepool;

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t