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

littlefs: Fix handling of root as target for create operations #6177

Merged
merged 1 commit into from Feb 26, 2018

Conversation

Projects
None yet
5 participants
@geky
Member

geky commented Feb 22, 2018

Before this patch, when calling lfs_mkdir or lfs_file_open with root as the target, littlefs wouldn't find the path properly and happily run into undefined behaviour.

The fix is to populate a directory entry for root in the lfs_dir_find function. As an added plus, this allowed several special cases around root to be completely dropped.

should fix #6090
cc @deepikabhavnani, @kegilbert
code size 10073B (-0.35%)
intended for patch

littlefs: Fixed handling of root as target for create operations
Before this patch, when calling lfs_mkdir or lfs_file_open with root
as the target, littlefs wouldn't find the path properly and happily
run into undefined behaviour.

The fix is to populate a directory entry for root in the lfs_dir_find
function. As an added plus, this allowed several special cases around
root to be completely dropped.

@cmonr cmonr requested review from kegilbert and deepikabhavnani Feb 23, 2018

@cmonr

cmonr approved these changes Feb 23, 2018

err = lfs_bd_read(lfs, cwd.pair[0],
entry.off + 4+entry.d.elen+entry.d.alen,
info->name, entry.d.nlen);
if (err) {

This comment has been minimized.

@cmonr

cmonr Feb 23, 2018

Contributor

Any reason you don't return(err) here?

This comment has been minimized.

@geky

geky Feb 23, 2018

Member

This is a heavily reoccuring pattern:

int err = lfs_do_thing();
if (err) {
    return err;
}

Which is effectively a form of exception handling. It's better to keep these sort of patterns consistent, because it makes it easier to recognize in context.

I do like to chain returns when the control flow passes completely to another function, but since this use is inside an if statement, it makes it harder to follow. If we needed to add an epilogue to this function it wouldn't be clear if the return err was supposed to be exceptional behavior or should be changed to continue to the end of the function.

But it's a very minor thing, so I wouldn't bat an eye if someone committed code that did just return err.

.d.alen = 0,
.d.nlen = 0,
.d.u.dir[0] = lfs->root[0],
.d.u.dir[1] = lfs->root[1],

This comment has been minimized.

@cmonr

cmonr Feb 23, 2018

Contributor

Neat. Didn't know trailing commas were supported like this in all compilers.

This comment has been minimized.

@geky

geky Feb 23, 2018

Member

There are still a lot of reasons to use C over C++. While C++ has been adding a lot of high-level features, C has been adding a lot of quality-of-life improvements :)

@cmonr cmonr added the needs: review label Feb 23, 2018

@cmonr cmonr added needs: CI and removed needs: review labels Feb 23, 2018

@cmonr

This comment has been minimized.

Contributor

cmonr commented Feb 23, 2018

/morph build

@mbed-ci

This comment has been minimized.

mbed-ci commented Feb 23, 2018

Build : SUCCESS

Build number : 1241
Build artifacts/logs : http://mbed-os.s3-website-eu-west-1.amazonaws.com/?prefix=builds/6177/

Triggering tests

/morph test
/morph uvisor-test
/morph export-build
/morph mbed2-build

@mbed-ci

This comment has been minimized.

@mbed-ci

This comment has been minimized.

@cmonr cmonr merged commit 7f81280 into ARMmbed:master Feb 26, 2018

18 checks passed

AWS-CI uVisor Build & Test Success
Details
ci-morph-build build completed
Details
ci-morph-exporter build completed
Details
ci-morph-mbed2-build build completed
Details
ci-morph-test test completed
Details
continuous-integration/jenkins/pr-head This commit looks good
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
mbed-ci-generic Build finished.
Details
travis-ci/docs/ Local docs testing has passed
Details
travis-ci/events/ Local events testing has passed
Details
travis-ci/littlefs/ Local littlefs testing has passed
Details
travis-ci/mbed2-ATMEL/ Local mbed2-ATMEL testing has passed
Details
travis-ci/mbed2-MAXIM/ Local mbed2-MAXIM testing has passed
Details
travis-ci/mbed2-NORDIC/ Local mbed2-NORDIC testing has passed
Details
travis-ci/mbed2-NUVOTON/ Local mbed2-NUVOTON testing has passed
Details
travis-ci/mbed2-NXP/ Local mbed2-NXP testing has passed
Details
travis-ci/mbed2-SILICON_LABS/ Local mbed2-SILICON_LABS testing has passed
Details
travis-ci/mbed2-STM/ Local mbed2-STM testing has passed
Details

@cmonr cmonr removed the ready for merge label Feb 26, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment