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

Settings Module - settings_line_val_read() returning -EINVAL instead of 0 for deleted setting entries #17415

Closed
DeclanTraill opened this issue Jul 9, 2019 · 13 comments · Fixed by #17446
Labels
area: Settings Settings subsystem bug The issue is a bug, or the PR is fixing a bug priority: low Low impact/importance bug
Milestone

Comments

@DeclanTraill
Copy link
Contributor

DeclanTraill commented Jul 9, 2019

When using the Settings module we found that when we delete a settings entry, upon reset and settings load, it was being reloaded with the previous value prior to the deleted entry.

Upon investigation I found that the reason for this was that the settings_line_val_read() function was returning -EINVAL when it read the deleted (NULL) entry, rather than a settings size of 0, so our code was not loading the NULL entry but retaining the previous version of the setting.

I have made a suggested change (see attached image for code before & after the fix) to that function and it seems to fix the problem here. Could you please see if this is a fix that should be made?

Regards,
Declan Traill

Zephyr1_14_Settings_Suggested_Change

@DeclanTraill DeclanTraill added the bug The issue is a bug, or the PR is fixing a bug label Jul 9, 2019
@aescolar aescolar added the area: Settings Settings subsystem label Jul 9, 2019
@aescolar
Copy link
Member

aescolar commented Jul 9, 2019

CC @nvlsianpu

@nvlsianpu
Copy link
Collaborator

@DeclanTraill Thanks for the bug registration!

@DeclanTraill DeclanTraill changed the title Zephyr 1.14, Settings Module - settings_line_val_read() returning -EINVAL instead of 0 for deleted setting entries Settings Module - settings_line_val_read() returning -EINVAL instead of 0 for deleted setting entries Jul 10, 2019
@Laczen
Copy link
Collaborator

Laczen commented Jul 10, 2019

@DeclanTraill, I agree with the patch submitted in #17446, but it might be easier to detect a delete by using the len that is provided in the h_set routine. This len should already be zero, so you can detect it early instead of doing it using the read function. It is a bit strange to do a read of a deleted item. Not all backends will give you this information, nvs for example will not call any h_set routine when a variable has been deleted.

@nvlsianpu
Copy link
Collaborator

@DeclanTraill What is the reason behind that you are using base64 encoding? I'm asking because was thinking about depreciate this as seams to be not needed and only over complicates the implementation.

@nwsetec
Copy link
Contributor

nwsetec commented Jul 11, 2019

Hi @nvlsianpu I'm working on the same project as Declan. We are using base64 encoding as we have products in the field running Zephyr 1.13 and are planning to update them to 1.14 (which I believe was using base64 only) and this was the easiest path we could see. This raises something I was wondering about, can the settings subsystem work over an nffs file without base64 decoding?

@DeclanTraill
Copy link
Contributor Author

DeclanTraill commented Jul 11, 2019 via email

@Laczen
Copy link
Collaborator

Laczen commented Jul 11, 2019

Hi Jehudi, But it is in the h_set routine where we were getting the length returned as -22 (-EINVAL) rather than the length of 0. This is what was causing the problem. I can’t see where the length is given to the h_set routine without calling settings_val_read_cb() We could call: size_t settings_line_val_get_len(off_t val_off, void *read_cb_ctx) to get the length, but this effectively does a read to determine the length anyhow. The parameters passed into h_set are a list of name strings and  void *value_ctx Are you saying that the length is already in this information somewhere?  If so, where? Regards, Declan

Hi Declan, in the h_set routine the second parameter that gets passed is the length of the data:
int (*h_set)(const char *key, size_t len, settings_read_cb read_cb, void *cb_arg);

@nwsetec
Copy link
Contributor

nwsetec commented Jul 11, 2019

@Laczen our project is currently using v1.14-branch LTS Zephyr so h_set callback doesn't have that len parameter. cc @DeclanTraill

@Laczen
Copy link
Collaborator

Laczen commented Jul 11, 2019

@nwsetec, I see, ok in that case there is no possibility to use len. There have been quite some changes in the settings module since 1.14 LTS,

@nvlsianpu
Copy link
Collaborator

Hi @nvlsianpu I'm working on the same project as Declan. We are using base64 encoding as we have products in the field running Zephyr 1.13 and are planning to update them to 1.14 (which I believe was using base64 only) and this was the easiest path we could see. This raises something I was wondering about, can the settings subsystem work over an nffs file without base64 decoding?

Yes, base64 encoding is not required anymore - I kept it just for backward compatibility. Be aware that settings record format for FS backend changes without base64 encoding:
<key>=<base64_encoded_data>/0 => <length><key>=<raw_data>

@ioannisg ioannisg added the priority: low Low impact/importance bug label Jul 12, 2019
@nwsetec
Copy link
Contributor

nwsetec commented Aug 1, 2019

Hi @ioannisg @nvlsianpu,
Unless another fix has gone into the v1.14-branch then the #17446 fix for this bug should be merged for the 1.14.1 release. I don't believe Declan will have the time to provide the test request in PR comment.
Thanks

@jenmwms jenmwms assigned ghost Aug 20, 2019
@jenmwms
Copy link
Collaborator

jenmwms commented Aug 20, 2019

Hi @nwsetec @ioannisg @nvlsianpu
Can you please provide an update on this?
Thanks

@jenmwms jenmwms added this to the v2.0.0 milestone Aug 20, 2019
@nwsetec
Copy link
Contributor

nwsetec commented Aug 20, 2019

Hi @jenmwms the #17446 PR fixes the issue, I've checked the master branch and the issue still exists, so PR needs to be reviewed and if all good merged.

nvlsianpu pushed a commit to DeclanTraill/zephyr that referenced this issue Aug 20, 2019
Fix for Zephyr bug zephyrproject-rtos#17415
For settings_line_val_read function with following .conf setting:
CONFIG_SETTINGS_USE_BASE64=y

Signed-off-by: Declan Traill <declan.traill@setec.com.au>
carlescufi pushed a commit that referenced this issue Aug 20, 2019
Fix for Zephyr bug #17415
For settings_line_val_read function with following .conf setting:
CONFIG_SETTINGS_USE_BASE64=y

Signed-off-by: Declan Traill <declan.traill@setec.com.au>
nvlsianpu pushed a commit to nvlsianpu/zephyr that referenced this issue Aug 21, 2019
Fix for Zephyr bug zephyrproject-rtos#17415
For settings_line_val_read function with following .conf setting:
CONFIG_SETTINGS_USE_BASE64=y

Signed-off-by: Declan Traill <declan.traill@setec.com.au>
carlescufi pushed a commit that referenced this issue Aug 27, 2019
Fix for Zephyr bug #17415
For settings_line_val_read function with following .conf setting:
CONFIG_SETTINGS_USE_BASE64=y

Signed-off-by: Declan Traill <declan.traill@setec.com.au>
LeiW000 pushed a commit to LeiW000/zephyr that referenced this issue Sep 2, 2019
Fix for Zephyr bug zephyrproject-rtos#17415
For settings_line_val_read function with following .conf setting:
CONFIG_SETTINGS_USE_BASE64=y

Signed-off-by: Declan Traill <declan.traill@setec.com.au>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: Settings Settings subsystem bug The issue is a bug, or the PR is fixing a bug priority: low Low impact/importance bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants