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

Fix last-address calculate error in norflash_erase #180

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

Conversation

CosmicRoach
Copy link

@CosmicRoach CosmicRoach commented Apr 25, 2024

Summary

ToDos

  • I only fixed 3 norflash-related code issues, and there are probably similar bugs somewhere.

@abrodkin abrodkin requested a review from xxkent May 2, 2024 09:00
@abrodkin
Copy link
Member

abrodkin commented May 2, 2024

Assigned to @xxkent for review.

@xxkent
Copy link

xxkent commented May 2, 2024

Looks good to me, in case of caller set sz > 0.

@CosmicRoach
Copy link
Author

Checking the input parameters (address and size) is another matter, here we should make sure that address>=0 and size>0;

Assuming a correct parameter input, if we do not subtract 1 when calculating the last address of the erase, it will cause us to erase one more sector when the size of the erase is exactly one or more sectors-size.

Examples of errors:
When address=0x0, size=4096, dev->sector_sz=4096, this means that the user wants to erase the first sector,
So, last_address = (address + size) & (~(dev-> sector_sz-1))=4096; however, because of the loop condition while (address <= last_address); We enter two loops, causing the second sector to be erased by mistake.

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.

None yet

3 participants