-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
mtd: Change API to return 0 on success #13896
mtd: Change API to return 0 on success #13896
Conversation
I hope i did not miss anything as the change is less than I thought it would be. I also found other structs Conversion from mtd to vfs happens for example in I am not sure how far they can coexist. |
TL;DR: I think the return value should be of type Reasoning: Returning a size as However: The overflow issue cannot happen for any currently supported platform: The read function reads from storage and writes into RAM, the write functions reads from RAM. So in both cases the capacity of the RAM is the limiting factor for the length. And for all platforms supported currently, an Using an |
There is the case to be made that returning 0 on success makes the code cleaner. |
If the function returns |
But I see another argument for |
Indeed. And likely this translates into a few bytes less ROM as well. I tried to come up with a convincing example where having the number of bytes actually written before an error occurred would be useful. However, this is something so unlikely to happen with so little benefit of the additional knowledge, that investing the ROM space to handle this is kind of hard to sell. Also, this error handling code likely ends up poorly tested (as those errors won't pop up frequently in practice) and likely turns out to be dysfunctional when (after years of waiting) the error handling actually gets triggered in the wild for somebody. Consider me convinced that returning zero makes more sense. However, I would like to additionally use |
I found some more lines to be changed. More test output:
|
agree |
c628d4d
to
1aa3231
Compare
I'm very much in favor of this change.
nvm those are actually used by file systems. |
@vincent-d: As one of the authors of this API, it would be good to have your opinion on this, too. I would like to have this in, but I have zero prior experience with the MTD API. Thus, I would like to avoid being the person giving the second ACK. |
While discussing the MTD API, I noticed another problem. We could just make that 64 bit or change it into |
If the latter would not only avoid 64 bit arithmetic but also make the file system code cleaner, we should go for that :-) |
@maribu I'm OK with these changes. ACK |
Sorry, I'm too tired to concentrate. |
For me the error does not appear locally either:
|
But that's what I'm doing too. |
I am going to rebase and push again. |
1aa3231
to
b6a772f
Compare
Jup, |
So i squash |
d484033
to
1c29ed4
Compare
I'm willing to just merge this now and ignore the CI test - I tested it locally and it works, CI build fails for other PRs too but with a different test - that can still explained by broken flash. Just one more thing: there will be a merge conflict with #11081 which touches Should I merge that first so you can quickly rebase again? :) |
Ok |
There you go 😉 |
1c29ed4
to
e14c6a8
Compare
I guess I can squash directly? |
e14c6a8
to
d52c716
Compare
Thanks |
Thank you for the cleanup! |
I do realize now that it does make sense for the low-level component to return the number of bytes written if the upper (MTD) layer handles this. E.g. if But instead it would return I'm now re-introducing an API to return the actual number of written bytes, but also use page-wise addressing to being able to write to media > 4GiB in size. |
Should the upper layer make sure that only valid parameters are passed to the lower layer? Why would that upper layer call the lower one with writes across pages, unless the upper layer is sure that this is supported? If you indent to add an intermediate layer on top of the drivers anyway, why not introduce two flavors of backends: One that supports arbitrary writes and reads, and one that only works on a page level. E.g. flash drivers will very naturally map to the page-wise access, while e.g. EEPROM or the native file based MTD map very naturally to arbitrary reads and writes. A |
You are right, some file systems will already align their writes accordingly. Adding two code paths would be a much bigger overhead.
EEPROMs still can't write over page boundaries. If a single write transaction goes beyond the current page, it will wrap around instead of writing to the next page. |
Ah, yes. So there is actually no real hardware that can do random access read/writes anyway (except for the one emulated by It would still be nice for hardware that can only do page-wise operations (e.g. not starting a read / write with given offset) to not lot the driver manage random access within the page. Instead, implementing random access on top once for all drivers in Maybe random access within a page could just be assumed to be supported unless a certian submodule of |
Returning the number of bytes written/read could return a negative integer
because a uint32_t is expected for the length in read()/write() operations.
Contribution description
MTD drivers returned the number of bytes read/written as a plain integer but this could overflow because a uint32_t is expected as a function parameter, being the length to read/write.
So this PR changes the return value to be 0 on a successful read/write operation.
Testing procedure
Issues/PRs references
Came up in #13877