[SRU][R][PATCH 05/18] ASoC: cs-amp-lib: Return attributes from cs_amp_get_efi_variable()
Chris Chiu
chris.chiu at canonical.com
Tue Mar 17 05:21:50 UTC 2026
From: Richard Fitzgerald <rf at opensource.cirrus.com>
BugLink: https://bugs.launchpad.net/bugs/2139391
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 at opensource.cirrus.com>
Reviewed-by: Takashi Iwai <tiwai at suse.de>
Link: https://patch.msgid.link/20251021105022.1013685-8-rf@opensource.cirrus.com
Signed-off-by: Mark Brown <broonie at kernel.org>
(backported from commit 959400caf51eb31f95d1ab754a285b5546ebd3e4)
[ChrisChiu: ignore irrelevant functions backporting for HP efi variables]
Signed-off-by: Chris Chiu <chris.chiu at canonical.com>
---
include/sound/cs-amp-lib.h | 1 +
sound/soc/codecs/cs-amp-lib-test.c | 10 ++++++++++
sound/soc/codecs/cs-amp-lib.c | 13 +++++++++----
3 files changed, 20 insertions(+), 4 deletions(-)
diff --git a/include/sound/cs-amp-lib.h b/include/sound/cs-amp-lib.h
index 5459c221badf..684c119c4d7b 100644
--- a/include/sound/cs-amp-lib.h
+++ b/include/sound/cs-amp-lib.h
@@ -53,6 +53,7 @@ int cs_amp_get_efi_calibration_data(struct device *dev, u64 target_uid, int amp_
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 a1a9758a73eb..e5e0998ad550 100644
--- a/sound/soc/codecs/cs-amp-lib-test.c
+++ b/sound/soc/codecs/cs-amp-lib-test.c
@@ -82,6 +82,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)
{
@@ -114,6 +115,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)
{
@@ -157,6 +159,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)
{
@@ -184,6 +187,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)
{
@@ -209,6 +213,12 @@ 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;
}
diff --git a/sound/soc/codecs/cs-amp-lib.c b/sound/soc/codecs/cs-amp-lib.c
index 808e67c90f7c..d5f2025f1978 100644
--- a/sound/soc/codecs/cs-amp-lib.c
+++ b/sound/soc/codecs/cs-amp-lib.c
@@ -102,15 +102,20 @@ EXPORT_SYMBOL_NS_GPL(cs_amp_write_cal_coeffs, "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;
}
@@ -124,7 +129,7 @@ static struct cirrus_amp_efi_data *cs_amp_get_cal_efi_buffer(struct device *dev)
int ret;
/* Get real size of UEFI variable */
- status = cs_amp_get_efi_variable(CS_AMP_CAL_NAME, &CS_AMP_CAL_GUID, &data_size, NULL);
+ status = cs_amp_get_efi_variable(CS_AMP_CAL_NAME, &CS_AMP_CAL_GUID, NULL, &data_size, NULL);
if (status != EFI_BUFFER_TOO_SMALL)
return ERR_PTR(-ENOENT);
@@ -138,7 +143,7 @@ static struct cirrus_amp_efi_data *cs_amp_get_cal_efi_buffer(struct device *dev)
if (!data)
return ERR_PTR(-ENOMEM);
- status = cs_amp_get_efi_variable(CS_AMP_CAL_NAME, &CS_AMP_CAL_GUID, &data_size, data);
+ status = cs_amp_get_efi_variable(CS_AMP_CAL_NAME, &CS_AMP_CAL_GUID, NULL, &data_size, data);
if (status != EFI_SUCCESS) {
ret = -EINVAL;
goto err;
--
2.43.0
More information about the kernel-team
mailing list