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

fs/fcb2: fix endless loop in fcb2_getprev if a flash error occurs #2949

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

blocksebastian
Copy link
Contributor

fcb2_sector_find_last does not return or break while loop if an error occured during read

@@ -52,7 +52,7 @@ fcb2_sector_find_last(struct fcb2 *fcb, struct fcb2_entry *loc)
}
}
loc->fe_entry_num++;
} while (1);
} while (rc == 0);
Copy link
Contributor

Choose a reason for hiding this comment

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

Endless loop was supposed to handle cases where FCB2 had corrupted entries (most likely CRC for broken writes).
I guess then in your case, due to some flash read error, loop would not finish.
FCB2 sector starts with header fcb2_disk_area; data is stored in flash after the header starting from the beginning while entries holding CRC and data position and length are stored starting from the end of the sector.
When read error occurs fe_entry_num should be increased like it is right now but some sanity check should be performed to see if probably entry does not reach to occupied space or header if read error persist.
I guess similar check is done when new data is being written to FCB and there is not space for data+entry.
Proposed solution does not cover case where there are some errors in flash that could be recovered.

@@ -34,7 +34,7 @@ fcb2_sector_find_last(struct fcb2 *fcb, struct fcb2_entry *loc)
if (rc == 0) {
last_valid = loc->fe_entry_num;
}
if (rc == FCB2_ERR_NOVAR) {
else if (rc == FCB2_ERR_NOVAR) {
Copy link
Contributor

Choose a reason for hiding this comment

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

else should be in previous line to keep coding style presistant

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants