Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

nvs_write: Bad documented return value. #34204

Closed
Vladimirek opened this issue Apr 11, 2021 · 8 comments
Closed

nvs_write: Bad documented return value. #34204

Vladimirek opened this issue Apr 11, 2021 · 8 comments
Assignees
Labels
area: API Changes to public APIs area: Flash Stale

Comments

@Vladimirek
Copy link

Docs say:

zephyr/include/fs/nvs.h

Lines 105 to 106 in 1342d12

* @return Number of bytes written. On success, it will be equal to the number
* of bytes requested to be written. On error returns -ERRNO code.

But when the key is already in flash with the same value zero is returned:

zephyr/subsys/fs/nvs/nvs.c

Lines 842 to 846 in 6acc4a2

/* compare the data and if equal return 0 */
rc = nvs_flash_block_cmp(fs, rd_addr, data, len);
if (rc <= 0) {
return rc;
}

Need update code or doc header.

@Laczen
Copy link
Collaborator

Laczen commented Apr 11, 2021

@Vladimirek, thanks for reporting this. I am unsure what the error is, when a rewrite of the same data is done, nothing is written to flash, so nvs reports 0 (as documented).

Wether this operation is succesful or not, this can be discussed.

@Vladimirek
Copy link
Author

so nvs reports 0 (as documented).
That is exactly what I missing. Simple note about 0 will be describe the situation exactly.
Number of bytes written. On success, it will be equal to the number of bytes requested to be written. Zero if value already present. On error returns -ERRNO code.
Yes I know that there is documented on other place, but who have a time read it all :-)

@nvlsianpu
Copy link
Collaborator

I think from user perspective API should return the number of bytes requested to be written for this case as well.

@galak galak added area: API Changes to public APIs area: Flash question labels Apr 13, 2021
@nvlsianpu
Copy link
Collaborator

Will response to this in a patch.

@Laczen
Copy link
Collaborator

Laczen commented Apr 15, 2021

@nvlsianpu, I don't think a patch is needed. It should be possible for a user to distinguish between a real write to flash and a trial to rewrite. If a documentation update is required i leave up to you.

@github-actions
Copy link

This issue has been marked as stale because it has been open (more than) 60 days with no activity. Remove the stale label or add a comment saying that you would like to have the label removed otherwise this issue will automatically be closed in 14 days. Note, that you can always re-open a closed issue at any time.

@github-actions github-actions bot added the Stale label Jun 15, 2021
@nvlsianpu nvlsianpu removed the Stale label Jun 15, 2021
@github-actions
Copy link

This issue has been marked as stale because it has been open (more than) 60 days with no activity. Remove the stale label or add a comment saying that you would like to have the label removed otherwise this issue will automatically be closed in 14 days. Note, that you can always re-open a closed issue at any time.

@jefffhaynes
Copy link

@nvlsianpu, I don't think a patch is needed. It should be possible for a user to distinguish between a real write to flash and a trial to rewrite. If a documentation update is required i leave up to you.

Decisions like this are why zephyr isn't as successful as it could be. The user doesn't care how the data was written, only that it was written. This just makes the API needlessly confusing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: API Changes to public APIs area: Flash Stale
Projects
None yet
Development

No branches or pull requests

5 participants