From patchwork Thu Aug 18 12:37:21 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Thompson X-Patchwork-Id: 9287507 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 5875C600CB for ; Thu, 18 Aug 2016 12:37:49 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4A0522915C for ; Thu, 18 Aug 2016 12:37:49 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3EA9B29170; Thu, 18 Aug 2016 12:37:49 +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=-6.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,T_DKIM_INVALID 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 AB6BC2915C for ; Thu, 18 Aug 2016 12:37:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753844AbcHRMhr (ORCPT ); Thu, 18 Aug 2016 08:37:47 -0400 Received: from mail-wm0-f50.google.com ([74.125.82.50]:37156 "EHLO mail-wm0-f50.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753755AbcHRMhq (ORCPT ); Thu, 18 Aug 2016 08:37:46 -0400 Received: by mail-wm0-f50.google.com with SMTP id i5so29895830wmg.0 for ; Thu, 18 Aug 2016 05:37:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id; bh=rP4C9Vbyq1fxzfsKEOZHjPfVHgTEhczN7V9BedzREl4=; b=Vx37pqc1DABfOwrw7mXbkj7UJEnKOf7KncqciCJbv+wuxWL1oOFuJOjQVr0if0hYqK zBzzS9Qv0LWUh3zIKbBYWIHwjf+TiaJCFFbQ2pLA9rUrhzkULDOkmBPpGHAlv7VE/O4K DHkkiJxRPEA9HYWXz5gD5aXkzfKw3OZ2w0ivs= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=rP4C9Vbyq1fxzfsKEOZHjPfVHgTEhczN7V9BedzREl4=; b=UlgMy9F9KQYP+FAk8cvKHgVvXVdJceDOsbGa+ern6mSmQL9ziW1F+UZQZ4MJYsmiMt D7zMWU+q02kBekVOaN5TKcwvH+15nX2oqKMB6CoBIBTlyt7K7gNBghI+1W7ETZuIsh5L EWAB1M2/TLL+AfBAb57k1QbgPflJVYhowlg+/ruS0tDZe0VR9VaDspRwybBop4mMkAx9 8h5sUQzuklLrgfqNqZZ83i4AT2cl07NzF0pJhGLSIshEZrtduXSLQI5ItDKKXickcCoY mZ8ZTYARy9eVgmaSJ3LT94qtoQ1hdaCw+4C/FVu02W0ev/a2K5xn5VI5KS1yyuQLlqaL AT0w== X-Gm-Message-State: AEkooutq/9KUSgsltdSy2Vnbe527zsReoNPgtEwoskCENjGiW1AdrZXEZ/xeCQN+STd9SwTq X-Received: by 10.194.202.198 with SMTP id kk6mr1969680wjc.22.1471523864518; Thu, 18 Aug 2016 05:37:44 -0700 (PDT) Received: from wychelm.lan (cpc4-aztw19-0-0-cust71.18-1.cable.virginm.net. [82.33.25.72]) by smtp.gmail.com with ESMTPSA id x6sm2079896wjk.26.2016.08.18.05.37.43 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 18 Aug 2016 05:37:43 -0700 (PDT) From: Daniel Thompson To: Matt Mackall , Herbert Xu Cc: Daniel Thompson , linux-crypto@vger.kernel.org, linux-kernel@vger.kernel.org, patches@linaro.org, linaro-kernel@lists.linaro.org, LABBE Corentin , PrasannaKumar Muralidharan Subject: [PATCH] hw_random: Improve description of the ->read() interface Date: Thu, 18 Aug 2016 13:37:21 +0100 Message-Id: <1471523841-30469-1-git-send-email-daniel.thompson@linaro.org> X-Mailer: git-send-email 2.7.4 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 Currently, very few RNG drivers support single byte reads using the ->read() interface. Of the 14 drivers in drivers/char/hw_random that support this interface only three of these actually support max == 1. The other behaviours vary between return 0, return 2, return 4 and return -EIO). This is not a problem in practice because the core hw_random code never performs a read shorter than 16 bytes. The documentation for this function already contrains the alignment of the buffer pointer, so let's also guarantee that the buffer is at least as large as its alignment. This constraint is intended to be the weakest guarantee neccessary to allow driver writers to safely simplify their code. Signed-off-by: Daniel Thompson --- include/linux/hw_random.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) -- 2.7.4 -- To unsubscribe from this list: send the line "unsubscribe linux-crypto" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/include/linux/hw_random.h b/include/linux/hw_random.h index 4f7d8f4b1e9a..34a0dc18f327 100644 --- a/include/linux/hw_random.h +++ b/include/linux/hw_random.h @@ -29,7 +29,9 @@ * Returns the number of lower random bytes in "data". * Must not be NULL. *OBSOLETE* * @read: New API. drivers can fill up to max bytes of data - * into the buffer. The buffer is aligned for any type. + * into the buffer. The buffer is aligned for any type + * and max is guaranteed to be >= to that alignment + * (either 4 or 8 depending on architecture). * @priv: Private data, for use by the RNG driver. * @quality: Estimation of true entropy in RNG's bitstream * (per mill).