From patchwork Fri Nov 18 17:30:10 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: PrasannaKumar Muralidharan X-Patchwork-Id: 9437141 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 A62C060237 for ; Fri, 18 Nov 2016 17:30:49 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9A0A52998A for ; Fri, 18 Nov 2016 17:30:49 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8DFEE299A1; Fri, 18 Nov 2016 17:30: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_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, 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 292422998A for ; Fri, 18 Nov 2016 17:30:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752345AbcKRRar (ORCPT ); Fri, 18 Nov 2016 12:30:47 -0500 Received: from mail-pg0-f67.google.com ([74.125.83.67]:33802 "EHLO mail-pg0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752057AbcKRRaj (ORCPT ); Fri, 18 Nov 2016 12:30:39 -0500 Received: by mail-pg0-f67.google.com with SMTP id e9so20819927pgc.1 for ; Fri, 18 Nov 2016 09:30:39 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id; bh=Dv2hd9eDSHif8syL+dGnymvFInfuIr+drbgFaRsg/yU=; b=y1n0Z+eqZ2Z//mGPn7MmpqDajfaJ3QzbikbPxvXSLK5LbAZ3uzBHhV8a2lCZYyp98G yDGcGB4UYrOzvAQjJwYVXEpi63HDkiY8Tw2UdP6c7tWcPyX8F1jyhDTWoy9f9ANTl43a LMpOyetbk1I3WPrWJhPNKobakasprAwi9DNHOgL1mrjMWjCDr2zdxB78vsg68hh71w1z w1RUjnLgM9RhxjwZrzHdncVRB6ppUKSuHQ/fu9+teleH2xbgI6tpbQ4epr8i6GLvfzzo 6U8CbPAdeLXz3Xn1+OxZsfeB+U6+wmO/WZkR1VYYzvAXMh2S/6uE5qfr+/3/JTDEl19M eT4g== 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=Dv2hd9eDSHif8syL+dGnymvFInfuIr+drbgFaRsg/yU=; b=LENR/zTzwE/VTAXvtHwjsYKVMAHK7oKOFVVyfLCds9LRohHOxH1BFwgJmpE592m4Og 7bmn/SwhnuylwlrMOZxIqhQyew72zTe3gze/lUmn+wRCIf1Lqf37uUKiGSGY+PWlrRZh St0UPP4ZcDXV9JJQcAVN95LZ+A6IjB0PL0nzKqh91OilzkaWC5tGMy7IBJFFOOYP1bpT OU/0SfQ25rcWCLlQxN2sSGt/yPluqyyS8Jl66O4E/YpQFlzBx+Tg8vDxSzvXUyNEQ6ty qhrHi7ImJ3JR9OLC/QgKaHoyvjMYVeatnMeUzVl8KdlEQh/xw7dV7ol6C927UkMnIKZB dYIw== X-Gm-Message-State: AKaTC00IAh2J/sF13sNAcx7QP52jhkMLHNMFhLOtlGg7n8a3UCEwEP8KW9c5YLtWbNwCLQ== X-Received: by 10.98.35.5 with SMTP id j5mr1076609pfj.91.1479490238705; Fri, 18 Nov 2016 09:30:38 -0800 (PST) Received: from localhost.localdomain ([180.151.32.106]) by smtp.gmail.com with ESMTPSA id a66sm19377255pfa.64.2016.11.18.09.30.35 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 18 Nov 2016 09:30:38 -0800 (PST) From: PrasannaKumar Muralidharan To: mpm@selenic.com, herbert@gondor.apana.org.au, daniel.thompson@linaro.org, linux-crypto@vger.kernel.org Cc: PrasannaKumar Muralidharan Subject: [PATCH] hw_random: Make explicit that max >= 32 always Date: Fri, 18 Nov 2016 23:00:10 +0530 Message-Id: <20161118173010.5448-1-prasannatsmkumar@gmail.com> X-Mailer: git-send-email 2.9.3 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 hw_random core calls ->read with max > 32 or more, make it explicit. Also remove checks involving 'max' being less than 8. Signed-off-by: PrasannaKumar Muralidharan --- drivers/char/hw_random/msm-rng.c | 4 ---- drivers/char/hw_random/pic32-rng.c | 3 --- drivers/char/hw_random/pseries-rng.c | 5 ++--- include/linux/hw_random.h | 3 +-- 4 files changed, 3 insertions(+), 12 deletions(-) diff --git a/drivers/char/hw_random/msm-rng.c b/drivers/char/hw_random/msm-rng.c index 96fb986..841fee8 100644 --- a/drivers/char/hw_random/msm-rng.c +++ b/drivers/char/hw_random/msm-rng.c @@ -90,10 +90,6 @@ static int msm_rng_read(struct hwrng *hwrng, void *data, size_t max, bool wait) /* calculate max size bytes to transfer back to caller */ maxsize = min_t(size_t, MAX_HW_FIFO_SIZE, max); - /* no room for word data */ - if (maxsize < WORD_SZ) - return 0; - ret = clk_prepare_enable(rng->clk); if (ret) return ret; diff --git a/drivers/char/hw_random/pic32-rng.c b/drivers/char/hw_random/pic32-rng.c index 11dc9b7..9b5e68a 100644 --- a/drivers/char/hw_random/pic32-rng.c +++ b/drivers/char/hw_random/pic32-rng.c @@ -62,9 +62,6 @@ static int pic32_rng_read(struct hwrng *rng, void *buf, size_t max, u32 t; unsigned int timeout = RNG_TIMEOUT; - if (max < 8) - return 0; - do { t = readl(priv->base + RNGRCNT) & RCNT_MASK; if (t == 64) { diff --git a/drivers/char/hw_random/pseries-rng.c b/drivers/char/hw_random/pseries-rng.c index 63ce51d..d9f46b4 100644 --- a/drivers/char/hw_random/pseries-rng.c +++ b/drivers/char/hw_random/pseries-rng.c @@ -28,7 +28,6 @@ static int pseries_rng_read(struct hwrng *rng, void *data, size_t max, bool wait) { u64 buffer[PLPAR_HCALL_BUFSIZE]; - size_t size = max < 8 ? max : 8; int rc; rc = plpar_hcall(H_RANDOM, (unsigned long *)buffer); @@ -36,10 +35,10 @@ static int pseries_rng_read(struct hwrng *rng, void *data, size_t max, bool wait pr_err_ratelimited("H_RANDOM call failed %d\n", rc); return -EIO; } - memcpy(data, buffer, size); + memcpy(data, buffer, 8); /* The hypervisor interface returns 64 bits */ - return size; + return 8; } /** diff --git a/include/linux/hw_random.h b/include/linux/hw_random.h index 34a0dc1..bee0827 100644 --- a/include/linux/hw_random.h +++ b/include/linux/hw_random.h @@ -30,8 +30,7 @@ * 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 - * and max is guaranteed to be >= to that alignment - * (either 4 or 8 depending on architecture). + * and max is a multiple of 4 and >= 32 bytes. * @priv: Private data, for use by the RNG driver. * @quality: Estimation of true entropy in RNG's bitstream * (per mill).