Add a pointer argument to cs_amp_get_efi_variable() to optionally
return the EFI variable attributes.
Originally this function internally consumed the attributes from
efi.get_variable(). The calling code did not use the attributes
so this was a small simplification.
However, when writing to a pre-existing variable we would want to
pass the existing attributes to efi.set_variable(). This patch
deals with the change to return the attribute in preparation for
adding code to update the variable.
Signed-off-by: Richard Fitzgerald <rf@opensource.cirrus.com>
Reviewed-by: Takashi Iwai <tiwai@suse.de>
Link: https://patch.msgid.link/20251021105022.1013685-8-rf@opensource.cirrus.com
Signed-off-by: Mark Brown <broonie@kernel.org>
struct cs_amp_test_hooks {
efi_status_t (*get_efi_variable)(efi_char16_t *name,
efi_guid_t *guid,
+ u32 *returned_attr,
unsigned long *size,
void *buf);
/* Redirected get_efi_variable to simulate that the file is too short */
static efi_status_t cs_amp_lib_test_get_efi_variable_nohead(efi_char16_t *name,
efi_guid_t *guid,
+ u32 *returned_attr,
unsigned long *size,
void *buf)
{
/* Redirected get_efi_variable to simulate that the count is larger than the file */
static efi_status_t cs_amp_lib_test_get_efi_variable_bad_count(efi_char16_t *name,
efi_guid_t *guid,
+ u32 *returned_attr,
unsigned long *size,
void *buf)
{
/* Redirected get_efi_variable to simulate that the variable not found */
static efi_status_t cs_amp_lib_test_get_efi_variable_none(efi_char16_t *name,
efi_guid_t *guid,
+ u32 *returned_attr,
unsigned long *size,
void *buf)
{
/* Redirected get_efi_variable to simulate reading a cal data blob */
static efi_status_t cs_amp_lib_test_get_efi_variable(efi_char16_t *name,
efi_guid_t *guid,
+ u32 *returned_attr,
unsigned long *size,
void *buf)
{
memcpy(buf, priv->cal_blob, priv->cal_blob->size);
+ if (returned_attr) {
+ *returned_attr = EFI_VARIABLE_NON_VOLATILE |
+ EFI_VARIABLE_BOOTSERVICE_ACCESS |
+ EFI_VARIABLE_RUNTIME_ACCESS;
+ }
+
return EFI_SUCCESS;
}
static efi_status_t cs_amp_lib_test_get_hp_cal_efi_variable(efi_char16_t *name,
efi_guid_t *guid,
+ u32 *returned_attr,
unsigned long *size,
void *buf)
{
memcpy(buf, priv->cal_blob, priv->cal_blob->size);
+ if (returned_attr) {
+ *returned_attr = EFI_VARIABLE_NON_VOLATILE |
+ EFI_VARIABLE_BOOTSERVICE_ACCESS |
+ EFI_VARIABLE_RUNTIME_ACCESS;
+ }
+
return EFI_SUCCESS;
}
static efi_status_t cs_amp_lib_test_get_efi_variable_lenovo_d0(efi_char16_t *name,
efi_guid_t *guid,
+ u32 *returned_attr,
unsigned long *size,
void *buf)
{
static efi_status_t cs_amp_lib_test_get_efi_variable_lenovo_d1(efi_char16_t *name,
efi_guid_t *guid,
+ u32 *returned_attr,
unsigned long *size,
void *buf)
{
static efi_status_t cs_amp_lib_test_get_efi_variable_lenovo_00(efi_char16_t *name,
efi_guid_t *guid,
+ u32 *returned_attr,
unsigned long *size,
void *buf)
{
static efi_status_t cs_amp_lib_test_get_efi_variable_buf_too_small(efi_char16_t *name,
efi_guid_t *guid,
+ u32 *returned_attr,
unsigned long *size,
void *buf)
{
static efi_status_t cs_amp_lib_test_get_efi_variable_hp_30(efi_char16_t *name,
efi_guid_t *guid,
+ u32 *returned_attr,
unsigned long *size,
void *buf)
{
static efi_status_t cs_amp_lib_test_get_efi_variable_hp_31(efi_char16_t *name,
efi_guid_t *guid,
+ u32 *returned_attr,
unsigned long *size,
void *buf)
{
static efi_status_t cs_amp_get_efi_variable(efi_char16_t *name,
efi_guid_t *guid,
+ u32 *returned_attr,
unsigned long *size,
void *buf)
{
u32 attr;
- KUNIT_STATIC_STUB_REDIRECT(cs_amp_get_efi_variable, name, guid, size, buf);
+ if (!returned_attr)
+ returned_attr = &attr;
+
+ KUNIT_STATIC_STUB_REDIRECT(cs_amp_get_efi_variable, name, guid,
+ returned_attr, size, buf);
if (efi_rt_services_supported(EFI_RT_SUPPORTED_GET_VARIABLE))
- return efi.get_variable(name, guid, &attr, size, buf);
+ return efi.get_variable(name, guid, returned_attr, size, buf);
return EFI_NOT_FOUND;
}
for (i = 0; i < ARRAY_SIZE(cs_amp_lib_cal_efivars); i++) {
status = cs_amp_get_efi_variable(cs_amp_lib_cal_efivars[i].name,
cs_amp_lib_cal_efivars[i].guid,
- &data_size, NULL);
+ NULL, &data_size, NULL);
if (status == EFI_BUFFER_TOO_SMALL)
break;
}
status = cs_amp_get_efi_variable(cs_amp_lib_cal_efivars[i].name,
cs_amp_lib_cal_efivars[i].guid,
- &data_size, data);
+ NULL, &data_size, data);
if (status != EFI_SUCCESS) {
ret = -EINVAL;
goto err;
int i, ret;
size = sizeof(spkid);
- status = cs_amp_get_efi_variable(info->name, info->guid, &size, &spkid);
+ status = cs_amp_get_efi_variable(info->name, info->guid, NULL, &size, &spkid);
ret = cs_amp_convert_efi_status(status);
if (ret < 0)
return ret;