From: Simon Glass <simon.glass@canonical.com> The SCMI agent uclass allocates strings for vendor, sub_vendor, agent_name, and protocols in the probe function but never frees them when the device is removed. This causes memory leaks when the device model is rebuilt, such as during test runs. Add a pre_remove function to free these allocated strings. Take care to only free sub_vendor and agent_name if they were actually allocated (they may point to the string literal "NA" when the corresponding SCMI calls are not supported). 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-developed-by: Claude <noreply@anthropic.com> --- drivers/firmware/scmi/scmi_agent-uclass.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/drivers/firmware/scmi/scmi_agent-uclass.c b/drivers/firmware/scmi/scmi_agent-uclass.c index 8c907c3b032..c77dd068c60 100644 --- a/drivers/firmware/scmi/scmi_agent-uclass.c +++ b/drivers/firmware/scmi/scmi_agent-uclass.c @@ -462,10 +462,31 @@ static int scmi_bind_protocols(struct udevice *dev) return ret; } +static int scmi_remove(struct udevice *dev) +{ + struct scmi_agent_priv *priv = dev_get_uclass_plat(dev); + + free(priv->vendor); + free(priv->protocols); + + /* + * Note: sub_vendor and agent_name may point to string literals "NA" + * when the corresponding SCMI calls are not supported; only free if + * they were allocated (i.e., not pointing to "NA") + */ + if (strcmp(priv->sub_vendor, "NA")) + free(priv->sub_vendor); + if (strcmp(priv->agent_name, "NA")) + free(priv->agent_name); + + return 0; +} + UCLASS_DRIVER(scmi_agent) = { .id = UCLASS_SCMI_AGENT, .name = "scmi_agent", .post_bind = scmi_bind_protocols, + .pre_remove = scmi_remove, .per_device_plat_auto = sizeof(struct scmi_agent_priv), .per_child_auto = sizeof(struct scmi_agent_proto_priv), }; -- 2.43.0