mmio: consolidate map and unmap error codes to open and close

This commit is contained in:
Vanya A. Sergeev
2019-09-30 22:15:56 -05:00
parent 8b21d0668c
commit 67d0e04d4c
3 changed files with 9 additions and 13 deletions
+5 -7
View File
@@ -164,13 +164,11 @@ The periphery MMIO functions return 0 on success or one of the negative error co
The libc errno of the failure in an underlying libc library call can be obtained with the `mmio_errno()` helper function. A human readable error message can be obtained with the `mmio_errmsg()` helper function.
| Error Code | Description |
|-----------------------|-------------------------------|
| `MMIO_ERROR_ARG` | Invalid arguments |
| `MMIO_ERROR_OPEN` | Opening /dev/mem |
| `MMIO_ERROR_MAP` | Mapping memory |
| `MMIO_ERROR_CLOSE` | Closing /dev/mem |
| `MMIO_ERROR_UNMAP` | Unmapping memory |
| Error Code | Description |
|-----------------------|-----------------------|
| `MMIO_ERROR_ARG` | Invalid arguments |
| `MMIO_ERROR_OPEN` | Opening MMIO |
| `MMIO_ERROR_CLOSE` | Closing MMIO |
### EXAMPLE
+2 -2
View File
@@ -73,7 +73,7 @@ int mmio_open(mmio_t *mmio, uintptr_t base, size_t size) {
if ((mmio->ptr = mmap(0, mmio->aligned_size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, mmio->aligned_base)) == MAP_FAILED) {
int errsv = errno;
close(fd);
return _mmio_error(mmio, MMIO_ERROR_MAP, errsv, "Mapping memory");
return _mmio_error(mmio, MMIO_ERROR_OPEN, errsv, "Mapping memory");
}
/* Close memory */
@@ -171,7 +171,7 @@ int mmio_close(mmio_t *mmio) {
/* Unmap memory */
if (munmap(mmio->ptr, mmio->aligned_size) < 0)
return _mmio_error(mmio, MMIO_ERROR_UNMAP, errno, "Unmapping memory");
return _mmio_error(mmio, MMIO_ERROR_CLOSE, errno, "Unmapping memory");
mmio->ptr = 0;
+2 -4
View File
@@ -17,10 +17,8 @@ extern "C" {
enum mmio_error_code {
MMIO_ERROR_ARG = -1, /* Invalid arguments */
MMIO_ERROR_OPEN = -2, /* Opening /dev/mem */
MMIO_ERROR_MAP = -3, /* Mapping memory */
MMIO_ERROR_CLOSE = -4, /* Closing /dev/mem */
MMIO_ERROR_UNMAP = -5, /* Unmapping memory */
MMIO_ERROR_OPEN = -2, /* Opening MMIO */
MMIO_ERROR_CLOSE = -3, /* Closing MMIO */
};
typedef struct mmio_handle mmio_t;