From mboxrd@z Thu Jan 1 00:00:00 1970 Return-path: Received: from metis.ext.pengutronix.de ([2001:67c:670:201:290:27ff:fe1d:cc33]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1cqKLP-0003HQ-2h for barebox@lists.infradead.org; Tue, 21 Mar 2017 14:01:05 +0000 From: Oleksij Rempel Date: Tue, 21 Mar 2017 15:00:22 +0100 Message-Id: <20170321140025.25784-6-o.rempel@pengutronix.de> In-Reply-To: <20170321140025.25784-1-o.rempel@pengutronix.de> References: <20170321140025.25784-1-o.rempel@pengutronix.de> List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "barebox" Errors-To: barebox-bounces+u.kleine-koenig=pengutronix.de@lists.infradead.org Subject: [PATCH v6 5/8] fs: add prng device To: barebox@lists.infradead.org Cc: Oleksij Rempel this should provide easy access to get_random_bytes() interfaces. Signed-off-by: Oleksij Rempel --- commands/stddev.c | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/commands/stddev.c b/commands/stddev.c index 318d05741..93da2c739 100644 --- a/commands/stddev.c +++ b/commands/stddev.c @@ -17,6 +17,7 @@ #include #include +#include static ssize_t zero_read(struct cdev *cdev, void *buf, size_t count, loff_t offset, ulong flags) { @@ -100,3 +101,31 @@ static int null_init(void) } device_initcall(null_init); + +static ssize_t prng_read(struct cdev *cdev, void *buf, size_t count, loff_t offset, ulong flags) +{ + get_random_bytes(buf, count); + return count; +} + +static struct file_operations prngops = { + .read = prng_read, + .lseek = dev_lseek_default, +}; + +static int prng_init(void) +{ + struct cdev *cdev; + + cdev = xzalloc(sizeof (*cdev)); + + cdev->name = "prng"; + cdev->flags = DEVFS_IS_CHARACTER_DEV; + cdev->ops = &prngops; + + devfs_create(cdev); + + return 0; +} + +device_initcall(prng_init); -- 2.11.0 _______________________________________________ barebox mailing list barebox@lists.infradead.org http://lists.infradead.org/mailman/listinfo/barebox