From 74ee491b842e1f1a4df75f81e980957ff194c5b0 Mon Sep 17 00:00:00 2001 From: Brian Gianforcaro Date: Mon, 29 Nov 2021 03:01:24 -0800 Subject: Kernel: Handle string format errors in SlabAllocator stats :^) Switch to KString::formatted and fix API so we can propagate errors. --- Kernel/GlobalProcessExposed.cpp | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) (limited to 'Kernel/GlobalProcessExposed.cpp') diff --git a/Kernel/GlobalProcessExposed.cpp b/Kernel/GlobalProcessExposed.cpp index 2bed0a83ae..2733e9537c 100644 --- a/Kernel/GlobalProcessExposed.cpp +++ b/Kernel/GlobalProcessExposed.cpp @@ -412,11 +412,14 @@ private: json.add("super_physical_available", system_memory.super_physical_pages - system_memory.super_physical_pages_used); json.add("kmalloc_call_count", stats.kmalloc_call_count); json.add("kfree_call_count", stats.kfree_call_count); - slab_alloc_stats([&json](size_t slab_size, size_t num_allocated, size_t num_free) { - auto prefix = String::formatted("slab_{}", slab_size); - json.add(String::formatted("{}_num_allocated", prefix), num_allocated); - json.add(String::formatted("{}_num_free", prefix), num_free); - }); + TRY(slab_alloc_stats([&json](size_t slab_size, size_t num_allocated, size_t num_free) -> ErrorOr { + auto prefix = TRY(KString::formatted("slab_{}", slab_size)); + auto formatted_num_allocated = TRY(KString::formatted("{}_num_allocated", prefix)); + auto formatted_num_free = TRY(KString::formatted("{}_num_free", prefix)); + json.add(formatted_num_allocated->view(), num_allocated); + json.add(formatted_num_free->view(), num_free); + return {}; + })); json.finish(); return {}; } @@ -952,7 +955,8 @@ ErrorOr ProcFSRootDirectory::traverse_as_directory(FileSystemID fsid, Func VERIFY(!(process.pid() < 0)); u64 process_id = (u64)process.pid().value(); InodeIdentifier identifier = { fsid, static_cast(process_id << 36) }; - TRY(callback({ String::formatted("{:d}", process.pid().value()), identifier, 0 })); + auto process_id_string = TRY(KString::formatted("{:d}", process_id)); + TRY(callback({ process_id_string->view(), identifier, 0 })); } return {}; }); -- cgit v1.2.3