From: Yu Watanabe Date: Sat, 30 Sep 2023 02:32:38 +0000 (+0900) Subject: mmap-cache: merge window_matches() and window_matches_fd() X-Git-Tag: v255-rc1~327^2~2 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=81598f5ead972fac3f78dc1c8190b059bd5fceeb;p=thirdparty%2Fsystemd.git mmap-cache: merge window_matches() and window_matches_fd() Let's drop meaningless optimization, and always check if the window is owned by the expected fd. --- diff --git a/src/libsystemd/sd-journal/mmap-cache.c b/src/libsystemd/sd-journal/mmap-cache.c index 7a3057c8840..11b1abd8b7f 100644 --- a/src/libsystemd/sd-journal/mmap-cache.c +++ b/src/libsystemd/sd-journal/mmap-cache.c @@ -137,24 +137,16 @@ static Window* window_free(Window *w) { return mfree(w); } -static bool window_matches(Window *w, uint64_t offset, size_t size) { - assert(w); +static bool window_matches(Window *w, MMapFileDescriptor *f, uint64_t offset, size_t size) { assert(size > 0); return + w && + f == w->fd && offset >= w->offset && offset + size <= w->offset + w->size; } -static bool window_matches_fd(Window *w, MMapFileDescriptor *f, uint64_t offset, size_t size) { - assert(w); - assert(f); - - return - w->fd == f && - window_matches(w, offset, size); -} - static Window *window_add(MMapCache *m, MMapFileDescriptor *f, bool keep_always, uint64_t offset, size_t size, void *ptr) { Window *w; @@ -272,7 +264,7 @@ static int try_context( if (!c->window) return 0; - if (!window_matches_fd(c->window, f, offset, size)) { + if (!window_matches(c->window, f, offset, size)) { /* Drop the reference to the window, since it's unnecessary now */ context_detach_window(f->cache, c); @@ -310,7 +302,7 @@ static int find_mmap( return -EIO; LIST_FOREACH(by_fd, w, f->windows) - if (window_matches(w, offset, size)) { + if (window_matches(w, f, offset, size)) { found = w; break; }