From: Denis Kenzior <denkenz@gmail.com>
To: ofono@lists.linux.dev
Cc: Denis Kenzior <denkenz@gmail.com>
Subject: [PATCH 1/2] doc: Prefer l_new instead of g_try*
Date: Thu, 1 Feb 2024 14:43:59 -0600 [thread overview]
Message-ID: <20240201204412.951617-1-denkenz@gmail.com> (raw)
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(-)
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
--
2.43.0
next reply other threads:[~2024-02-01 20:45 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-02-01 20:43 Denis Kenzior [this message]
2024-02-01 20:44 ` [PATCH 2/2] doc: Remove rule 13 in favor of O3 Denis Kenzior
2024-02-01 21:40 ` [PATCH 1/2] doc: Prefer l_new instead of g_try* patchwork-bot+ofono
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20240201204412.951617-1-denkenz@gmail.com \
--to=denkenz@gmail.com \
--cc=ofono@lists.linux.dev \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox