mirror of
https://github.com/RT-Thread/rt-thread.git
synced 2025-01-18 13:33:31 +08:00
[DeviceDriver][SFUD] Fix flash device lock not detach when an error occurred. #1167
This commit is contained in:
parent
c63d9a8864
commit
7b8f8d9615
@ -250,8 +250,13 @@ rt_spi_flash_device_t rt_sfud_flash_probe(const char *spi_flash_dev_name, const
|
||||
spi_flash_dev_name_bak = (char *) rt_malloc(rt_strlen(spi_flash_dev_name) + 1);
|
||||
spi_dev_name_bak = (char *) rt_malloc(rt_strlen(spi_dev_name) + 1);
|
||||
|
||||
if (rtt_dev && sfud_dev && spi_flash_dev_name_bak && spi_dev_name_bak) {
|
||||
if (rtt_dev) {
|
||||
rt_memset(rtt_dev, 0, sizeof(struct spi_flash_device));
|
||||
/* initialize lock */
|
||||
rt_mutex_init(&(rtt_dev->lock), spi_flash_dev_name, RT_IPC_FLAG_FIFO);
|
||||
}
|
||||
|
||||
if (rtt_dev && sfud_dev && spi_flash_dev_name_bak && spi_dev_name_bak) {
|
||||
rt_memset(sfud_dev, 0, sizeof(sfud_flash));
|
||||
rt_strncpy(spi_flash_dev_name_bak, spi_flash_dev_name, rt_strlen(spi_flash_dev_name));
|
||||
rt_strncpy(spi_dev_name_bak, spi_dev_name, rt_strlen(spi_dev_name));
|
||||
@ -268,8 +273,6 @@ rt_spi_flash_device_t rt_sfud_flash_probe(const char *spi_flash_dev_name, const
|
||||
}
|
||||
sfud_dev->spi.name = spi_dev_name_bak;
|
||||
rt_spi_configure(rtt_dev->rt_spi_device, &cfg);
|
||||
/* initialize lock */
|
||||
rt_mutex_init(&(rtt_dev->lock), spi_flash_dev_name, RT_IPC_FLAG_FIFO);
|
||||
}
|
||||
/* SFUD flash device initialize */
|
||||
{
|
||||
@ -308,6 +311,10 @@ rt_spi_flash_device_t rt_sfud_flash_probe(const char *spi_flash_dev_name, const
|
||||
}
|
||||
|
||||
error:
|
||||
|
||||
if (rtt_dev) {
|
||||
rt_mutex_detach(&(rtt_dev->lock));
|
||||
}
|
||||
/* may be one of objects memory was malloc success, so need free all */
|
||||
rt_free(rtt_dev);
|
||||
rt_free(sfud_dev);
|
||||
|
Loading…
x
Reference in New Issue
Block a user