From patchwork Thu Oct 19 20:45:05 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Jason A. Donenfeld" X-Patchwork-Id: 10018297 X-Patchwork-Delegate: herbert@gondor.apana.org.au Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id A42B3600CC for ; Thu, 19 Oct 2017 20:45:28 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9626028E5F for ; Thu, 19 Oct 2017 20:45:28 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 93FCB28E3E; Thu, 19 Oct 2017 20:45:28 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 048A828E5F for ; Thu, 19 Oct 2017 20:45:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753976AbdJSUp0 (ORCPT ); Thu, 19 Oct 2017 16:45:26 -0400 Received: from frisell.zx2c4.com ([192.95.5.64]:57167 "EHLO frisell.zx2c4.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753212AbdJSUp0 (ORCPT ); Thu, 19 Oct 2017 16:45:26 -0400 Received: by frisell.zx2c4.com (ZX2C4 Mail Server) with ESMTP id 99c544fb; Thu, 19 Oct 2017 20:44:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=zx2c4.com; h=from:to:cc :subject:date:message-id:in-reply-to:references; s=mail; bh=FRyS FKFfQeo0YBeYuEys6Hs3LDs=; b=3D9LOHzJ3QMwaKk408o6eHfDvktK3BVwW+A+ jmkVwnowanI8/mUDoG1uiTU1xHMyYrUJOb3qAe8IUf00CA5lwIGeTB/EJt9XXbXC gHd4gSt46wOJKvGV6HsPvI5vJOIVxskvSKvPZe22kxiv2yyQUMpsPGiMykLrvLa5 KA5N/Eo7XPR2vDyL7KvnTBg/UtKm/rUmlalBboZoMHLqTT2ZtEhHWCN1ic4Jq1oN kF7o/op7pfVjmpN5GgscI+O6ggpSbpTOi8aqpN+fXRdkJgVQIrOxwoewfme0pggW DGB/gQb7hybTFCpG3NkQS7mFa2VTvz1/Bv9w2Gnmd3zChemirw== Received: by frisell.zx2c4.com (ZX2C4 Mail Server) with ESMTPSA id 960a8dc0 (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256:NO); Thu, 19 Oct 2017 20:44:31 +0000 (UTC) From: "Jason A. Donenfeld" To: Kees Cook , LKML , linux-crypto@vger.kernel.org, herbert@gondor.apana.org.au, tytso@mit.edu, gregkh@linuxfoundation.org Cc: "Jason A. Donenfeld" Subject: [PATCH 1/2] random: always call random ready function Date: Thu, 19 Oct 2017 22:45:05 +0200 Message-Id: <20171019204506.25090-1-Jason@zx2c4.com> In-Reply-To: References: Sender: linux-crypto-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP As this interface becomes more heavily used, it will be painful for callers to always need to check for -EALREADY. Signed-off-by: Jason A. Donenfeld --- drivers/char/random.c | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/drivers/char/random.c b/drivers/char/random.c index 8ad92707e45f..e161acf35d4a 100644 --- a/drivers/char/random.c +++ b/drivers/char/random.c @@ -1556,40 +1556,45 @@ EXPORT_SYMBOL(wait_for_random_bytes); /* * Add a callback function that will be invoked when the nonblocking - * pool is initialised. + * pool is initialised, or calls that function if it already is. * * returns: 0 if callback is successfully added - * -EALREADY if pool is already initialised (callback not called) * -ENOENT if module for callback is not alive */ int add_random_ready_callback(struct random_ready_callback *rdy) { struct module *owner; unsigned long flags; - int err = -EALREADY; - if (crng_ready()) - return err; + BUG_ON(!rdy->func); + + if (crng_ready()) { + rdy->func(rdy); + rdy->func = NULL; + return 0; + } owner = rdy->owner; if (!try_module_get(owner)) return -ENOENT; spin_lock_irqsave(&random_ready_list_lock, flags); - if (crng_ready()) + if (crng_ready()) { + rdy->func(rdy); + rdy->func = NULL; goto out; + } owner = NULL; list_add(&rdy->list, &random_ready_list); - err = 0; out: spin_unlock_irqrestore(&random_ready_list_lock, flags); module_put(owner); - return err; + return 0; } EXPORT_SYMBOL(add_random_ready_callback); @@ -1601,6 +1606,9 @@ void del_random_ready_callback(struct random_ready_callback *rdy) unsigned long flags; struct module *owner = NULL; + if (!rdy->func) + return; + spin_lock_irqsave(&random_ready_list_lock, flags); if (!list_empty(&rdy->list)) { list_del_init(&rdy->list);