From 7b8f8d961587c66312d8b68f3c931a065b9c1b7b Mon Sep 17 00:00:00 2001 From: armink Date: Sun, 28 Jan 2018 18:29:33 +0800 Subject: [PATCH] [DeviceDriver][SFUD] Fix flash device lock not detach when an error occurred. #1167 --- components/drivers/spi/spi_flash_sfud.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/components/drivers/spi/spi_flash_sfud.c b/components/drivers/spi/spi_flash_sfud.c index c94effa61..d86179aaf 100644 --- a/components/drivers/spi/spi_flash_sfud.c +++ b/components/drivers/spi/spi_flash_sfud.c @@ -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); -- GitLab