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: 74155 Delivered-To: patches@linaro.org Received: by 10.140.29.52 with SMTP id a49csp325546qga; Thu, 18 Aug 2016 05:37:45 -0700 (PDT) X-Received: by 10.28.220.8 with SMTP id t8mr17271726wmg.114.1471523864966; Thu, 18 Aug 2016 05:37:44 -0700 (PDT) Return-Path: Received: from mail-wm0-x230.google.com (mail-wm0-x230.google.com. [2a00:1450:400c:c09::230]) by mx.google.com with ESMTPS id ht7si1709997wjb.52.2016.08.18.05.37.44 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 18 Aug 2016 05:37:44 -0700 (PDT) Received-SPF: pass (google.com: domain of daniel.thompson@linaro.org designates 2a00:1450:400c:c09::230 as permitted sender) client-ip=2a00:1450:400c:c09::230; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org; spf=pass (google.com: domain of daniel.thompson@linaro.org designates 2a00:1450:400c:c09::230 as permitted sender) smtp.mailfrom=daniel.thompson@linaro.org; dmarc=pass (p=NONE dis=NONE) header.from=linaro.org Received: by mail-wm0-x230.google.com with SMTP id f65so236798169wmi.0 for ; Thu, 18 Aug 2016 05:37:44 -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=QxOIp88cDcqiYkfo1qyz7Bw5orlroS//gZuv+90uby3QGVSXVdaG717rqQvm4OmgAo y4DslOitK8D6oyIejhoK2i6l3idJhpp2rBb+Z1a3376swW3DXExPSt6ABCYIh7fpLi9y JFWodKLQgnsKewnKz31zUCCOlwCC44bP5EJkrwCzqhnqh9FsXWiuA5leCI7euSOJUfhz j3gt7+9227JSkU9MX7xVcwfWz2uR+W6iWq2rsYc4LtAPNWuZmxOgw3bmylVUlHUN8cU2 zmr2Ne/QWK9iAn1lHLp0aUe9nQuby3cnpLfQVvlrseZAH2JMKlCF69MWt0C9q3M3MXza pUzQ== X-Gm-Message-State: AEkoouuVGQuetAQCV4oNBdpjfzfeq4GlSZ3XIfWbsNtDmWfhUjZkGCemxueaK3Xdl4QVcCu19Mk= X-Received: by 10.194.202.198 with SMTP id kk6mr1969680wjc.22.1471523864518; Thu, 18 Aug 2016 05:37:44 -0700 (PDT) Return-Path: 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 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 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).