]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
ASoC: SDCA: Add bounds check for function address
authorCharles Keepax <ckeepax@opensource.cirrus.com>
Fri, 20 Dec 2024 17:35:14 +0000 (17:35 +0000)
committerMark Brown <broonie@kernel.org>
Tue, 24 Dec 2024 22:44:55 +0000 (22:44 +0000)
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>
include/sound/sdca.h
sound/soc/sdca/sdca_functions.c

index 3eea1dfec16cc6d6c86fa4c0922aef7ac7bbb963..973252d0adac10bec956861b85045bc1ca3928c6 100644 (file)
@@ -23,9 +23,9 @@ struct sdw_slave;
  * @name: human-readable string
  */
 struct sdca_function_desc {
-       u64 adr;
-       u32 type;
        const char *name;
+       u32 type;
+       u8 adr;
 };
 
 /**
index 46aa874bb0aaad30ac265971be8433675253a393..a69fdb9c8b15b22a7e73b197544546a57da227eb 100644 (file)
@@ -108,17 +108,12 @@ static int find_sdca_function(struct acpi_device *adev, void *data)
                return -EINVAL;
        }
 
-       /*
-        * The number of functions cannot exceed 8, we could use
-        * acpi_get_local_address() but the value is stored as u64 so
-        * we might as well avoid casts and intermediate levels
-        */
        ret = acpi_get_local_u64_address(adev->handle, &addr);
        if (ret < 0)
                return ret;
 
-       if (!addr) {
-               dev_err(dev, "no addr\n");
+       if (!addr || addr > 0x7) {
+               dev_err(dev, "invalid addr: 0x%llx\n", addr);
                return -ENODEV;
        }