]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
ASoC: cs-amp-lib: Return attributes from cs_amp_get_efi_variable()
authorRichard Fitzgerald <rf@opensource.cirrus.com>
Tue, 21 Oct 2025 10:50:18 +0000 (11:50 +0100)
committerMark Brown <broonie@kernel.org>
Mon, 27 Oct 2025 14:07:47 +0000 (14:07 +0000)
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>
include/sound/cs-amp-lib.h
sound/soc/codecs/cs-amp-lib-test.c
sound/soc/codecs/cs-amp-lib.c

index efa744133a35b380fe40b239b49c85498c8b3b72..2e5616a5e1f706d7e99b0b534cbf4b3fbd654d76 100644 (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);
 
index 6878941a8f579bbd3fbb2ec4950227eca55491f1..b00ba65badd5324168799bd08e095ff31ce52876 100644 (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)
 {
index f9f79da3a9eabd14f4ea775b589cb9454961b177..c5791cbeb5b813fc7ec1554e56489bf4458ff50e 100644 (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;