RT-Thread 4.1.0
SD 驱动框架
SD 初始化失败移除 blk_dev
时存在双向链表 next
和 prev
都为 NULL
的情况,造成死循环。
修改 rt_mmcsd_blk_remove
:
void rt_mmcsd_blk_remove(struct rt_mmcsd_card *card)
{
rt_list_t *l, *n;
struct mmcsd_blk_device *blk_dev;
+ if(card == RT_NULL)
+ {
+ LOG_E("card is null!");
+ return;
+ }
+
+ if(rt_list_isempty(&card->blk_devices))
+ {
+ LOG_E("card blk_devices is empty!");
+ return;
+ }
+
+ if ((&card->blk_devices)->next == RT_NULL)
+ {
+ LOG_E("card blk_devices is null!");
+ return;
+ }
for (l = (&card->blk_devices)->next, n = l->next; l != &card->blk_devices; l = n, n=n->next)
{
blk_dev = (struct mmcsd_blk_device *)rt_list_entry(l, struct mmcsd_blk_device, list);
if (blk_dev->card == card)
{
/* unmount file system */
const char * mounted_path = dfs_filesystem_get_mounted_path(&(blk_dev->dev));
if (mounted_path)
{
dfs_unmount(mounted_path);
LOG_D("unmount file system %s for device %s.\r\n", mounted_path, blk_dev->dev.parent.name);
}
rt_sem_delete(blk_dev->part.lock);
rt_device_unregister(&blk_dev->dev);
rt_list_remove(&blk_dev->list);
rt_free(blk_dev);
}
}
}
...大约 1 分钟