Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions drivers/flash/flash_mcux_flexspi_hyperflash.c
Original file line number Diff line number Diff line change
Expand Up @@ -395,6 +395,14 @@ static int flash_flexspi_hyperflash_read(const struct device *dev, off_t offset,
{
struct flash_flexspi_hyperflash_data *data = dev->data;

if (len == 0) {
return 0;
}

if (!buffer) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not compliant with Coding Guidelines, Zephyr rule 85 (https://gitlab.com/MISRA/MISRA-C/MISRA-C-2012/Example-Suite/-/blob/master/R_14_04.c), should be buffer == NULL.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, now I see that the entire driver keeps that style, so the decision is on you.

return -EINVAL;
}

uint8_t *src = memc_flexspi_get_ahb_address(&data->controller,
data->port,
offset);
Expand Down
9 changes: 9 additions & 0 deletions drivers/flash/flash_mcux_flexspi_mx25um51345g.c
Original file line number Diff line number Diff line change
Expand Up @@ -361,6 +361,15 @@ static int flash_flexspi_nor_read(const struct device *dev, off_t offset,
void *buffer, size_t len)
{
struct flash_flexspi_nor_data *data = dev->data;

if (len == 0) {
return 0;
}

if (!buffer) {
return -EINVAL;
}

uint8_t *src = memc_flexspi_get_ahb_address(data->controller,
data->port,
offset);
Expand Down
4 changes: 4 additions & 0 deletions drivers/flash/flash_mcux_flexspi_nor.c
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,10 @@ static int flash_flexspi_nor_read(const struct device *dev, off_t offset,
{
struct flash_flexspi_nor_data *data = dev->data;

if (len == 0) {
return 0;
}

if (!buffer) {
return -EINVAL;
}
Expand Down
4 changes: 4 additions & 0 deletions drivers/flash/flash_nxp_s32_qspi.c
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,10 @@ int nxp_s32_qspi_read(const struct device *dev, off_t offset, void *dest, size_t
Qspi_Ip_StatusType status;
int ret = 0;

if (size == 0) {
return 0;
}

if (!dest) {
return -EINVAL;
}
Expand Down
12 changes: 12 additions & 0 deletions include/zephyr/drivers/flash.h
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,18 @@ int flash_params_get_erase_cap(const struct flash_parameters *p)
* @{
*/

/**
* @brief Flash read implementation handler type
*
* @return 0 on success or len is zero, -EINVAL if page offset doesn't exist or data
* destination is NULL
*
* @note Any necessary read protection management must be performed by
* the driver.
*
* For consistency across implementations, value check len parameter equal zero and
* return result 0 before validating the data destination parameter.
*/
typedef int (*flash_api_read)(const struct device *dev, off_t offset,
void *data,
size_t len);
Expand Down