Skip to content

Commit

Permalink
drivers: flash: spi_nor: ensure paired calling of acquire/release_device
Browse files Browse the repository at this point in the history
Adjusted the code to guarantee resource release irrespective of operation
success or failure.
Fixes #67336

Signed-off-by: Pisit Sawangvonganan <[email protected]>
  • Loading branch information
ndrs-pst authored and fabiobaltieri committed Jan 10, 2024
1 parent b85b7a3 commit c65b1bb
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions drivers/flash/spi_nor.c
Original file line number Diff line number Diff line change
Expand Up @@ -659,6 +659,7 @@ static int mxicy_configure(const struct device *dev, const uint8_t *jedec_id)

ret = mxicy_rdcr(dev);
if (ret < 0) {
release_device(dev);
return ret;
}
current_cr = ret;
Expand Down Expand Up @@ -1231,6 +1232,7 @@ static int spi_nor_configure(const struct device *dev)
rc = exit_dpd(dev);
if (rc < 0) {
LOG_ERR("Failed to exit DPD (%d)", rc);
release_device(dev);
return -ENODEV;
}

Expand Down Expand Up @@ -1280,12 +1282,12 @@ static int spi_nor_configure(const struct device *dev)
rc = spi_nor_wrsr(dev, rc & ~cfg->has_lock);
}

release_device(dev);

if (rc != 0) {
LOG_ERR("BP clear failed: %d\n", rc);
return -ENODEV;
}

release_device(dev);
}

#ifdef CONFIG_SPI_NOR_SFDP_MINIMAL
Expand Down

0 comments on commit c65b1bb

Please sign in to comment.