All of lore.kernel.org
 help / color / mirror / Atom feed
From: Juergen Gross <jgross@suse.com>
To: xen-devel@lists.xenproject.org
Cc: Juergen Gross <jgross@suse.com>, Wei Liu <wl@xen.org>,
	Julien Grall <julien@xen.org>,
	Anthony PERARD <anthony.perard@citrix.com>
Subject: [PATCH v2 01/19] tools/xenstore: let talloc_free() preserve errno
Date: Tue, 13 Dec 2022 17:00:27 +0100	[thread overview]
Message-ID: <20221213160045.28170-2-jgross@suse.com> (raw)
In-Reply-To: <20221213160045.28170-1-jgross@suse.com>

Today talloc_free() is not guaranteed to preserve errno, especially in
case a custom destructor is being used.

Change that by renaming talloc_free() to _talloc_free() in talloc.c and
adding a wrapper to talloc.c.

This allows to remove some errno saving outside of talloc.c.

Signed-off-by: Juergen Gross <jgross@suse.com>
---
V2:
- drop wrapper (Julien Grall)
---
 tools/xenstore/talloc.c         | 21 +++++++++++++--------
 tools/xenstore/xenstored_core.c |  2 --
 2 files changed, 13 insertions(+), 10 deletions(-)

diff --git a/tools/xenstore/talloc.c b/tools/xenstore/talloc.c
index d7edcf3a93..23c3a23b19 100644
--- a/tools/xenstore/talloc.c
+++ b/tools/xenstore/talloc.c
@@ -541,38 +541,39 @@ static void talloc_free_children(void *ptr)
 */
 int talloc_free(void *ptr)
 {
+	int saved_errno = errno;
 	struct talloc_chunk *tc;
 
 	if (ptr == NULL) {
-		return -1;
+		goto err;
 	}
 
 	tc = talloc_chunk_from_ptr(ptr);
 
 	if (tc->null_refs) {
 		tc->null_refs--;
-		return -1;
+		goto err;
 	}
 
 	if (tc->refs) {
 		talloc_reference_destructor(tc->refs);
-		return -1;
+		goto err;
 	}
 
 	if (tc->flags & TALLOC_FLAG_LOOP) {
 		/* we have a free loop - stop looping */
-		return 0;
+		goto success;
 	}
 
 	if (tc->destructor) {
 		talloc_destructor_t d = tc->destructor;
 		if (d == (talloc_destructor_t)-1) {
-			return -1;
+			goto err;
 		}
 		tc->destructor = (talloc_destructor_t)-1;
 		if (d(ptr) == -1) {
 			tc->destructor = d;
-			return -1;
+			goto err;
 		}
 		tc->destructor = NULL;
 	}
@@ -594,10 +595,14 @@ int talloc_free(void *ptr)
 	tc->flags |= TALLOC_FLAG_FREE;
 
 	free(tc);
+ success:
+	errno = saved_errno;
 	return 0;
-}
-
 
