Skip to content

[FATFileSystem] Bug in FATFileSystem::file_truncate() causes deadlock #14613

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

Open
horeich opened this issue May 1, 2021 · 3 comments
Open

[FATFileSystem] Bug in FATFileSystem::file_truncate() causes deadlock #14613

horeich opened this issue May 1, 2021 · 3 comments

Comments

@horeich
Copy link
Contributor

horeich commented May 1, 2021

Description of defect

Program runs into deadlock once FATFileSystem::file_truncate(...) is called: any subsequent member function call from a different thread context is blocked as mutex is not returned.

int FATFileSystem::file_truncate(fs_file_t file, off_t length)
{
    FIL *fh = static_cast<FIL *>(file);

    lock();
    // save current position
    FSIZE_t oldoff = f_tell(fh);

    // seek to new file size and truncate
    FRESULT res = f_lseek(fh, length);
    if (res) {
        unlock();
        return fat_error_remap(res);
    }

    res = f_truncate(fh);
    if (res) {
        unlock();
        return fat_error_remap(res);
    }

    // restore old position
    res = f_lseek(fh, oldoff);
    if (res) {
        unlock();
        return fat_error_remap(res);
    }

    ****missing unlock() here****
    return 0;
}

Target(s) affected by this defect ?

All targets

Toolchain(s) (name and version) displaying this defect ?

arm-none-eabi-gcc (1.70201.0)
pio version 5.1.1

What version of Mbed-os are you using (tag or sha) ?

mbed 6.6.0

What version(s) of tools are you using. List all that apply (E.g. mbed-cli)

n/a

How is this defect reproduced ?

The defect can only be reproduced when member functions are accessed from different threads; problem does not occur if member functions are called from the same thread as mutex is already owned by this thread.

@ciarmcom
Copy link
Member

ciarmcom commented May 1, 2021

@horeich thank you for raising this issue.Please take a look at the following comments:

It would help if you could also specify the versions of any tools you are using?

NOTE: If there are fields which are not applicable then please just add 'n/a' or 'None'. This indicates to us that at least all the fields have been considered.
Please update the issue header with the missing information, the issue will not be mirrored to our internal defect tracking system or investigated until this has been fully resolved.

@horeich
Copy link
Contributor Author

horeich commented May 1, 2021

@ciarmcom I've added the missing info. Let me know if you need more details regarding this specific issue.

@ciarmcom
Copy link
Member

ciarmcom commented May 1, 2021

Thank you for raising this detailed GitHub issue. I am now notifying our internal issue triagers.
Internal Jira reference: https://jira.arm.com/browse/IOTOSM-3923

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

No branches or pull requests

4 participants