From b6d955c648b901d8365f463f633e9ddbe6c56d66 Mon Sep 17 00:00:00 2001 From: Ryan McClelland Date: Mon, 30 Jun 2025 19:23:55 -0700 Subject: [PATCH] drivers: i3c: check addr slot is free only if it's different The bus helpers for SETDASA and SETNEWDA could have the same dynamic address assigned as it's static addr for SETDASA or as it's dynamic addr for SETNEWDA. (Althrough, only a clown would set the new dynamic address to the same old dynamic address, it is still a valid address to set to). Signed-off-by: Ryan McClelland --- drivers/i3c/i3c_common.c | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/drivers/i3c/i3c_common.c b/drivers/i3c/i3c_common.c index 6d9ea2c1eb4..a478941d671 100644 --- a/drivers/i3c/i3c_common.c +++ b/drivers/i3c/i3c_common.c @@ -938,10 +938,13 @@ int i3c_bus_setdasa(struct i3c_device_desc *desc, uint8_t dynamic_addr) struct i3c_ccc_address dyn_addr; int ret; - /* check if the addressed is free */ - if (!i3c_addr_slots_is_free(&data->attached_dev.addr_slots, dynamic_addr)) { - LOG_ERR("%s: Address 0x%02x is already in use.", desc->bus->name, dynamic_addr); - return -EADDRNOTAVAIL; + /* check if the addressed is free, if the requested DA is different from the SA */ + if (desc->static_addr != dynamic_addr) { + if (!i3c_addr_slots_is_free(&data->attached_dev.addr_slots, dynamic_addr)) { + LOG_ERR("%s: Address 0x%02x is already in use.", desc->bus->name, + dynamic_addr); + return -EADDRNOTAVAIL; + } } /* @@ -978,10 +981,13 @@ int i3c_bus_setnewda(struct i3c_device_desc *desc, uint8_t dynamic_addr) uint8_t old_da; int ret; - /* check if the addressed is free */ - if (!i3c_addr_slots_is_free(&data->attached_dev.addr_slots, dynamic_addr)) { - LOG_ERR("%s: Address 0x%02x is already in use.", desc->bus->name, dynamic_addr); - return -EADDRNOTAVAIL; + /* check if the addressed is free, also a 'clown' could set the same DA */ + if (desc->dynamic_addr != dynamic_addr) { + if (!i3c_addr_slots_is_free(&data->attached_dev.addr_slots, dynamic_addr)) { + LOG_ERR("%s: Address 0x%02x is already in use.", desc->bus->name, + dynamic_addr); + return -EADDRNOTAVAIL; + } } /*