+ err:
+	errno = saved_errno;
+	return -1;
+}
 
 /*
   A talloc version of realloc. The context argument is only used if
diff --git a/tools/xenstore/xenstored_core.c b/tools/xenstore/xenstored_core.c
index 476d5c6d51..5a174b9881 100644
--- a/tools/xenstore/xenstored_core.c
+++ b/tools/xenstore/xenstored_core.c
@@ -771,9 +771,7 @@ struct node *read_node(struct connection *conn, const void *ctx,
 	return node;
 
  error:
-	err = errno;
 	talloc_free(node);
-	errno = err;
 	return NULL;
 }
 
-- 
2.35.3



  reply	other threads:[~2022-12-13 16:01 UTC|newest]

Thread overview: 44+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-12-13 16:00 [PATCH v2 00/19] tools/xenstore: do some cleanup and fixes Juergen Gross
2022-12-13 16:00 ` Juergen Gross [this message]
2022-12-14  9:54   ` [PATCH v2 01/19] tools/xenstore: let talloc_free() preserve errno Jan Beulich
2022-12-14 10:08     ` Juergen Gross
2022-12-13 16:00 ` [PATCH v2 02/19] tools/xenstore: let tdb_logger() " Juergen Gross
2022-12-13 16:00 ` [PATCH v2 03/19] tools/xenstore: preserve errno across corrupt() Juergen Gross
2022-12-13 16:00 ` [PATCH v2 04/19] tools/xenstore: remove all watches when a domain has stopped Juergen Gross
2022-12-20 19:01   ` Julien Grall
2023-01-11  6:36     ` Juergen Gross
2023-01-11 17:45       ` Julien Grall
2022-12-13 16:00 ` [PATCH v2 05/19] tools/xenstore: enhance hashtable implementation Juergen Gross
2022-12-13 16:00 ` [PATCH v2 06/19] tools/xenstore: add hashlist for finding struct domain by domid Juergen Gross
2022-12-20 19:09   ` Julien Grall
2022-12-13 16:00 ` [PATCH v2 07/19] tools/xenstore: introduce dummy nodes for special watch paths Juergen Gross
2022-12-20 19:39   ` Julien Grall
2023-01-11  6:41     ` Juergen Gross
2023-01-11 17:46       ` Julien Grall
2022-12-13 16:00 ` [PATCH v2 08/19] tools/xenstore: replace watch->relative_path with a prefix length Juergen Gross
2022-12-20 19:42   ` Julien Grall
2023-01-11  6:48     ` Juergen Gross
2022-12-13 16:00 ` [PATCH v2 09/19] tools/xenstore: move changed domain handling Juergen Gross
2022-12-20 19:49   ` Julien Grall
2022-12-13 16:00 ` [PATCH v2 10/19] tools/xenstore: change per-domain node accounting interface Juergen Gross
2022-12-20 20:15   ` Julien Grall
2023-01-11  8:59     ` Juergen Gross
2023-01-11 17:48       ` Julien Grall
2023-01-12  5:49         ` Juergen Gross
2023-01-13  9:53           ` Julien Grall
2023-01-13  9:57             ` Juergen Gross
2022-12-13 16:00 ` [PATCH v2 11/19] tools/xenstore: don't allow creating too many nodes in a transaction Juergen Gross
2022-12-20 20:18   ` Julien Grall
2023-01-11  9:07     ` Juergen Gross
2022-12-13 16:00 ` [PATCH v2 12/19] tools/xenstore: replace literal domid 0 with dom0_domid Juergen Gross
2022-12-13 16:00 ` [PATCH v2 13/19] tools/xenstore: make domain_is_unprivileged() an inline function Juergen Gross
2022-12-13 16:00 ` [PATCH v2 14/19] tools/xenstore: let chk_domain_generation() return a bool Juergen Gross
2022-12-13 16:00 ` [PATCH v2 15/19] tools/xenstore: switch hashtable to use the talloc framework Juergen Gross
2022-12-20 21:50   ` Julien Grall
2023-01-11  9:27     ` Juergen Gross
2023-01-11 17:50       ` Julien Grall
2022-12-13 16:00 ` [PATCH v2 16/19] tools/xenstore: make log macro globally available Juergen Gross
2022-12-13 16:00 ` [PATCH v2 17/19] tools/xenstore: introduce trace classes Juergen Gross
2022-12-13 16:00 ` [PATCH v2 18/19] tools/xenstore: let check_store() check the accounting data Juergen Gross
2022-12-13 16:00 ` [PATCH v2 19/19] tools/xenstore: make output of "xenstore-control help" more pretty Juergen Gross
2022-12-14 11:06 ` [PATCH v2 00/19] tools/xenstore: do some cleanup and fixes Jan Beulich

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=20221213160045.28170-2-jgross@suse.com \
    --to=jgross@suse.com \
    --cc=anthony.perard@citrix.com \
    --cc=julien@xen.org \
    --cc=wl@xen.org \
    --cc=xen-devel@lists.xenproject.org \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.