Skip to content

Commit cd30f28

Browse files
pabigotmbolivar-nordic
authored andcommitted
[nrf fromlist] drivers: flash: nrf_qspi_nor: clean up lock/unlock idioms
Having a completion wait function release a lock internally only when the operation fails is confusing. Remove that feature, and make the lock and unlock operations explicit and paired. This makes it much more clear how to properly handle transactions that require multiple calls to the HAL. Signed-off-by: Peter Bigot <[email protected]> Signed-off-by: Sigvart Hovland <[email protected]> (cherry picked from commit 35d3836)
1 parent 4174ae9 commit cd30f28

File tree

1 file changed

+11
-8
lines changed

1 file changed

+11
-8
lines changed

drivers/flash/nrf_qspi_nor.c

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -248,8 +248,6 @@ static inline void qspi_wait_for_completion(struct device *dev,
248248

249249
if (res == NRFX_SUCCESS) {
250250
k_sem_take(&dev_data->sync, K_FOREVER);
251-
} else {
252-
qspi_unlock(dev);
253251
}
254252
}
255253

@@ -273,7 +271,6 @@ static void qspi_handler(nrfx_qspi_evt_t event, void *p_context)
273271

274272
if (event == NRFX_QSPI_EVENT_DONE) {
275273
qspi_complete(dev);
276-
qspi_unlock(dev);
277274
}
278275
}
279276

@@ -319,14 +316,14 @@ static int qspi_erase(struct device *dev, u32_t addr, u32_t size)
319316
return -EINVAL;
320317
}
321318

322-
int rv = -EIO;
319+
int rv = 0;
323320
const struct qspi_nor_config *params = dev->config_info;
324321

325-
while (size) {
322+
qspi_lock(dev);
323+
while ((rv == 0) && (size > 0)) {
326324
nrfx_err_t res = !NRFX_SUCCESS;
327325
u32_t adj = 0;
328326

329-
qspi_lock(dev);
330327
if (size == params->size) {
331328
/* chip erase */
332329
res = nrfx_qspi_chip_erase();
@@ -353,11 +350,13 @@ static int qspi_erase(struct device *dev, u32_t addr, u32_t size)
353350
size -= adj;
354351
} else {
355352
LOG_ERR("erase error at 0x%lx size %zu", (long)addr, size);
356-
return rv;
353+
rv = qspi_get_zephyr_ret_code(res);
357354
}
358355
}
359356

360-
return 0;
357+
qspi_unlock(dev);
358+
359+
return rv;
361360
}
362361

363362
/**
@@ -529,6 +528,8 @@ static int qspi_nor_read(struct device *dev, off_t addr, void *dest,
529528

530529
qspi_wait_for_completion(dev, res);
531530

531+
qspi_unlock(dev);
532+
532533
int rc = qspi_get_zephyr_ret_code(res);
533534

534535
if ((rc == 0) && (dest != dptr)) {
@@ -621,6 +622,8 @@ static int qspi_nor_write(struct device *dev, off_t addr, const void *src,
621622
qspi_wait_for_completion(dev, res);
622623
}
623624

625+
qspi_unlock(dev);
626+
624627
return qspi_get_zephyr_ret_code(res);
625628
}
626629

0 commit comments

Comments
 (0)