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

Configure Feed

Select the types of activity you want to include in your feed.

ASoC: SDCA: Add bounds check for function address

SDCA only supports 3-bits for the function address, but the ACPI value
is 64-bits. Update the code that parses this to do a bounds check
and error out on invalid addresses. Currently, an invalid address
would truncate to the bottom 3-bits when used and thus use a likely
incorrect address. With the bounds check, it is also now safe to
shrink the size of the adr member of sdca_function_desc to a u8 and
rearrange the struct members to pack better with the new size of adr.

Signed-off-by: Charles Keepax <ckeepax@opensource.cirrus.com>
Link: https://patch.msgid.link/20241220173516.907406-3-ckeepax@opensource.cirrus.com
Signed-off-by: Mark Brown <broonie@kernel.org>

authored by

Charles Keepax and committed by
Mark Brown
c36297b1 935cd06b

+4 -9
+2 -2
include/sound/sdca.h
··· 23 23 * @name: human-readable string 24 24 */ 25 25 struct sdca_function_desc { 26 - u64 adr; 27 - u32 type; 28 26 const char *name; 27 + u32 type; 28 + u8 adr; 29 29 }; 30 30 31 31 /**
+2 -7
sound/soc/sdca/sdca_functions.c
··· 108 108 return -EINVAL; 109 109 } 110 110 111 - /* 112 - * The number of functions cannot exceed 8, we could use 113 - * acpi_get_local_address() but the value is stored as u64 so 114 - * we might as well avoid casts and intermediate levels 115 - */ 116 111 ret = acpi_get_local_u64_address(adev->handle, &addr); 117 112 if (ret < 0) 118 113 return ret; 119 114 120 - if (!addr) { 121 - dev_err(dev, "no addr\n"); 115 + if (!addr || addr > 0x7) { 116 + dev_err(dev, "invalid addr: 0x%llx\n", addr); 122 117 return -ENODEV; 123 118 } 124 119