Skip to content

Commit c36297b

Browse files
charleskeepaxbroonie
authored andcommitted
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>
1 parent 935cd06 commit c36297b

2 files changed

Lines changed: 4 additions & 9 deletions

File tree

include/sound/sdca.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@ struct sdw_slave;
2323
* @name: human-readable string
2424
*/
2525
struct sdca_function_desc {
26-
u64 adr;
27-
u32 type;
2826
const char *name;
27+
u32 type;
28+
u8 adr;
2929
};
3030

3131
/**

sound/soc/sdca/sdca_functions.c

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -108,17 +108,12 @@ static int find_sdca_function(struct acpi_device *adev, void *data)
108108
return -EINVAL;
109109
}
110110

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-
*/
116111
ret = acpi_get_local_u64_address(adev->handle, &addr);
117112
if (ret < 0)
118113
return ret;
119114

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);
122117
return -ENODEV;
123118
}
124119

0 commit comments

Comments
 (0)