Skip to content

[Bug] SDIO 驱动注销失败与节点内存泄漏风险 #11801

Description

@Huoyanlifusu

RT-Thread Version

master e538ad7

Affected area

Device drivers

Hardware/BSP vendor

Not applicable / Other

Architecture

Not applicable / Other

Board and hardware details

无特定版型要求

Develop Toolchain

GCC

Describe the bug

尽管多数 sdio 设备(比如 mmc/sd卡)不会热插拔,出于代码稳定角度考虑,建议进行这几处优化。

  1. 系统加载多个 sdio 驱动,在卸载驱动时,链表未及时退出,sd 可能会被下一轮循环覆盖为 NULL
    for (l = (&sdio_drivers)->next; l != &sdio_drivers; l = l->next)
    {
        sd = (struct sdio_driver *)rt_list_entry(l, struct sdio_driver, list);
        if (sd->drv != driver)
        {
            sd = RT_NULL;
        }
    }
  1. 目前释放 sd 指针动作在软件找到卡后才进行,有内存泄漏风险,这个指针的申请动作不依赖 SDIO 卡,因此释放也不需要依赖 SDIO 卡匹配到与否。
if (card != RT_NULL)
{
    driver->remove(card);
    rt_list_remove(&sd->list);
    rt_free(sd);
}
  1. 可选优化:使用 rt_list_for_each_entry 替代 rt_list_entry + for 的写法

Other additional context

No response

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions