From patchwork Thu Mar 12 21:00:06 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Torokhov X-Patchwork-Id: 5999141 X-Patchwork-Delegate: herbert@gondor.apana.org.au Return-Path: X-Original-To: patchwork-linux-crypto@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 50F0FBF90F for ; Thu, 12 Mar 2015 21:00:35 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 55F3F20160 for ; Thu, 12 Mar 2015 21:00:34 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 51BD4200E9 for ; Thu, 12 Mar 2015 21:00:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755129AbbCLVAc (ORCPT ); Thu, 12 Mar 2015 17:00:32 -0400 Received: from mail-ig0-f172.google.com ([209.85.213.172]:40473 "EHLO mail-ig0-f172.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754162AbbCLVAb (ORCPT ); Thu, 12 Mar 2015 17:00:31 -0400 Received: by igal13 with SMTP id l13so468833iga.5; Thu, 12 Mar 2015 14:00:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=tZG+13ywdnebZfvFKiVOay1+3iZEpxfDty2MLEA5QOc=; b=tUUaHTsrPeqhyOSgmNn2i4fSlIvb+YPQtvEajYaMMug/8Q8BSjy0wn9Imbi+A1IfiB KqQ3hUI0d60eNu8HyZ7/HCSB0AB4XhPk/zua67fQjJ3qrCaJx/xYhMdFM11CpkOZV3HL 4Fgu9vNQI9t/7ZqIH3f0EvQc5zbyD4D740TzUCvHHowrvUmDNW2BlTMcX0SA4SILd/Me dUeV/TI2TbU9GTbxErHdzt1qr3sqgRuiX2v8tmcE34/QEtp/QOyzU7fTXxmUbQKm8sYG J2P2JYpMo47iCcAF1MoOtauZl3DgJsOrXSXJ5x39qXfStcLX2tCiNyzJKxRkn8PSP8xl 1HoQ== X-Received: by 10.107.37.132 with SMTP id l126mr78547363iol.42.1426194030960; Thu, 12 Mar 2015 14:00:30 -0700 (PDT) Received: from dtor-ws.mtv.corp.google.com ([172.22.64.149]) by mx.google.com with ESMTPSA id c8sm1267igx.9.2015.03.12.14.00.29 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 12 Mar 2015 14:00:30 -0700 (PDT) From: Dmitry Torokhov To: Herbert Xu Cc: linux-crypto@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 5/6] hwrng: iproc-rng200 - do not use static structure Date: Thu, 12 Mar 2015 14:00:06 -0700 Message-Id: <1426194007-22182-6-git-send-email-dmitry.torokhov@gmail.com> X-Mailer: git-send-email 2.2.0.rc0.207.ga3a616c In-Reply-To: <1426194007-22182-1-git-send-email-dmitry.torokhov@gmail.com> References: <1426194007-22182-1-git-send-email-dmitry.torokhov@gmail.com> Sender: linux-crypto-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org X-Spam-Status: No, score=-6.8 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, T_DKIM_INVALID, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Instead of using static hwrng structure that is reused between binds/unbinds of the device let's embed it into driver's private structure that we allocate. This way we are guaranteed not to stumble onto something left from previous bind attempt. Signed-off-by: Dmitry Torokhov --- drivers/char/hw_random/iproc-rng200.c | 44 +++++++++++++++++------------------ 1 file changed, 21 insertions(+), 23 deletions(-) diff --git a/drivers/char/hw_random/iproc-rng200.c b/drivers/char/hw_random/iproc-rng200.c index 276cb8a..2dbaf5c 100644 --- a/drivers/char/hw_random/iproc-rng200.c +++ b/drivers/char/hw_random/iproc-rng200.c @@ -48,9 +48,12 @@ #define RNG_FIFO_COUNT_RNG_FIFO_COUNT_MASK 0x000000FF struct iproc_rng200_dev { - void __iomem *base; + struct hwrng rng; + void __iomem *base; }; +#define to_rng_priv(rng) container_of(rng, struct iproc_rng200_dev, rng) + static void iproc_rng200_restart(void __iomem *rng_base) { uint32_t val; @@ -89,11 +92,11 @@ static void iproc_rng200_restart(void __iomem *rng_base) } static int iproc_rng200_read(struct hwrng *rng, void *buf, size_t max, - bool wait) + bool wait) { - uint32_t status; + struct iproc_rng200_dev *priv = to_rng_priv(rng); uint32_t num_remaining = max; - struct iproc_rng200_dev *priv = (struct iproc_rng200_dev *)rng->priv; + uint32_t status; #define MAX_RESETS_PER_READ 1 uint32_t num_resets = 0; @@ -151,10 +154,8 @@ static int iproc_rng200_read(struct hwrng *rng, void *buf, size_t max, static int iproc_rng200_init(struct hwrng *rng) { + struct iproc_rng200_dev *priv = to_rng_priv(rng); uint32_t val; - struct iproc_rng200_dev *priv; - - priv = (struct iproc_rng200_dev *)rng->priv; /* Setup RNG. */ val = ioread32(priv->base + RNG_CTRL_OFFSET); @@ -167,10 +168,8 @@ static int iproc_rng200_init(struct hwrng *rng) static void iproc_rng200_cleanup(struct hwrng *rng) { + struct iproc_rng200_dev *priv = to_rng_priv(rng); uint32_t val; - struct iproc_rng200_dev *priv; - - priv = (struct iproc_rng200_dev *)rng->priv; /* Disable RNG hardware */ val = ioread32(priv->base + RNG_CTRL_OFFSET); @@ -179,13 +178,6 @@ static void iproc_rng200_cleanup(struct hwrng *rng) iowrite32(val, priv->base + RNG_CTRL_OFFSET); } -static struct hwrng iproc_rng200_ops = { - .name = "iproc-rng200", - .read = iproc_rng200_read, - .init = iproc_rng200_init, - .cleanup = iproc_rng200_cleanup, -}; - static int iproc_rng200_probe(struct platform_device *pdev) { struct iproc_rng200_dev *priv; @@ -193,13 +185,10 @@ static int iproc_rng200_probe(struct platform_device *pdev) struct device *dev = &pdev->dev; int ret; - priv = devm_kzalloc(dev, sizeof(struct iproc_rng200_dev), GFP_KERNEL); + priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); if (!priv) return -ENOMEM; - iproc_rng200_ops.priv = (unsigned long)priv; - platform_set_drvdata(pdev, priv); - /* Map peripheral */ res = platform_get_resource(pdev, IORESOURCE_MEM, 0); if (!res) { @@ -213,13 +202,20 @@ static int iproc_rng200_probe(struct platform_device *pdev) return PTR_ERR(priv->base); } + priv->rng.name = "iproc-rng200", + priv->rng.read = iproc_rng200_read, + priv->rng.init = iproc_rng200_init, + priv->rng.cleanup = iproc_rng200_cleanup, + /* Register driver */ - ret = hwrng_register(&iproc_rng200_ops); + ret = hwrng_register(&priv->rng); if (ret) { dev_err(dev, "hwrng registration failed\n"); return ret; } + platform_set_drvdata(pdev, priv); + dev_info(dev, "hwrng registered\n"); return 0; @@ -227,8 +223,10 @@ static int iproc_rng200_probe(struct platform_device *pdev) static int iproc_rng200_remove(struct platform_device *pdev) { + struct iproc_rng200_dev *priv = platform_get_drvdata(pdev); + /* Unregister driver */ - hwrng_unregister(&iproc_rng200_ops); + hwrng_unregister(&priv->rng); return 0; }