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
Open
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
4 changes: 2 additions & 2 deletions fs/fcb2/src/fcb_getprev.c
Original file line number Diff line number Diff line change
Expand Up @@ -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

/*
* Out entries in this sector
*/
Expand All @@ -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.

return rc;
}

Expand Down