From patchwork Thu Feb 27 13:56:11 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rasmus Villemoes X-Patchwork-Id: 1245868 X-Patchwork-Delegate: trini@ti.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=85.214.62.61; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=prevas.dk Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=prevas.dk header.i=@prevas.dk header.a=rsa-sha256 header.s=selector1 header.b=hRE7vue5; dkim-atps=neutral Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (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 48SvNg4HXvz9shl for ; Fri, 28 Feb 2020 00:56:51 +1100 (AEDT) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id D65DA80911; Thu, 27 Feb 2020 14:56:31 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=prevas.dk Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (1024-bit key; unprotected) header.d=prevas.dk header.i=@prevas.dk header.b="hRE7vue5"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 13D0880671; Thu, 27 Feb 2020 14:56:20 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-1.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, FORGED_SPF_HELO, SPF_HELO_PASS, URIBL_BLOCKED autolearn=no autolearn_force=no version=3.4.2 Received: from EUR01-HE1-obe.outbound.protection.outlook.com (mail-he1eur01on0713.outbound.protection.outlook.com [IPv6:2a01:111:f400:fe1e::713]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 6FADB80671 for ; Thu, 27 Feb 2020 14:56:14 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=prevas.dk Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=rasmus.villemoes@prevas.dk ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=e1iaAP2iUXdSX3E9xrMMcWn9mO/rzzLVX7YHnr7hl/JTuyg9QsCK73oODjIMJxuwczaCRSL2UsUqW+STnzwdltcQSZ3hD3gkRa716kSXWxvFx+K+ZEXl3Ur5KFlfdh8ooinmuaNETGC3ks9EZ9sdBGb4FgnbLCk5X6WC9mZhNxCfYSxKDUL0BmNMXxHyWhEfLDoN+9SCxrAZNOgA63XOy/8hMt3nmE5RhppLnCA16LZx+fj5jYj6Jp1dUdoTtun9P/+E1/EPgNwix9Bk7A2bVzPIoEFc09fvxacEXFIxTmlexY2BBF3pNtBnT/gBXHUCJXKuT/SmWyBEweRkAuTiyw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=grE29DFm4BiORkinIUZ33CabsVld5Yc39hSGnw4W2Zk=; b=X7PT7+jbYdhyWhI/bspRhh0pXTLref/gmyCEoGqscjlLNlRi6UvBd93CYPWYXhYbN/BXypKsuxl0SCJKFc803lg8ecjHshbmCCLLqnmcP4YRyl1QAx9YaFHhxnuso1yXIyG23D8y7RdwfJzHgJmsCN/YyOugdm30M1c6BeKHRfh8OtAmmWAckgIrIcLr4tcXI7uXGUuNJBPfm33MzLmVmKJQ7jlw//fVufUXb9Yu40Nyz1IKK1QoY7pWqqjiPhuDlzHEAPtTROkV3skrhAhbMmSawuHXrg6y21poZwpWJf2N0DCURgiwIN0SrcMO4HjXcyeKoNgZw+Qh0PpseeocAw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=prevas.dk; dmarc=pass action=none header.from=prevas.dk; dkim=pass header.d=prevas.dk; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=prevas.dk; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=grE29DFm4BiORkinIUZ33CabsVld5Yc39hSGnw4W2Zk=; b=hRE7vue5LqGot3DN4So8iTvzCL0/FZQk5X7lp2za5NIXZlOgKIp/BsinCCGw4pfDkQK6vrJuN0LiIuxjE2nmdJ651k/rLZVLoIjJRN3S5JOm3+Lt5x7e9/DN7BVvQs/HqRGvNJwCOhMYMR3DOjGAxM1dRirTd94vQyw9ty2YoTw= Received: from VI1PR10MB2765.EURPRD10.PROD.OUTLOOK.COM (20.178.126.85) by VI1PR10MB3183.EURPRD10.PROD.OUTLOOK.COM (52.133.244.11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2772.14; Thu, 27 Feb 2020 13:56:12 +0000 Received: from VI1PR10MB2765.EURPRD10.PROD.OUTLOOK.COM ([fe80::e58f:1097:b71d:32c7]) by VI1PR10MB2765.EURPRD10.PROD.OUTLOOK.COM ([fe80::e58f:1097:b71d:32c7%5]) with mapi id 15.20.2772.012; Thu, 27 Feb 2020 13:56:12 +0000 Received: from prevas-ravi.prevas.se (5.186.115.35) by AM5P194CA0007.EURP194.PROD.OUTLOOK.COM (2603:10a6:203:8f::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2772.14 via Frontend Transport; Thu, 27 Feb 2020 13:56:10 +0000 From: Rasmus Villemoes To: "u-boot@lists.denx.de" CC: Wolfgang Denk , Simon Glass , Joe Hershberger , Rasmus Villemoes Subject: [PATCH 2/4] lib/hashtable.c: create helper for calling env_entry::callback Thread-Topic: [PATCH 2/4] lib/hashtable.c: create helper for calling env_entry::callback Thread-Index: AQHV7XWqkTrftNXJCkOgBdKGaMWLzg== Date: Thu, 27 Feb 2020 13:56:11 +0000 Message-ID: <20200227135600.28853-3-rasmus.villemoes@prevas.dk> References: <20200227135600.28853-1-rasmus.villemoes@prevas.dk> In-Reply-To: <20200227135600.28853-1-rasmus.villemoes@prevas.dk> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-clientproxiedby: AM5P194CA0007.EURP194.PROD.OUTLOOK.COM (2603:10a6:203:8f::17) To VI1PR10MB2765.EURPRD10.PROD.OUTLOOK.COM (2603:10a6:803:e1::21) x-mailer: git-send-email 2.23.0 authentication-results: spf=none (sender IP is ) smtp.mailfrom=rasmus.villemoes@prevas.dk; x-ms-exchange-messagesentrepresentingtype: 1 x-originating-ip: [5.186.115.35] x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: bfd7f6f4-ae8b-4115-e926-08d7bb8ccd3e x-ms-traffictypediagnostic: VI1PR10MB3183: x-ms-exchange-transport-forked: True x-microsoft-antispam-prvs: x-ms-oob-tlc-oobclassifiers: OLM:309; x-forefront-prvs: 03264AEA72 x-forefront-antispam-report: SFV:NSPM; SFS:(10019020)(366004)(396003)(376002)(346002)(39840400004)(136003)(199004)(189003)(5660300002)(64756008)(2616005)(66446008)(8976002)(66556008)(956004)(66946007)(6506007)(66476007)(2906002)(54906003)(71200400001)(8936002)(44832011)(107886003)(86362001)(6486002)(6512007)(186003)(36756003)(8676002)(26005)(81156014)(81166006)(316002)(1076003)(16526019)(478600001)(4326008)(52116002)(6916009); DIR:OUT; SFP:1102; SCL:1; SRVR:VI1PR10MB3183; H:VI1PR10MB2765.EURPRD10.PROD.OUTLOOK.COM; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; A:1; MX:1; received-spf: None (protection.outlook.com: prevas.dk does not designate permitted sender hosts) x-ms-exchange-senderadcheck: 1 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: R9wW4FU+5nZFNgVKn1Ta/Om1gSCRZXwLl5jw3Pg5SPWJKSYOFtZaUjUd2K27PoWdkghLOv2jM+S+1Zk9p1JW6P4x3/pigMnecBFtHwBcN+065bqs/YqKLokS+7NGhKhQFlMt46pUVSw54mlv5W9jFwJiTxkyMGB40wwaRdaVMHrxxvw3YRBdGRungo+BJ7ju2OvT9S3Re9fzlW8GX8dGO+obCgwNnOdEVF3KZeor81uZivY/5139AI0znjgUTwiUiEnVVXMcYVeHQq/aNvVdhYTt4yYovwLQojgJ80qtXK1yy02VQegFYIWpNpz46stnMEb5CSBWJb7TlD+0j+5ozKtmG4CO3hBg4FK/NAzHqfB2TywH3uNYDFz72VKV+RXcUE0S8llVpu8W7OQRWqEN1XpZUtDcaTOHbfp5yDZbR6iyUyuLwjAoZVT0R0M9v6qd x-ms-exchange-antispam-messagedata: QtuESKpR7OJkQU82AuSKfbSs8sz5vSF+K1u3VKIPhlEnybEdnA8RdPbvFRQwaAKnMOJn+r25XG6ZjyJZg+7LKshPgjerEh6Yr5gSTFrcsYvB2IwWecJlC8DfyGfeXgh6gOtKlDJKvYW984fjjWZ2mQ== MIME-Version: 1.0 X-OriginatorOrg: prevas.dk X-MS-Exchange-CrossTenant-Network-Message-Id: bfd7f6f4-ae8b-4115-e926-08d7bb8ccd3e X-MS-Exchange-CrossTenant-originalarrivaltime: 27 Feb 2020 13:56:11.1101 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: d350cf71-778d-4780-88f5-071a4cb1ed61 X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: 2InVNM5N0yoCl3FJQsQOObJx8f+l1OJGezHfJ1qSebQc9Q+rS1cYb/ATXfqaOYlPaUI8hGWvApYZuR8ZyjuoRDYpGcgoU1L/MiMpDEbfyk8= X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR10MB3183 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 is preparation for compiling out the "call the callback" code and associated error handling for SPL, where ->callback is always NULL. Signed-off-by: Rasmus Villemoes Reviewed-by: Simon Glass --- lib/hashtable.c | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/lib/hashtable.c b/lib/hashtable.c index 907e8a642f..574ec6af86 100644 --- a/lib/hashtable.c +++ b/lib/hashtable.c @@ -222,6 +222,15 @@ int hmatch_r(const char *match, int last_idx, struct env_entry **retval, return 0; } +static int +do_callback(const struct env_entry *e, const char *name, const char *value, + enum env_op op, int flags) +{ + if (e->callback) + return e->callback(name, value, op, flags); + return 0; +} + /* * Compare an existing entry with the desired key, and overwrite if the action * is ENV_ENTER. This is simply a helper function for hsearch_r(). @@ -247,9 +256,8 @@ static inline int _compare_and_overwrite_entry(struct env_entry item, } /* If there is a callback, call it */ - if (htab->table[idx].entry.callback && - htab->table[idx].entry.callback(item.key, - item.data, env_op_overwrite, flag)) { + if (do_callback(&htab->table[idx].entry, item.key, + item.data, env_op_overwrite, flag)) { debug("callback() rejected setting variable " "%s, skipping it!\n", item.key); __set_errno(EINVAL); @@ -402,9 +410,8 @@ int hsearch_r(struct env_entry item, enum env_action action, } /* If there is a callback, call it */ - if (htab->table[idx].entry.callback && - htab->table[idx].entry.callback(item.key, item.data, - env_op_create, flag)) { + if (do_callback(&htab->table[idx].entry, item.key, item.data, + env_op_create, flag)) { debug("callback() rejected setting variable " "%s, skipping it!\n", item.key); _hdelete(item.key, htab, &htab->table[idx].entry, idx); @@ -473,8 +480,8 @@ int hdelete_r(const char *key, struct hsearch_data *htab, int flag) } /* If there is a callback, call it */ - if (htab->table[idx].entry.callback && - htab->table[idx].entry.callback(key, NULL, env_op_delete, flag)) { + if (do_callback(&htab->table[idx].entry, key, NULL, + env_op_delete, flag)) { debug("callback() rejected deleting variable " "%s, skipping it!\n", key); __set_errno(EINVAL);