From patchwork Thu Jul 5 20:19:17 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Brown X-Patchwork-Id: 169258 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from mail-wi0-f184.google.com (mail-wi0-f184.google.com [209.85.212.184]) (using TLSv1 with cipher ECDHE-RSA-RC4-SHA (128/128 bits)) (Client CN "smtp.gmail.com", Issuer "Google Internet Authority" (not verified)) by ozlabs.org (Postfix) with ESMTPS id 7EF8C2C01BC for ; Fri, 6 Jul 2012 06:20:10 +1000 (EST) Received: by wibhq12 with SMTP id hq12sf45083wib.11 for ; Thu, 05 Jul 2012 13:20:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlegroups.com; s=beta; h=mime-version:x-beenthere:received-spf:from:to:cc:subject:date :message-id:x-mailer:x-original-sender :x-original-authentication-results:reply-to:precedence:mailing-list :list-id:x-google-group-id:list-post:list-help:list-archive:sender :list-subscribe:list-unsubscribe:content-type; bh=wVO5vXATBq6k2BvsF94j88/zgJxvsZy3D648meqQJmk=; b=Ge4npXV5tcp0QqsnAC7nUVvCmLm6iBeYhqUyNZoabQoyl0UHMw9BzBgwfq7bf0/f3D cajrlUXfmtokGbFsT+lmnhPlkeRwJFJRvcAlmHp2AEInp7uOsl6yAEuf5va43u5Sqfak Y1vXB3+mHZaruAYtK8utSLunR1ld8ZX1KdrHc= Received: by 10.216.81.6 with SMTP id l6mr95058wee.62.1341519606627; Thu, 05 Jul 2012 13:20:06 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: rtc-linux@googlegroups.com Received: by 10.14.37.139 with SMTP id y11ls32949eea.4.gmail; Thu, 05 Jul 2012 13:20:06 -0700 (PDT) Received: by 10.180.98.199 with SMTP id ek7mr182896wib.0.1341519605853; Thu, 05 Jul 2012 13:20:05 -0700 (PDT) Received: by 10.180.98.199 with SMTP id ek7mr182895wib.0.1341519605843; Thu, 05 Jul 2012 13:20:05 -0700 (PDT) Received: from opensource.wolfsonmicro.com (opensource.wolfsonmicro.com. [80.75.67.52]) by gmr-mx.google.com with ESMTPS id em7si275403wib.2.2012.07.05.13.20.05 (version=TLSv1/SSLv3 cipher=OTHER); Thu, 05 Jul 2012 13:20:05 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of broonie@opensource.wolfsonmicro.com designates 80.75.67.52 as permitted sender) client-ip=80.75.67.52; Received: from finisterre.wolfsonmicro.main (unknown [87.246.78.26]) by opensource.wolfsonmicro.com (Postfix) with ESMTPSA id E2259750004; Thu, 5 Jul 2012 21:20:04 +0100 (BST) Received: from broonie by finisterre.wolfsonmicro.main with local (Exim 4.77) (envelope-from ) id 1SmsWx-0001Ma-HE; Thu, 05 Jul 2012 21:20:04 +0100 From: Mark Brown To: Theodore Ts'o , Alessandro Zummo , Andrew Morton Cc: linux-kernel@vger.kernel.org, patches@opensource.wolfsonmicro.com, rtc-linux@googlegroups.com, Mark Brown Subject: [rtc-linux] [PATCH] rtc: wm831x: Feed the write counter into device_add_randomness() Date: Thu, 5 Jul 2012 21:19:17 +0100 Message-Id: <1341519557-5115-1-git-send-email-broonie@opensource.wolfsonmicro.com> X-Mailer: git-send-email 1.7.10 X-Original-Sender: broonie@opensource.wolfsonmicro.com X-Original-Authentication-Results: gmr-mx.google.com; spf=pass (google.com: best guess record for domain of broonie@opensource.wolfsonmicro.com designates 80.75.67.52 as permitted sender) smtp.mail=broonie@opensource.wolfsonmicro.com Reply-To: rtc-linux@googlegroups.com Precedence: list Mailing-list: list rtc-linux@googlegroups.com; contact rtc-linux+owners@googlegroups.com List-ID: X-Google-Group-Id: 712029733259 List-Post: , List-Help: , List-Archive: Sender: rtc-linux@googlegroups.com List-Subscribe: , List-Unsubscribe: , The tamper evident features of the RTC include the "write counter" which is a pseudo-random number regenerated whenever we set the RTC. Since this value is unpredictable it should provide some useful seeding to the random number generator. Only do this on boot since the goal is to seed the pool rather than add useful entropy. Signed-off-by: Mark Brown --- add_device_randomness() has only just been added in -next, this will need to either wait until after the merge window or be merged along with the patch adding it. drivers/rtc/rtc-wm831x.c | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/drivers/rtc/rtc-wm831x.c b/drivers/rtc/rtc-wm831x.c index 59c6245..ea5c6f8 100644 --- a/drivers/rtc/rtc-wm831x.c +++ b/drivers/rtc/rtc-wm831x.c @@ -24,7 +24,7 @@ #include #include #include - +#include /* * R16416 (0x4020) - RTC Write Counter @@ -96,6 +96,26 @@ struct wm831x_rtc { unsigned int alarm_enabled:1; }; +static void wm831x_rtc_add_randomness(struct wm831x *wm831x) +{ + int ret; + u16 reg; + + /* + * The write counter contains a pseudo-random number which is + * regenerated every time we set the RTC so it should be a + * useful per-system source of entropy. + */ + ret = wm831x_reg_read(wm831x, WM831X_RTC_WRITE_COUNTER); + if (ret >= 0) { + reg = ret; + add_device_randomness(®, sizeof(reg)); + } else { + dev_warn(wm831x->dev, "Failed to read RTC write counter: %d\n", + ret); + } +} + /* * Read current time and date in RTC */ @@ -431,6 +451,8 @@ static int wm831x_rtc_probe(struct platform_device *pdev) alm_irq, ret); } + wm831x_rtc_add_randomness(wm831x); + return 0; err: