diff options
author | Heinrich Schuchardt | 2021-03-18 07:46:07 +0100 |
---|---|---|
committer | Heinrich Schuchardt | 2021-03-25 20:15:30 +0100 |
commit | 57cba225faf60f16f63b7aaba0dcd991a69666b5 (patch) | |
tree | 5e49f1a97609367f8ade9d44968efa071b171b15 /drivers/dfu | |
parent | cbea241e935ec754df44d5de0ad20b801f2d3f90 (diff) |
dfu: dfu_sf: avoid double free of SPI device
Multiple DFU entities may share the same SPI device. We must make sure that
the SPI device is only freed once.
When using the driver model it is not necessary to free the SPI device.
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Acked-by: Lukasz Majewski <lukma@denx.de>
Diffstat (limited to 'drivers/dfu')
-rw-r--r-- | drivers/dfu/dfu_sf.c | 18 |
1 files changed, 17 insertions, 1 deletions
diff --git a/drivers/dfu/dfu_sf.c b/drivers/dfu/dfu_sf.c index 76b629a334f..8f8c4259772 100644 --- a/drivers/dfu/dfu_sf.c +++ b/drivers/dfu/dfu_sf.c @@ -87,7 +87,23 @@ static unsigned int dfu_polltimeout_sf(struct dfu_entity *dfu) static void dfu_free_entity_sf(struct dfu_entity *dfu) { - spi_flash_free(dfu->data.sf.dev); + /* + * In the DM case it is not necessary to free the SPI device. + * For the non-DM case we must ensure that the the SPI device is only + * freed once. + */ + if (!CONFIG_IS_ENABLED(DM_SPI_FLASH)) { + struct spi_flash *dev = dfu->data.sf.dev; + + if (!dev) + return; + dfu->data.sf.dev = NULL; + list_for_each_entry(dfu, &dfu_list, list) { + if (dfu->data.sf.dev == dev) + dfu->data.sf.dev = NULL; + } + spi_flash_free(dev); + } } static struct spi_flash *parse_dev(char *devstr) |