From 67cb2e3cdc9495ab00ad13c2971222c3da7bb78e Mon Sep 17 00:00:00 2001 From: Aidan MacDonald Date: Sat, 14 Jan 2023 18:50:15 +0000 Subject: [PATCH] Add core_get_data_pinned(), use it where possible Change-Id: I1b2f62f27780f99423085d2fffc972ea2701f998 --- apps/core_keymap.c | 7 ++++--- apps/misc.c | 6 +++--- firmware/include/core_alloc.h | 12 ++++++++++++ 3 files changed, 19 insertions(+), 6 deletions(-) diff --git a/apps/core_keymap.c b/apps/core_keymap.c index 966f32057a..89e7913c33 100644 --- a/apps/core_keymap.c +++ b/apps/core_keymap.c @@ -80,11 +80,12 @@ int core_load_key_remap(const char *filename) int handle = core_alloc(bufsize); if (handle > 0) { - core_pin(handle); - if (read(fd, core_get_data(handle), bufsize) == (ssize_t)bufsize) + void *data = core_get_data_pinned(handle); + + if (read(fd, data, bufsize) == (ssize_t)bufsize) count = action_set_keymap_handle(handle, count); - core_unpin(handle); + core_put_data_pinned(data); } close(fd); diff --git a/apps/misc.c b/apps/misc.c index e6c8a219ea..e17df02bff 100644 --- a/apps/misc.c +++ b/apps/misc.c @@ -1635,8 +1635,7 @@ int core_load_bmp(const char * filename, struct bitmap *bm, const int bmformat, handle = core_alloc_ex(buf_size, ops); if (handle > 0) { - core_pin(handle); - bm->data = core_get_data(handle); + bm->data = core_get_data_pinned(handle); lseek(fd, 0, SEEK_SET); /* reset to beginning of file */ size_read = read_bmp_fd(fd, bm, buf_size, bmformat, NULL); @@ -1645,9 +1644,10 @@ int core_load_bmp(const char * filename, struct bitmap *bm, const int bmformat, core_shrink(handle, bm->data, size_read); *buf_reqd = size_read; } + + core_put_data_pinned(bm->data); bm->data = NULL; /* do this to force a crash later if the caller doesnt call core_get_data() */ - core_unpin(handle); } else *buf_reqd = buf_size; /* couldn't allocate pass bytes needed */ diff --git a/firmware/include/core_alloc.h b/firmware/include/core_alloc.h index 22cc1988da..dc9b2036ec 100644 --- a/firmware/include/core_alloc.h +++ b/firmware/include/core_alloc.h @@ -45,6 +45,18 @@ static inline void* core_get_data(int handle) return buflib_get_data(&core_ctx, handle); } +static inline void* core_get_data_pinned(int handle) +{ + extern struct buflib_context core_ctx; + return buflib_get_data_pinned(&core_ctx, handle); +} + +static inline void core_put_data_pinned(void *data) +{ + extern struct buflib_context core_ctx; + buflib_put_data_pinned(&core_ctx, data); +} + /* core context chunk_alloc */ static inline bool core_chunk_alloc_init(struct chunk_alloc_header *hdr, size_t chunk_size, size_t max_chunks)