From: Andrew Morton <akpm@osdl.org>
To: Michael Buesch <mb@bu3sch.de>
Cc: dsaxena@plexity.net, bcm43xx-dev@lists.berlios.de,
linux-kernel@vger.kernel.org, vsu@altlinux.ru, mb@bu3sch.de
Subject: Re: [patch 2/9] Add new generic HW RNG core
Date: Mon, 15 May 2006 15:02:02 -0700 [thread overview]
Message-ID: <20060515150202.0835232d.akpm@osdl.org> (raw)
In-Reply-To: <20060515145316.089681000@bu3sch.de>
Michael Buesch <mb@bu3sch.de> wrote:
>
> ...
>
> +static inline
> +int hwrng_init(struct hwrng *rng)
> +static inline
> +void hwrng_cleanup(struct hwrng *rng)
> +static inline
> +int hwrng_data_present(struct hwrng *rng)
> +static inline
> +int hwrng_data_read(struct hwrng *rng, u32 *data)
Lose the newlines, please.
> +static int rng_dev_open(struct inode *inode, struct file *filp)
Like that.
> +static ssize_t rng_dev_read(struct file *filp, char __user *buf,
> + size_t size, loff_t *offp)
> +{
> + int have_data;
> + u32 data;
> + ssize_t ret = 0;
> + int i, err = 0;
> +
> + while (size) {
> + err = -ERESTARTSYS;
> + if (mutex_lock_interruptible(&rng_mutex))
> + goto out;
> + if (!current_rng) {
> + mutex_unlock(&rng_mutex);
> + err = -ENODEV;
> + goto out;
> + }
> + have_data = 0;
> + if (hwrng_data_present(current_rng))
> + have_data = hwrng_data_read(current_rng, &data);
> + mutex_unlock(&rng_mutex);
> +
> + err = -EFAULT;
> + while (have_data && size) {
> + if (put_user((u8)data, buf++))
> + goto out;
> + size--;
> + ret++;
> + have_data--;
> + data >>= 8;
> + }
> +
> + err = -EAGAIN;
> + if (filp->f_flags & O_NONBLOCK)
> + goto out;
> +
> + err = -ERESTARTSYS;
> + if (need_resched()) {
> + if (schedule_timeout_interruptible(1))
> + goto out;
> + } else {
> + if (mutex_lock_interruptible(&rng_mutex))
> + goto out;
> + if (!current_rng) {
> + mutex_unlock(&rng_mutex);
> + err = -ENODEV;
> + goto out;
> + }
> + for (i = 0; i < 20; i++) {
> + if (hwrng_data_present(current_rng))
> + break;
> + udelay(10);
> + }
> + mutex_unlock(&rng_mutex);
> + }
> + if (signal_pending(current))
> + goto out;
> + }
> +out:
> + return ret ? : err;
> +}
What's going on with the need_resched() tricks in there? (Unobvious, needs
a comment). From my reading, it'll cause a caller to this function to hang
for arbitrary periods of time if something if causing heavy scheduling
pressure.
What's the polling of hwrng_data_present() doing in here? (Unobvious,
needs a comment).
> +static ssize_t hwrng_attr_current_store(struct class_device *class,
> + const char *buf, size_t len)
> +{
> + int err;
> + struct hwrng *rng;
> +
> + if (!capable(CAP_SYS_ADMIN))
> + return -EPERM;
Are the sysfs permissions not adequate?
> +MODULE_AUTHOR("The Linux Kernel team");
Mutter. Might as well remove this.
A MAINTAINERS record would be nice.
next parent reply other threads:[~2006-05-15 21:59 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <20060515145243.905923000@bu3sch.de>
[not found] ` <20060515145316.089681000@bu3sch.de>
2006-05-15 22:02 ` Andrew Morton [this message]
2006-05-16 12:56 ` [patch 2/9] Add new generic HW RNG core Michael Buesch
[not found] ` <20060515145317.142226000@bu3sch.de>
2006-05-16 22:29 ` [patch 6/9] Add VIA HW RNG driver Andrew Morton
2006-05-16 23:30 ` Jeff Garzik
2006-05-12 10:35 [patch 0/9] New Generic HW RNG (#3) mb
2006-05-12 10:35 ` [patch 2/9] Add new generic HW RNG core mb
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20060515150202.0835232d.akpm@osdl.org \
--to=akpm@osdl.org \
--cc=bcm43xx-dev@lists.berlios.de \
--cc=dsaxena@plexity.net \
--cc=linux-kernel@vger.kernel.org \
--cc=mb@bu3sch.de \
--cc=vsu@altlinux.ru \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox