[PATCH 07/11] ASoC: cs-amp-lib: Return attributes from cs_amp_get_efi_variable()

Richard Fitzgerald
2025-10-16T10:42:54Z

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>
---
include/sound/cs-amp-lib.h | 1 +
sound/soc/codecs/cs-amp-lib-test.c | 23 +++++++++++++++++++++++
sound/soc/codecs/cs-amp-lib.c | 15 ++++++++++-----
3 files changed, 34 insertions(+), 5 deletions(-)

diff --git a/include/sound/cs-amp-lib.h b/include/sound/cs-amp-lib.h
index 485daadd13a1..09c54b1bbe6c 100644
--- a/include/sound/cs-amp-lib.h
+++ b/include/sound/cs-amp-lib.h
@@ -65,6 +65,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);

diff --git a/sound/soc/codecs/cs-amp-lib-test.c b/sound/soc/codecs/cs-amp-lib-test.c
index b19aaacd7f2b..d3419f48297e 100644
--- a/sound/soc/codecs/cs-amp-lib-test.c
+++ b/sound/soc/codecs/cs-amp-lib-test.c
@@ -90,6 +90,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)
{
@@ -122,6 +123,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)
{
@@ -165,6 +167,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)
{
@@ -192,6 +195,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)
{
@@ -218,11 +222,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)
{
@@ -249,6 +260,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;
}

@@ -787,6 +804,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)
{
@@ -805,6 +823,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)
{
@@ -823,6 +842,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)
{
@@ -874,6 +894,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)
{
@@ -894,6 +915,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)
{
@@ -912,6 +934,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)
{
diff --git a/sound/soc/codecs/cs-amp-lib.c b/sound/soc/codecs/cs-amp-lib.c
index d510e0e065ca..2630ea6a8f3a 100644
--- a/sound/soc/codecs/cs-amp-lib.c
+++ b/sound/soc/codecs/cs-amp-lib.c
@@ -244,15 +244,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;
}
@@ -287,7 +292,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;
}
@@ -307,7 +312,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;
@@ -451,7 +456,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;
--
2.47.3