fix(platform/rtthread/usbh_dfs): fix mem free

This commit is contained in:
sakumisu 2024-08-31 16:02:30 +08:00
parent 02ac1db3ff
commit a8a5d95f8f

View File

@ -9,7 +9,7 @@
#include "rtthread.h" #include "rtthread.h"
#include <dfs_fs.h> #include <dfs_fs.h>
#define DEV_FORMAT "/sd%c" #define DEV_FORMAT "/dev/sd%c"
#ifndef CONFIG_USB_DFS_MOUNT_POINT #ifndef CONFIG_USB_DFS_MOUNT_POINT
#define CONFIG_USB_DFS_MOUNT_POINT "/" #define CONFIG_USB_DFS_MOUNT_POINT "/"
@ -46,7 +46,7 @@ static rt_err_t rt_udisk_init(rt_device_t dev)
} }
static ssize_t rt_udisk_read(rt_device_t dev, rt_off_t pos, void *buffer, static ssize_t rt_udisk_read(rt_device_t dev, rt_off_t pos, void *buffer,
rt_size_t size) rt_size_t size)
{ {
struct usbh_msc *msc_class = (struct usbh_msc *)dev->user_data; struct usbh_msc *msc_class = (struct usbh_msc *)dev->user_data;
int ret; int ret;
@ -85,7 +85,7 @@ static ssize_t rt_udisk_read(rt_device_t dev, rt_off_t pos, void *buffer,
} }
static ssize_t rt_udisk_write(rt_device_t dev, rt_off_t pos, const void *buffer, static ssize_t rt_udisk_write(rt_device_t dev, rt_off_t pos, const void *buffer,
rt_size_t size) rt_size_t size)
{ {
struct usbh_msc *msc_class = (struct usbh_msc *)dev->user_data; struct usbh_msc *msc_class = (struct usbh_msc *)dev->user_data;
int ret; int ret;
@ -175,15 +175,17 @@ int udisk_init(struct usbh_msc *msc_class)
ret = usbh_msc_scsi_read10(msc_class, 0, msc_sector, 1); ret = usbh_msc_scsi_read10(msc_class, 0, msc_sector, 1);
if (ret != RT_EOK) { if (ret != RT_EOK) {
rt_kprintf("usb mass_storage read failed\n"); rt_kprintf("usb mass_storage read failed\n");
rt_free(dev);
return ret; return ret;
} }
for (i = 0; i < 16; i++) { for (i = 0; i < 4; i++) {
/* Get the first partition */ /* Get the first partition */
ret = dfs_filesystem_get_partition(&part0, msc_sector, i); ret = dfs_filesystem_get_partition(&part0, msc_sector, i);
if (ret == RT_EOK) { if (ret == RT_EOK) {
rt_kprintf("Found partition %d: type = %d, offet=0x%x, size=0x%x\n", rt_kprintf("Found partition %d: type = %d, offet=0x%x, size=0x%x\n",
i, part0.type, part0.offset, part0.size); i, part0.type, part0.offset, part0.size);
break;
} else { } else {
break; break;
} }
@ -219,6 +221,8 @@ void usbh_msc_run(struct usbh_msc *msc_class)
void usbh_msc_stop(struct usbh_msc *msc_class) void usbh_msc_stop(struct usbh_msc *msc_class)
{ {
struct rt_device *dev;
char name[CONFIG_USBHOST_DEV_NAMELEN]; char name[CONFIG_USBHOST_DEV_NAMELEN];
char mount_point[CONFIG_USBHOST_DEV_NAMELEN]; char mount_point[CONFIG_USBHOST_DEV_NAMELEN];
@ -226,5 +230,9 @@ void usbh_msc_stop(struct usbh_msc *msc_class)
snprintf(mount_point, CONFIG_USBHOST_DEV_NAMELEN, CONFIG_USB_DFS_MOUNT_POINT, msc_class->sdchar); snprintf(mount_point, CONFIG_USBHOST_DEV_NAMELEN, CONFIG_USB_DFS_MOUNT_POINT, msc_class->sdchar);
dfs_unmount(mount_point); dfs_unmount(mount_point);
rt_device_unregister(rt_device_find(name)); dev = rt_device_find(name);
if (dev) {
rt_device_unregister(dev);
rt_free(dev);
}
} }