Skip to content

Commit 0b4c982

Browse files
drivers: flash: flash_mcux_flexspi_hyperflash: don't access device ptr
Don't access device pointer from critical sections when programming the hyperflash, as this could cause a RWW hazard Signed-off-by: Daniel DeGrasse <ddegrasse@tenstorrent.com>
1 parent 99957e1 commit 0b4c982

File tree

1 file changed

+11
-14
lines changed

1 file changed

+11
-14
lines changed

drivers/flash/flash_mcux_flexspi_hyperflash.c

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -256,9 +256,8 @@ struct flash_flexspi_hyperflash_data {
256256
struct flash_parameters flash_parameters;
257257
};
258258

259-
static int flash_flexspi_hyperflash_wait_bus_busy(const struct device *dev)
259+
static int flash_flexspi_hyperflash_wait_bus_busy(struct flash_flexspi_hyperflash_data *data)
260260
{
261-
struct flash_flexspi_hyperflash_data *data = dev->data;
262261
flexspi_transfer_t transfer;
263262
int ret;
264263
bool is_busy;
@@ -289,9 +288,9 @@ static int flash_flexspi_hyperflash_wait_bus_busy(const struct device *dev)
289288
return ret;
290289
}
291290

292-
static int flash_flexspi_hyperflash_write_enable(const struct device *dev, uint32_t address)
291+
static int flash_flexspi_hyperflash_write_enable(struct flash_flexspi_hyperflash_data *data,
292+
uint32_t address)
293293
{
294-
struct flash_flexspi_hyperflash_data *data = dev->data;
295294
flexspi_transfer_t transfer;
296295
int ret;
297296

@@ -370,11 +369,9 @@ static int flash_flexspi_hyperflash_check_vendor_id(const struct device *dev)
370369
return ret;
371370
}
372371

373-
static int flash_flexspi_hyperflash_page_program(const struct device *dev, off_t
374-
offset, const void *buffer, size_t len)
372+
static int flash_flexspi_hyperflash_page_program(struct flash_flexspi_hyperflash_data *data,
373+
off_t offset, const void *buffer, size_t len)
375374
{
376-
struct flash_flexspi_hyperflash_data *data = dev->data;
377-
378375
flexspi_transfer_t transfer = {
379376
.deviceAddress = offset,
380377
.port = data->port,
@@ -464,23 +461,23 @@ static int flash_flexspi_hyperflash_write(const struct device *dev, off_t offset
464461
memc_flexspi_wait_bus_idle(&data->controller);
465462
}
466463
#endif
467-
ret = flash_flexspi_hyperflash_write_enable(dev, offset);
464+
ret = flash_flexspi_hyperflash_write_enable(data, offset);
468465
if (ret != 0) {
469466
LOG_ERR("failed to enable write");
470467
break;
471468
}
472469
#ifdef CONFIG_FLASH_MCUX_FLEXSPI_HYPERFLASH_WRITE_BUFFER
473-
ret = flash_flexspi_hyperflash_page_program(dev, offset,
470+
ret = flash_flexspi_hyperflash_page_program(data, offset,
474471
hyperflash_write_buf, i);
475472
#else
476-
ret = flash_flexspi_hyperflash_page_program(dev, offset, src, i);
473+
ret = flash_flexspi_hyperflash_page_program(data, offset, src, i);
477474
#endif
478475
if (ret != 0) {
479476
LOG_ERR("failed to write");
480477
break;
481478
}
482479

483-
ret = flash_flexspi_hyperflash_wait_bus_busy(dev);
480+
ret = flash_flexspi_hyperflash_wait_bus_busy(data);
484481
if (ret != 0) {
485482
LOG_ERR("failed to wait bus busy");
486483
break;
@@ -546,7 +543,7 @@ static int flash_flexspi_hyperflash_erase(const struct device *dev, off_t offset
546543
}
547544

548545
for (i = 0; i < num_sectors; i++) {
549-
ret = flash_flexspi_hyperflash_write_enable(dev, offset);
546+
ret = flash_flexspi_hyperflash_write_enable(data, offset);
550547
if (ret != 0) {
551548
LOG_ERR("failed to write_enable");
552549
break;
@@ -567,7 +564,7 @@ static int flash_flexspi_hyperflash_erase(const struct device *dev, off_t offset
567564
}
568565

569566
/* wait bus busy */
570-
ret = flash_flexspi_hyperflash_wait_bus_busy(dev);
567+
ret = flash_flexspi_hyperflash_wait_bus_busy(data);
571568
if (ret != 0) {
572569
LOG_ERR("failed to wait bus busy");
573570
break;

0 commit comments

Comments
 (0)