Skip to content

Commit f8ad05e

Browse files
committed
drivers: flash: Align NXP flash drivers on parameter checking
Parameter checking of flash read API expects checking for len == 0 before checking dest buffer validation. Fixes #87021 Signed-off-by: David Leach <david.leach@nxp.com>
1 parent 4cb48fa commit f8ad05e

File tree

4 files changed

+25
-0
lines changed

4 files changed

+25
-0
lines changed

drivers/flash/flash_mcux_flexspi_hyperflash.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -395,6 +395,14 @@ static int flash_flexspi_hyperflash_read(const struct device *dev, off_t offset,
395395
{
396396
struct flash_flexspi_hyperflash_data *data = dev->data;
397397

398+
if (len == 0) {
399+
return 0;
400+
}
401+
402+
if (!buffer) {
403+
return -EINVAL;
404+
}
405+
398406
uint8_t *src = memc_flexspi_get_ahb_address(&data->controller,
399407
data->port,
400408
offset);

drivers/flash/flash_mcux_flexspi_mx25um51345g.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -361,6 +361,15 @@ static int flash_flexspi_nor_read(const struct device *dev, off_t offset,
361361
void *buffer, size_t len)
362362
{
363363
struct flash_flexspi_nor_data *data = dev->data;
364+
365+
if (len == 0) {
366+
return 0;
367+
}
368+
369+
if (!buffer) {
370+
return -EINVAL;
371+
}
372+
364373
uint8_t *src = memc_flexspi_get_ahb_address(data->controller,
365374
data->port,
366375
offset);

drivers/flash/flash_mcux_flexspi_nor.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -325,6 +325,10 @@ static int flash_flexspi_nor_read(const struct device *dev, off_t offset,
325325
{
326326
struct flash_flexspi_nor_data *data = dev->data;
327327

328+
if (len == 0) {
329+
return 0;
330+
}
331+
328332
if (!buffer) {
329333
return -EINVAL;
330334
}

drivers/flash/flash_nxp_s32_qspi.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,10 @@ int nxp_s32_qspi_read(const struct device *dev, off_t offset, void *dest, size_t
5959
Qspi_Ip_StatusType status;
6060
int ret = 0;
6161

62+
if (size == 0) {
63+
return 0;
64+
}
65+
6266
if (!dest) {
6367
return -EINVAL;
6468
}

0 commit comments

Comments
 (0)