From patchwork Wed May 20 06:41:01 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sean Anderson X-Patchwork-Id: 1294015 X-Patchwork-Delegate: uboot@andestech.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20161025 header.b=D7GmdD72; dkim-atps=neutral Received: from phobos.denx.de (phobos.denx.de [IPv6:2a01:238:438b:c500:173d:9f52:ddab:ee01]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 49Rjrn2Z3dz9sT6 for ; Wed, 20 May 2020 16:43:52 +1000 (AEST) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 23F0D81EB2; Wed, 20 May 2020 08:42:14 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="D7GmdD72"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 852F981E84; Wed, 20 May 2020 08:41:35 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,SPF_HELO_NONE autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-qk1-x743.google.com (mail-qk1-x743.google.com [IPv6:2607:f8b0:4864:20::743]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 3BA8381E7E for ; Wed, 20 May 2020 08:41:31 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=seanga2@gmail.com Received: by mail-qk1-x743.google.com with SMTP id s1so2513040qkf.9 for ; Tue, 19 May 2020 23:41:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=GB+W2R40o6k9UDV10sxa5Xa3KvT8gt35A0ScHUXuqPs=; b=D7GmdD7206Fb7omJfrpZFqd0YgME1i9DvLDLeIIwCi1PmN7nBXbJ1hJMxTN8xNhLty NsQErrDuU0xuICKvTUeOjN1lbC3WwA5SkIrZeJywRf8jUBu1w/85/fCfBVUp+5f/1OOO 6JxfU+tx1Fqwg6UZY+r9I7L7zczCeZOMyyBDKJdp29nr/VaaILVSpWaFkZTw0iz0PMA7 tCMiLYYAS492rQc7RDKkmXqbzokbpnY19iRVkwVT5SMVPybsODjqVBUUydNdBiqusBGU iirXd8tiOUURjz2zVF87k21JcNRm6OTYMENM9N7jIcfg3R0uHOPGztP+ndJnpD/oskJA N6MQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=GB+W2R40o6k9UDV10sxa5Xa3KvT8gt35A0ScHUXuqPs=; b=o+/bqYLZNWFTYN5+73MFSRHrtLhhn8tohnBlanp4vZ3NheNOGzxuecFAOLJutE4jL+ piwX71Tftsswwo1h+RCagKW9yb5IIdyKEH2WmNhKFgvT25UDEZmF1o7fFKH0ioBGDCLc TiDp3a6YxmOzhx8WyTu+4XEhGsiPkDFp8FA/Lvje631OZIhC9RbeocUod/R2YpbVDqfd 5205/zL31vx+S6bXQR+b9DUEPW6dSv8KMc2khQ1opU7VOFAhnmVw9nngZueAEjs0Rz+o kgPEvyCD2nW/2UI6K2QiPW9GX4DS/2r+MyJwqdSPKKd1ruJLyvF49GHtbuKDqPfKIPOQ jEbg== X-Gm-Message-State: AOAM531OsVAKp8QfT1K+88775lhYe/k/f3hTlUHsSOfdh0y7/nOweXqJ edkbPZZ2PhldGDLuGLSdSYfct8RVeI71UA== X-Google-Smtp-Source: ABdhPJxSc2bmWMTb0VRjRas3dtGK1ip6tZ/3fzB8xCw05Zez9U5xpEfpU91We4fmF3hGaWpVM9CI8w== X-Received: by 2002:a37:ba86:: with SMTP id k128mr3335076qkf.64.1589956889862; Tue, 19 May 2020 23:41:29 -0700 (PDT) Received: from godwin.fios-router.home (pool-108-51-35-162.washdc.fios.verizon.net. [108.51.35.162]) by smtp.gmail.com with ESMTPSA id i59sm1600393qtb.58.2020.05.19.23.41.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 May 2020 23:41:29 -0700 (PDT) From: Sean Anderson To: u-boot@lists.denx.de Cc: Rick Chen , Bin Meng , Sean Anderson , Tom Rini Subject: [PATCH v11 11/21] lib: Always set errno in hcreate_r Date: Wed, 20 May 2020 02:41:01 -0400 Message-Id: <20200520064111.317605-12-seanga2@gmail.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200520064111.317605-1-seanga2@gmail.com> References: <20200520064111.317605-1-seanga2@gmail.com> MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.30rc1 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.102.2 at phobos.denx.de X-Virus-Status: Clean This could give a confusing error message if it failed and didn't set errno. Signed-off-by: Sean Anderson Reviewed-by: Bin Meng --- 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 b96dbe19be..7b6781bc35 100644 --- a/lib/hashtable.c +++ b/lib/hashtable.c @@ -110,8 +110,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 */ @@ -124,8 +126,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;