public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
From: Sean Anderson <seanga2@gmail.com>
To: u-boot@lists.denx.de
Subject: [PATCH v7 12/22] lib: Always set errno in hcreate_r
Date: Thu, 19 Mar 2020 16:54:10 -0400	[thread overview]
Message-ID: <20200319205420.720815-13-seanga2@gmail.com> (raw)
In-Reply-To: <20200319205420.720815-1-seanga2@gmail.com>

This could give a confusing error message if it failed and didn't set
errno.

Signed-off-by: Sean Anderson <seanga2@gmail.com>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
---

Changes in v5:
- New

 lib/hashtable.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/lib/hashtable.c b/lib/hashtable.c
index 907e8a642f..e9ac7e252e 100644
--- a/lib/hashtable.c
+++ b/lib/hashtable.c
@@ -109,8 +109,10 @@ int hcreate_r(size_t nel, struct hsearch_data *htab)
 	}
 
 	/* There is still another table active. Return with error. */
-	if (htab->table != NULL)
+	if (htab->table != NULL) {
+		__set_errno(EINVAL);
 		return 0;
+	}
 
 	/* Change nel to the first prime number not smaller as nel. */
 	nel |= 1;		/* make odd */
@@ -123,8 +125,10 @@ int hcreate_r(size_t nel, struct hsearch_data *htab)
 	/* allocate memory and zero out */
 	htab->table = (struct env_entry_node *)calloc(htab->size + 1,
 						sizeof(struct env_entry_node));
-	if (htab->table == NULL)
+	if (htab->table == NULL) {
+		__set_errno(ENOMEM);
 		return 0;
+	}
 
 	/* everything went alright */
 	return 1;
-- 
2.25.1

  parent reply	other threads:[~2020-03-19 20:54 UTC|newest]

Thread overview: 30+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-03-19 20:53 [PATCH v7 00/22] riscv: Add Sipeed Maix support Sean Anderson
2020-03-19 20:53 ` [PATCH v7 01/22] clk: Always use the supplied struct clk Sean Anderson
2020-03-19 20:54 ` [PATCH v7 02/22] clk: Check that ops of composite clock components exist before calling Sean Anderson
2020-03-19 20:54 ` [PATCH v7 03/22] clk: Unconditionally recursively en-/dis-able clocks Sean Anderson
2020-03-19 20:54 ` [PATCH v7 04/22] clk: Fix clk_get_by_* handling of index Sean Anderson
2020-03-30  6:42   ` Rick Chen
2020-03-19 20:54 ` [PATCH v7 05/22] clk: Add functions to register CCF clock structs Sean Anderson
2020-03-30  7:05   ` Rick Chen
2020-03-19 20:54 ` [PATCH v7 06/22] clk: Add K210 pll support Sean Anderson
2020-03-19 20:54 ` [PATCH v7 07/22] clk: Add a bypass clock for K210 Sean Anderson
2020-03-19 20:54 ` [PATCH v7 08/22] clk: Add K210 clock support Sean Anderson
2020-03-19 20:54 ` [PATCH v7 09/22] dm: Add support for simple-pm-bus Sean Anderson
2020-03-19 20:54 ` [PATCH v7 10/22] dm: Fix error handling for dev_read_addr_ptr Sean Anderson
2020-03-19 20:54 ` [PATCH v7 11/22] reset: Add generic reset driver Sean Anderson
2020-03-19 20:54 ` Sean Anderson [this message]
2020-03-19 20:54 ` [PATCH v7 13/22] riscv: Add headers for asm/global_data.h Sean Anderson
2020-03-19 20:54 ` [PATCH v7 14/22] riscv: Clear pending interrupts before enabling IPIs Sean Anderson
2020-03-27  9:04   ` Rick Chen
2020-03-19 20:54 ` [PATCH v7 15/22] riscv: Clean up IPI initialization code Sean Anderson
2020-03-27  9:03   ` Rick Chen
2020-03-30  7:39     ` Rick Chen
2020-03-19 20:54 ` [PATCH v7 16/22] riscv: Add option to support RISC-V privileged spec 1.9 Sean Anderson
2020-03-19 20:54 ` [PATCH v7 17/22] riscv: Allow use of reset drivers Sean Anderson
2020-03-19 20:54 ` [PATCH v7 18/22] riscv: Try to get cpu frequency from a "clocks" node if it exists Sean Anderson
2020-03-19 20:54 ` [PATCH v7 19/22] riscv: Enable cpu clock if it is present Sean Anderson
2020-03-19 20:54 ` [PATCH v7 20/22] riscv: Add device tree for K210 and Sipeed Maix BitM Sean Anderson
2020-03-19 20:54 ` [PATCH v7 21/22] doc: riscv: Add documentation for Sipeed Maix Bit Sean Anderson
2020-03-19 20:54 ` [PATCH v7 22/22] riscv: Add Sipeed Maix support Sean Anderson
2020-03-30  7:14   ` Rick Chen
2020-03-30  8:39     ` Sean Anderson

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=20200319205420.720815-13-seanga2@gmail.com \
    --to=seanga2@gmail.com \
    --cc=u-boot@lists.denx.de \
    /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