linux-arm-kernel.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
From: lee.jones@linaro.org (Lee Jones)
To: linux-arm-kernel@lists.infradead.org
Subject: [PATCH 2/6] hwrng: core: Simplify RNG switching from sysfs
Date: Fri, 11 Sep 2015 21:08:26 +0100	[thread overview]
Message-ID: <1442002110-28733-3-git-send-email-lee.jones@linaro.org> (raw)
In-Reply-To: <1442002110-28733-1-git-send-email-lee.jones@linaro.org>

If we attempt to use sysfs to change the current RNG in the usual
way i.e. issuing something like:

`echo 8a8a000.rng > /sys/devices/virtual/misc/hw_random/rng_current`

... it will fail because the code doesn't currently take the '\n'
into consideration.  Well, now it does.

Signed-off-by: Lee Jones <lee.jones@linaro.org>
---
 drivers/char/hw_random/core.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/drivers/char/hw_random/core.c b/drivers/char/hw_random/core.c
index da8faf7..14dc984 100644
--- a/drivers/char/hw_random/core.c
+++ b/drivers/char/hw_random/core.c
@@ -316,6 +316,7 @@ static ssize_t hwrng_attr_current_store(struct device *dev,
 					const char *buf, size_t len)
 {
 	int err;
+	int snip = 0;
 	struct hwrng *rng;
 
 	err = mutex_lock_interruptible(&rng_mutex);
@@ -323,7 +324,11 @@ static ssize_t hwrng_attr_current_store(struct device *dev,
 		return -ERESTARTSYS;
 	err = -ENODEV;
 	list_for_each_entry(rng, &rng_list, list) {
-		if (strcmp(rng->name, buf) == 0) {
+
+		if (buf[len-1] == '\n')
+			snip = 1; /* Snip one character */
+
+		if (strncmp(rng->name, buf, len - snip) == 0) {
 			err = 0;
 			if (rng != current_rng)
 				err = set_current_rng(rng);
-- 
1.9.1

  parent reply	other threads:[~2015-09-11 20:08 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-09-11 20:08 [PATCH 0/6] hwrng: Add support for STMicroelectronics' RNG IP Lee Jones
2015-09-11 20:08 ` [PATCH 1/6] Documentation: hw_random: Fix device node name /dev/hw_random => /dev/hwrng Lee Jones
2015-09-14 14:57   ` Kieran Bingham
2015-09-11 20:08 ` Lee Jones [this message]
2015-09-13 14:24   ` [PATCH 2/6] hwrng: core: Simplify RNG switching from sysfs Peter Korsgaard
2015-09-14  7:27     ` Lee Jones
2015-09-11 20:08 ` [PATCH 3/6] hwrng: st: Provide DT bindings for ST's Random Number Generator Lee Jones
2015-09-11 20:08 ` [PATCH 4/6] hwrng: st: Add support for ST's HW " Lee Jones
2015-09-12 22:58   ` Kieran Bingham
2015-09-14  8:04     ` Lee Jones
2015-09-12 23:04   ` Fabio Estevam
2015-09-14  7:42     ` Lee Jones
2015-09-11 20:08 ` [PATCH 5/6] ARM: STi: STiH407: Enable the 2 HW Random Number Generators for STiH4{07, 10} Lee Jones
2015-09-11 20:08 ` [PATCH 6/6] MAINTAINERS: Add ST's Random Number Generator to the ST entry Lee Jones

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=1442002110-28733-3-git-send-email-lee.jones@linaro.org \
    --to=lee.jones@linaro.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    /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;
as well as URLs for NNTP newsgroup(s).