ASoC: cs-amp-lib: Return attributes from cs_amp_get_efi_variable()

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>
This commit is contained in:
Richard Fitzgerald
2025-10-21 11:50:18 +01:00
committed by Mark Brown
parent cf6290eebe
commit 959400caf5
3 changed files with 34 additions and 5 deletions

View File

@@ -66,6 +66,7 @@ static inline u64 cs_amp_cal_target_u64(const struct cirrus_amp_cal_data *data)
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);

View File

@@ -89,6 +89,7 @@ static u64 cs_amp_lib_test_get_target_uid(struct kunit *test)
/* 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)
{
@@ -121,6 +122,7 @@ static void cs_amp_lib_test_cal_data_too_short_test(struct kunit *test)
/* 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)
{
@@ -164,6 +166,7 @@ static void cs_amp_lib_test_cal_count_too_big_test(struct kunit *test)
/* 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)
{
@@ -191,6 +194,7 @@ static void cs_amp_lib_test_no_cal_data_test(struct kunit *test)
/* 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)
{
@@ -217,11 +221,18 @@ static efi_status_t cs_amp_lib_test_get_efi_variable(efi_char16_t *name,
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)
{
@@ -248,6 +259,12 @@ static efi_status_t cs_amp_lib_test_get_hp_cal_efi_variable(efi_char16_t *name,
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;
}
@@ -786,6 +803,7 @@ static void cs_amp_lib_test_spkid_lenovo_not_present(struct kunit *test)
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)
{
@@ -804,6 +822,7 @@ static efi_status_t cs_amp_lib_test_get_efi_variable_lenovo_d0(efi_char16_t *nam
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)
{
@@ -822,6 +841,7 @@ static efi_status_t cs_amp_lib_test_get_efi_variable_lenovo_d1(efi_char16_t *nam
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)
{
@@ -873,6 +893,7 @@ static void cs_amp_lib_test_spkid_lenovo_illegal(struct kunit *test)
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)
{
@@ -893,6 +914,7 @@ static void cs_amp_lib_test_spkid_lenovo_oversize(struct kunit *test)
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)
{
@@ -911,6 +933,7 @@ static efi_status_t cs_amp_lib_test_get_efi_variable_hp_30(efi_char16_t *name,
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)
{

View File

@@ -245,15 +245,20 @@ EXPORT_SYMBOL_NS_GPL(cs_amp_write_ambient_temp, "SND_SOC_CS_AMP_LIB");
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;
}
@@ -288,7 +293,7 @@ static struct cirrus_amp_efi_data *cs_amp_get_cal_efi_buffer(struct device *dev)
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;
}
@@ -308,7 +313,7 @@ static struct cirrus_amp_efi_data *cs_amp_get_cal_efi_buffer(struct device *dev)
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;
@@ -452,7 +457,7 @@ static int cs_amp_get_efi_byte_spkid(struct device *dev, const struct cs_amp_spk
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;