From patchwork Thu Nov 14 19:57:13 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 1195162 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=none (no SPF record) smtp.mailfrom=lists.denx.de (client-ip=81.169.180.215; helo=lists.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=chromium.org Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.b="HZaAsfeA"; dkim-atps=neutral Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 47DXSj00fLz9sPk for ; Fri, 15 Nov 2019 07:02:12 +1100 (AEDT) Received: by lists.denx.de (Postfix, from userid 105) id 9A6CCC21C29; Thu, 14 Nov 2019 20:00:36 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on lists.denx.de X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=RCVD_IN_MSPIKE_H2, T_DKIM_INVALID autolearn=unavailable autolearn_force=no version=3.4.0 Received: from lists.denx.de (localhost [IPv6:::1]) by lists.denx.de (Postfix) with ESMTP id 553BDC21C2F; Thu, 14 Nov 2019 19:58:24 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 609A9C21D83; Thu, 14 Nov 2019 19:58:22 +0000 (UTC) Received: from mail-io1-f66.google.com (mail-io1-f66.google.com [209.85.166.66]) by lists.denx.de (Postfix) with ESMTPS id 8D91FC21D56 for ; Thu, 14 Nov 2019 19:58:10 +0000 (UTC) Received: by mail-io1-f66.google.com with SMTP id r144so8193021iod.8 for ; Thu, 14 Nov 2019 11:58:10 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=1XJWbmof9Q4s0DsmNHwfX7/DZoe+BgPc82bJ6Jcu0ig=; b=HZaAsfeAxDDq4KR1Tm8wx4lo5qSjRZ/R07xUUS60B8B/DT3MfaxoTxkPOpXJzq4jPj wsQpOmu3+jNhpUGH9pJa7G0AVQx6gzGgi2nuayiVgULhboKTFxgp53E6wCX0OgjklQFy O/mmissMoEEIYb32t5GHLhwADZ1bfGARU47iE= 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=1XJWbmof9Q4s0DsmNHwfX7/DZoe+BgPc82bJ6Jcu0ig=; b=co8rtChVQmHj8Ooxs+352pxEP04vnMvCwIPMaW1j9K1fWinqvhfBQ01xJqULIAq8Wn VdACMyKu6na1cLK5wPchika/Ez+/WZzpAJhHFwtEOyfPJ6FApp7GhHkPrCEnJ9THnsPT cqZ4wf7wjgFMvvWSCYRcv8p2hSlaGk+Z3IQvpqXjja8YD39YcvOdmzU+Ya3yqhPERpnU ZrUeuAymXj3BUkzLX9aVCFgziUpjT49EaTi1P1618fmxZCj0T3JYO7ps/Cjz4zxED4/9 Nj7G3pwkqFBeD46ew8qnrPUsOCFfJR2pjYT7AZRzofw7+k90YV5unCOBCbCm7lPSqvcv 1Lsw== X-Gm-Message-State: APjAAAXctpwQ6enD+Mxu4SAda6D8Rhsj/68Qp9KcoMPSxsMccoGJ8en/ PslGSqD0Q8RJNj9oU9kHoUCOnCwuZ28= X-Google-Smtp-Source: APXvYqywBFkUjpXo/8lbxFePwyIBU6VpfPWLTMIrgIKFz+mCCOn4Tiw6dNheuETFamOsD2krVKVjmg== X-Received: by 2002:a6b:7e44:: with SMTP id k4mr526095ioq.306.1573761489341; Thu, 14 Nov 2019 11:58:09 -0800 (PST) Received: from kiwi.bld.corp.google.com ([2620:15c:183:0:8223:87c:a681:66aa]) by smtp.gmail.com with ESMTPSA id c83sm652546iof.48.2019.11.14.11.58.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Nov 2019 11:58:09 -0800 (PST) From: Simon Glass To: U-Boot Mailing List Date: Thu, 14 Nov 2019 12:57:13 -0700 Message-Id: <20191114125724.v4.5.I7aa3d4f52a2b16462b1c11eb90dcca7e2a1e52a5@changeid> X-Mailer: git-send-email 2.24.0.rc1.363.gb1bccd3e3d-goog In-Reply-To: <20191114195751.30357-1-sjg@chromium.org> References: <20191114195751.30357-1-sjg@chromium.org> MIME-Version: 1.0 Cc: Tom Rini Subject: [U-Boot] [PATCH v4 05/42] common: Move random-number functions into their own header X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.18 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" Create a new rand.h header file and move functions into it, to reduce the size of common.h Signed-off-by: Simon Glass Reviewed-by: Tom Rini --- Changes in v4: None Changes in v3: None Changes in v2: None include/common.h | 6 ------ include/net.h | 1 + include/rand.h | 40 ++++++++++++++++++++++++++++++++++++++++ lib/rand.c | 1 + net/link_local.c | 1 + 5 files changed, 43 insertions(+), 6 deletions(-) create mode 100644 include/rand.h diff --git a/include/common.h b/include/common.h index 52bcc2e591..b09c7aeddd 100644 --- a/include/common.h +++ b/include/common.h @@ -325,12 +325,6 @@ char * strmhz(char *buf, unsigned long hz); /* lib/crc32.c */ #include -/* lib/rand.c */ -#define RAND_MAX -1U -void srand(unsigned int seed); -unsigned int rand(void); -unsigned int rand_r(unsigned int *seedp); - /* * STDIO based functions (can always be used) */ diff --git a/include/net.h b/include/net.h index 75a16e4c8f..d8d187d8af 100644 --- a/include/net.h +++ b/include/net.h @@ -16,6 +16,7 @@ #include /* for nton* / ntoh* stuff */ #include #include +#include #define DEBUG_LL_STATE 0 /* Link local state machine changes */ #define DEBUG_DEV_PKT 0 /* Packets or info directed to the device */ diff --git a/include/rand.h b/include/rand.h new file mode 100644 index 0000000000..c9d15f50a1 --- /dev/null +++ b/include/rand.h @@ -0,0 +1,40 @@ +/* SPDX-License-Identifier: GPL-2.0+ */ +/* + * (C) Copyright 2000-2009 + * Wolfgang Denk, DENX Software Engineering, wd@denx.de. + */ + +#ifndef __RAND_H +#define __RAND_H + +#define RAND_MAX -1U + +/** + * srand() - Set the random-number seed value + * + * This can be used to restart the pseudo-random-number sequence from a known + * point. This affects future calls to rand() to start from that point + * + * @seed: New seed + */ +void srand(unsigned int seed); + +/** + * rand() - Get a 32-bit pseudo-random number + * + * @returns next random number in the sequence + */ +unsigned int rand(void); + +/** + * rand_r() - Get a 32-bit pseudo-random number + * + * This version of the function allows multiple sequences to be used at the + * same time, since it requires the caller to store the seed value. + * + * @seed value to use, updated on exit + * @returns next random number in the sequence + */ +unsigned int rand_r(unsigned int *seedp); + +#endif diff --git a/lib/rand.c b/lib/rand.c index af4cf3a0e8..d256baf5ce 100644 --- a/lib/rand.c +++ b/lib/rand.c @@ -8,6 +8,7 @@ */ #include +#include static unsigned int y = 1U; diff --git a/net/link_local.c b/net/link_local.c index dd9fcad087..1986b9b9d3 100644 --- a/net/link_local.c +++ b/net/link_local.c @@ -14,6 +14,7 @@ #include #include #include +#include #include "arp.h" #include "net_rand.h"