Open Source Telephony
 help / color / mirror / Atom feed
* [PATCH 1/2] doc: Prefer l_new instead of g_try*
@ 2024-02-01 20:43 Denis Kenzior
  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
  0 siblings, 2 replies; 3+ messages in thread
From: Denis Kenzior @ 2024-02-01 20:43 UTC (permalink / raw)
  To: ofono; +Cc: Denis Kenzior

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


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* [PATCH 2/2] doc: Remove rule 13 in favor of O3
  2024-02-01 20:43 [PATCH 1/2] doc: Prefer l_new instead of g_try* Denis Kenzior
@ 2024-02-01 20:44 ` Denis Kenzior
  2024-02-01 21:40 ` [PATCH 1/2] doc: Prefer l_new instead of g_try* patchwork-bot+ofono
  1 sibling, 0 replies; 3+ messages in thread
From: Denis Kenzior @ 2024-02-01 20:44 UTC (permalink / raw)
  To: ofono; +Cc: Denis Kenzior

Since oFono is slowly migrating to ell, remove rule M13 and indicate
that rule O3 style is preferred to match the prevalent coding style in
ell.  Many of the newer code additions have already been silently
following these recommendations.  Make them explicit.
---
 doc/coding-style.txt | 38 ++++++++++++++++----------------------
 1 file changed, 16 insertions(+), 22 deletions(-)

diff --git a/doc/coding-style.txt b/doc/coding-style.txt
index 0ec1cd97e8ca..96837f7687eb 100644
--- a/doc/coding-style.txt
+++ b/doc/coding-style.txt
@@ -241,28 +241,6 @@ However if the enum comes from an external header file outside ofono
 we cannot make any assumption of how the enum is defined and this
 rule might not apply.
 
-M13: Check for pointer being NULL
-=================================
-
-When checking if a pointer or a return value is NULL, explicitly compare to
-NULL rather than use the shorter check with "!" operator.
-
-Example:
-1)
-array = g_try_new0(int, 20);
-if (!array)	// Wrong
-	return;
-
-2)
-if (!g_at_chat_get_slave(chat))	// Wrong
-	return -EINVAL;
-
-3)
-array = g_try_new0(int, 20);
-if (array == NULL)	// Correct
-	return;
-
-
 M14: Always use parenthesis with sizeof
 =======================================
 The expression argument to the sizeof operator should always be in
@@ -347,3 +325,19 @@ v = voicecall_create(vc, call);
 v->detect_time = time(NULL);
 DBG("Registering new call: %d", call->id);
 voicecall_dbus_register(v);
+
+O3: Prefer !foo when checking pointers for NULL or boolean values
+=================================================================
+
+When checking if a pointer or a return value is NULL, prefer the negation
+operator form.
+
+Example:
+1)
+array = g_try_new0(int, 2000000);
+if (!array)
+	return -ENOMEM;
+
+2)
+if (!g_at_chat_get_slave(chat))
+	return -EINVAL;
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH 1/2] doc: Prefer l_new instead of g_try*
  2024-02-01 20:43 [PATCH 1/2] doc: Prefer l_new instead of g_try* Denis Kenzior
  2024-02-01 20:44 ` [PATCH 2/2] doc: Remove rule 13 in favor of O3 Denis Kenzior
@ 2024-02-01 21:40 ` patchwork-bot+ofono
  1 sibling, 0 replies; 3+ messages in thread
From: patchwork-bot+ofono @ 2024-02-01 21:40 UTC (permalink / raw)
  To: Denis Kenzior; +Cc: ofono

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!
-- 
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html



^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2024-02-01 21:40 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-02-01 20:43 [PATCH 1/2] doc: Prefer l_new instead of g_try* Denis Kenzior
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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox