Message ID | 20240201204412.951617-1-denkenz@gmail.com (mailing list archive) |
---|---|
State | Accepted |
Commit | b461139f484e4d6ea4ce4f66ebafbb25efb9eb40 |
Headers | show |
Series | [1/2] doc: Prefer l_new instead of g_try* | expand |
Hello: This series was applied to ofono.git (master) by Denis Kenzior <denkenz@gmail.com>: On Thu, 1 Feb 2024 14:43:59 -0600 you wrote: > Using l_new and g_new* variants for small allocations has been the > preferred approach for quite some time. Update the coding style > document to reflect that. > --- > doc/coding-style.txt | 15 ++++++--------- > 1 file changed, 6 insertions(+), 9 deletions(-) Here is the summary with links: - [1/2] doc: Prefer l_new instead of g_try* https://git.kernel.org/pub/scm/network/ofono/ofono.git/?id=b461139f484e - [2/2] doc: Remove rule 13 in favor of O3 https://git.kernel.org/pub/scm/network/ofono/ofono.git/?id=feb3e44bb6b4 You are awesome, thank you!
diff --git a/doc/coding-style.txt b/doc/coding-style.txt index c27a2f275565..0ec1cd97e8ca 100644 --- a/doc/coding-style.txt +++ b/doc/coding-style.txt @@ -155,15 +155,12 @@ for (i = 0; i < 3; i++) { } -M8: Use g_try_malloc instead of g_malloc -======================================== -When g_malloc fails, the whole program would exit. Most of time, this is not -the expected behavior, and you may want to use g_try_malloc instead. - -Example: -additional = g_try_malloc(len - 1); // correct -if (additional == NULL) - return FALSE; +M8: Prefer l_new when allocating small structures +================================================= +Small allocations (less than a page) in userspace Linux applications typically +do not fail, and often there's nothing meaningful a program can do to recover. +For small allocations, prefer using l_new (or the GLib equivalent g_new0) +instead of g_try* functions. M9: Follow the order of include header elements