diff options
author | Mark Brown <broonie@opensource.wolfsonmicro.com> | 2012-07-05 16:19:17 -0400 |
---|---|---|
committer | Theodore Ts'o <tytso@mit.edu> | 2012-07-19 10:38:31 -0400 |
commit | 9dccf55f4cb011a7552a8a2749a580662f5ed8ed (patch) | |
tree | cb6002c78787c636617fdc23e089e88d05c77c87 /drivers/rtc/rtc-wm831x.c | |
parent | 330e0a01d54c2b8606c56816f99af6ebc58ec92c (diff) |
rtc: wm831x: Feed the write counter into device_add_randomness()
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 <broonie@opensource.wolfsonmicro.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
Cc: stable@vger.kernel.org
Diffstat (limited to 'drivers/rtc/rtc-wm831x.c')
-rw-r--r-- | drivers/rtc/rtc-wm831x.c | 24 |
1 files changed, 23 insertions, 1 deletions
diff --git a/drivers/rtc/rtc-wm831x.c b/drivers/rtc/rtc-wm831x.c index 59c6245e0421..ea5c6f857ca5 100644 --- a/drivers/rtc/rtc-wm831x.c +++ b/drivers/rtc/rtc-wm831x.c | |||
@@ -24,7 +24,7 @@ | |||
24 | #include <linux/mfd/wm831x/core.h> | 24 | #include <linux/mfd/wm831x/core.h> |
25 | #include <linux/delay.h> | 25 | #include <linux/delay.h> |
26 | #include <linux/platform_device.h> | 26 | #include <linux/platform_device.h> |
27 | 27 | #include <linux/random.h> | |
28 | 28 | ||
29 | /* | 29 | /* |
30 | * R16416 (0x4020) - RTC Write Counter | 30 | * R16416 (0x4020) - RTC Write Counter |
@@ -96,6 +96,26 @@ struct wm831x_rtc { | |||
96 | unsigned int alarm_enabled:1; | 96 | unsigned int alarm_enabled:1; |
97 | }; | 97 | }; |
98 | 98 | ||
99 | static void wm831x_rtc_add_randomness(struct wm831x *wm831x) | ||
100 | { | ||
101 | int ret; | ||
102 | u16 reg; | ||
103 | |||
104 | /* | ||
105 | * The write counter contains a pseudo-random number which is | ||
106 | * regenerated every time we set the RTC so it should be a | ||
107 | * useful per-system source of entropy. | ||
108 | */ | ||
109 | ret = wm831x_reg_read(wm831x, WM831X_RTC_WRITE_COUNTER); | ||
110 | if (ret >= 0) { | ||
111 | reg = ret; | ||
112 | add_device_randomness(®, sizeof(reg)); | ||
113 | } else { | ||
114 | dev_warn(wm831x->dev, "Failed to read RTC write counter: %d\n", | ||
115 | ret); | ||
116 | } | ||
117 | } | ||
118 | |||
99 | /* | 119 | /* |
100 | * Read current time and date in RTC | 120 | * Read current time and date in RTC |
101 | */ | 121 | */ |
@@ -431,6 +451,8 @@ static int wm831x_rtc_probe(struct platform_device *pdev) | |||
431 | alm_irq, ret); | 451 | alm_irq, ret); |
432 | } | 452 | } |
433 | 453 | ||
454 | wm831x_rtc_add_randomness(wm831x); | ||
455 | |||
434 | return 0; | 456 | return 0; |
435 | 457 | ||
436 | err: | 458 | err: |