Skip to content

prussdrv_open() fails if filedescriptor=0 is the first available file descriptor in system. #44

Open
@hzeller

Description

@hzeller

If all file-descriptors are closed (say, we're running as daemon and have closed all file descriptors), prussdrv_open() fails.

The reason is a flaw in the assumptions in the implementation of prussdrv.c ( https://github.com/beagleboard/am335x_pru_package/blob/master/pru_sw/app_loader/interface/prussdrv.c ): file-descriptors (prussdrv.mmap_fd and prussdrv.fd[i]) are initialized with zero and considered not opened/invalid when they are zero.

Of course, this assumption fails if all files have been closed before, thus the very first file descriptor in the system is, in fact, zero, so an open("/dev/uio0") returns FD 0. This results in prussdrv_open() to fail.

The whole file has to be changed so that the assumption of 'invalid filedescriptor' is changed to '-1' instead of 0. There are various ways to do that, so I let the maintainers choose what they prefer without suggesting patch for now.

(this was, indeed, a real world problem that surfaced in BeagleG. I've worked around it by re-opening file descriptors
hzeller/beagleg@042d1c4
)

To replicate

Here is a little test-program. With the close(0) call in place, it will fail.


#include <stdio.h>
#include <unistd.h>

#include <prussdrv.h>

int main() {
        // Close file-descriptor 0
        close(0);

        int ret = prussdrv_open(PRU_EVTOUT_0);
        fprintf(stderr, "Return code=%d ", ret);
        if (ret == 0) {
                fprintf(stderr, "SUCCESS\n");
        } else {
                fprintf(stderr, "FAILURE\n");
        }
        return ret;
}

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions