Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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>

authored by

Richard Fitzgerald and committed by
Mark Brown
959400ca cf6290ee

+34 -5
+1
include/sound/cs-amp-lib.h
··· 66 66 struct cs_amp_test_hooks { 67 67 efi_status_t (*get_efi_variable)(efi_char16_t *name, 68 68 efi_guid_t *guid, 69 + u32 *returned_attr, 69 70 unsigned long *size, 70 71 void *buf); 71 72
+23
sound/soc/codecs/cs-amp-lib-test.c
··· 89 89 /* Redirected get_efi_variable to simulate that the file is too short */ 90 90 static efi_status_t cs_amp_lib_test_get_efi_variable_nohead(efi_char16_t *name, 91 91 efi_guid_t *guid, 92 + u32 *returned_attr, 92 93 unsigned long *size, 93 94 void *buf) 94 95 { ··· 122 121 /* Redirected get_efi_variable to simulate that the count is larger than the file */ 123 122 static efi_status_t cs_amp_lib_test_get_efi_variable_bad_count(efi_char16_t *name, 124 123 efi_guid_t *guid, 124 + u32 *returned_attr, 125 125 unsigned long *size, 126 126 void *buf) 127 127 { ··· 166 164 /* Redirected get_efi_variable to simulate that the variable not found */ 167 165 static efi_status_t cs_amp_lib_test_get_efi_variable_none(efi_char16_t *name, 168 166 efi_guid_t *guid, 167 + u32 *returned_attr, 169 168 unsigned long *size, 170 169 void *buf) 171 170 { ··· 194 191 /* Redirected get_efi_variable to simulate reading a cal data blob */ 195 192 static efi_status_t cs_amp_lib_test_get_efi_variable(efi_char16_t *name, 196 193 efi_guid_t *guid, 194 + u32 *returned_attr, 197 195 unsigned long *size, 198 196 void *buf) 199 197 { ··· 221 217 222 218 memcpy(buf, priv->cal_blob, priv->cal_blob->size); 223 219 220 + if (returned_attr) { 221 + *returned_attr = EFI_VARIABLE_NON_VOLATILE | 222 + EFI_VARIABLE_BOOTSERVICE_ACCESS | 223 + EFI_VARIABLE_RUNTIME_ACCESS; 224 + } 225 + 224 226 return EFI_SUCCESS; 225 227 } 226 228 227 229 static efi_status_t cs_amp_lib_test_get_hp_cal_efi_variable(efi_char16_t *name, 228 230 efi_guid_t *guid, 231 + u32 *returned_attr, 229 232 unsigned long *size, 230 233 void *buf) 231 234 { ··· 258 247 KUNIT_ASSERT_GE_MSG(test, ksize(buf), priv->cal_blob->size, "Buffer to small"); 259 248 260 249 memcpy(buf, priv->cal_blob, priv->cal_blob->size); 250 + 251 + if (returned_attr) { 252 + *returned_attr = EFI_VARIABLE_NON_VOLATILE | 253 + EFI_VARIABLE_BOOTSERVICE_ACCESS | 254 + EFI_VARIABLE_RUNTIME_ACCESS; 255 + } 261 256 262 257 return EFI_SUCCESS; 263 258 } ··· 803 786 804 787 static efi_status_t cs_amp_lib_test_get_efi_variable_lenovo_d0(efi_char16_t *name, 805 788 efi_guid_t *guid, 789 + u32 *returned_attr, 806 790 unsigned long *size, 807 791 void *buf) 808 792 { ··· 822 804 823 805 static efi_status_t cs_amp_lib_test_get_efi_variable_lenovo_d1(efi_char16_t *name, 824 806 efi_guid_t *guid, 807 + u32 *returned_attr, 825 808 unsigned long *size, 826 809 void *buf) 827 810 { ··· 841 822 842 823 static efi_status_t cs_amp_lib_test_get_efi_variable_lenovo_00(efi_char16_t *name, 843 824 efi_guid_t *guid, 825 + u32 *returned_attr, 844 826 unsigned long *size, 845 827 void *buf) 846 828 { ··· 893 873 894 874 static efi_status_t cs_amp_lib_test_get_efi_variable_buf_too_small(efi_char16_t *name, 895 875 efi_guid_t *guid, 876 + u32 *returned_attr, 896 877 unsigned long *size, 897 878 void *buf) 898 879 { ··· 914 893 915 894 static efi_status_t cs_amp_lib_test_get_efi_variable_hp_30(efi_char16_t *name, 916 895 efi_guid_t *guid, 896 + u32 *returned_attr, 917 897 unsigned long *size, 918 898 void *buf) 919 899 { ··· 933 911 934 912 static efi_status_t cs_amp_lib_test_get_efi_variable_hp_31(efi_char16_t *name, 935 913 efi_guid_t *guid, 914 + u32 *returned_attr, 936 915 unsigned long *size, 937 916 void *buf) 938 917 {
+10 -5
sound/soc/codecs/cs-amp-lib.c
··· 245 245 246 246 static efi_status_t cs_amp_get_efi_variable(efi_char16_t *name, 247 247 efi_guid_t *guid, 248 + u32 *returned_attr, 248 249 unsigned long *size, 249 250 void *buf) 250 251 { 251 252 u32 attr; 252 253 253 - KUNIT_STATIC_STUB_REDIRECT(cs_amp_get_efi_variable, name, guid, size, buf); 254 + if (!returned_attr) 255 + returned_attr = &attr; 256 + 257 + KUNIT_STATIC_STUB_REDIRECT(cs_amp_get_efi_variable, name, guid, 258 + returned_attr, size, buf); 254 259 255 260 if (efi_rt_services_supported(EFI_RT_SUPPORTED_GET_VARIABLE)) 256 - return efi.get_variable(name, guid, &attr, size, buf); 261 + return efi.get_variable(name, guid, returned_attr, size, buf); 257 262 258 263 return EFI_NOT_FOUND; 259 264 } ··· 293 288 for (i = 0; i < ARRAY_SIZE(cs_amp_lib_cal_efivars); i++) { 294 289 status = cs_amp_get_efi_variable(cs_amp_lib_cal_efivars[i].name, 295 290 cs_amp_lib_cal_efivars[i].guid, 296 - &data_size, NULL); 291 + NULL, &data_size, NULL); 297 292 if (status == EFI_BUFFER_TOO_SMALL) 298 293 break; 299 294 } ··· 313 308 314 309 status = cs_amp_get_efi_variable(cs_amp_lib_cal_efivars[i].name, 315 310 cs_amp_lib_cal_efivars[i].guid, 316 - &data_size, data); 311 + NULL, &data_size, data); 317 312 if (status != EFI_SUCCESS) { 318 313 ret = -EINVAL; 319 314 goto err; ··· 457 452 int i, ret; 458 453 459 454 size = sizeof(spkid); 460 - status = cs_amp_get_efi_variable(info->name, info->guid, &size, &spkid); 455 + status = cs_amp_get_efi_variable(info->name, info->guid, NULL, &size, &spkid); 461 456 ret = cs_amp_convert_efi_status(status); 462 457 if (ret < 0) 463 458 return ret;