From: Rusty Russell <rusty@rustcorp.com.au>
To: Herbert Xu <herbert@gondor.apana.org.au>,
Fengguang Wu <fengguang.wu@intel.com>, LKP <lkp@01.org>,
linux-kernel@vger.kernel.org,
Linux Crypto Mailing List <linux-crypto@vger.kernel.org>,
Amos Kong <akong@redhat.com>,
m@bues.ch, mpm@selenic.com, amit.shah@redhat.com
Subject: Re: [PATCH 1/5] hwrng: core - Use struct completion for cleanup_done
Date: Wed, 24 Dec 2014 09:49:10 +1030 [thread overview]
Message-ID: <87tx0mgdjl.fsf@rustcorp.com.au> (raw)
In-Reply-To: <E1Y3ICf-0007cX-B9@gondolin.me.apana.org.au>
Herbert Xu <herbert@gondor.apana.org.au> writes:
> There is no point in doing a manual completion for cleanup_done
> when struct completion fits in perfectly.
>
> Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Indeed.
Acked-by: Rusty Russell <rusty@rustcorp.com.au>
Thanks,
Rusty.
> ---
>
> drivers/char/hw_random/core.c | 12 +++---------
> include/linux/hw_random.h | 3 ++-
> 2 files changed, 5 insertions(+), 10 deletions(-)
>
> diff --git a/drivers/char/hw_random/core.c b/drivers/char/hw_random/core.c
> index 6ec4225..3dba2cf 100644
> --- a/drivers/char/hw_random/core.c
> +++ b/drivers/char/hw_random/core.c
> @@ -60,7 +60,6 @@ static DEFINE_MUTEX(rng_mutex);
> static DEFINE_MUTEX(reading_mutex);
> static int data_avail;
> static u8 *rng_buffer, *rng_fillbuf;
> -static DECLARE_WAIT_QUEUE_HEAD(rng_done);
> static unsigned short current_quality;
> static unsigned short default_quality; /* = 0; default to "off" */
>
> @@ -100,10 +99,7 @@ static inline void cleanup_rng(struct kref *kref)
> if (rng->cleanup)
> rng->cleanup(rng);
>
> - /* cleanup_done should be updated after cleanup finishes */
> - smp_wmb();
> - rng->cleanup_done = true;
> - wake_up_all(&rng_done);
> + complete(&rng->cleanup_done);
> }
>
> static void set_current_rng(struct hwrng *rng)
> @@ -498,7 +494,7 @@ int hwrng_register(struct hwrng *rng)
> add_early_randomness(rng);
> }
>
> - rng->cleanup_done = false;
> + init_completion(&rng->cleanup_done);
>
> out_unlock:
> mutex_unlock(&rng_mutex);
> @@ -532,9 +528,7 @@ void hwrng_unregister(struct hwrng *rng)
> } else
> mutex_unlock(&rng_mutex);
>
> - /* Just in case rng is reading right now, wait. */
> - wait_event(rng_done, rng->cleanup_done &&
> - atomic_read(&rng->ref.refcount) == 0);
> + wait_for_completion(&rng->cleanup_done);
> }
> EXPORT_SYMBOL_GPL(hwrng_unregister);
>
> diff --git a/include/linux/hw_random.h b/include/linux/hw_random.h
> index 7832e50..eb7b414 100644
> --- a/include/linux/hw_random.h
> +++ b/include/linux/hw_random.h
> @@ -12,6 +12,7 @@
> #ifndef LINUX_HWRANDOM_H_
> #define LINUX_HWRANDOM_H_
>
> +#include <linux/completion.h>
> #include <linux/types.h>
> #include <linux/list.h>
> #include <linux/kref.h>
> @@ -46,7 +47,7 @@ struct hwrng {
> /* internal. */
> struct list_head list;
> struct kref ref;
> - bool cleanup_done;
> + struct completion cleanup_done;
> };
>
> /** Register a new Hardware Random Number Generator driver. */
next prev parent reply other threads:[~2014-12-23 23:19 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <20141223030956.GA26839@wfg-t540p.sh.intel.com>
2014-12-23 5:39 ` [0/5] hwrng: Fix kref warning and underlying bugs Herbert Xu
2014-12-23 5:40 ` [PATCH 1/5] hwrng: core - Use struct completion for cleanup_done Herbert Xu
2014-12-23 23:19 ` Rusty Russell [this message]
2014-12-23 5:40 ` [PATCH 2/5] hwrng: core - Fix current_rng init/cleanup race yet again Herbert Xu
2014-12-23 23:26 ` Rusty Russell
2014-12-26 0:52 ` Herbert Xu
2014-12-23 5:40 ` [PATCH 3/5] hwrng: core - Do not register device opportunistically Herbert Xu
2014-12-23 23:29 ` Rusty Russell
2014-12-26 1:00 ` Herbert Xu
2014-12-23 5:40 ` [PATCH 4/5] hwrng: core - Drop current rng in set_current_rng Herbert Xu
2014-12-23 5:40 ` [PATCH 5/5] hwrng: core - Move hwrng_init call into set_current_rng Herbert Xu
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=87tx0mgdjl.fsf@rustcorp.com.au \
--to=rusty@rustcorp.com.au \
--cc=akong@redhat.com \
--cc=amit.shah@redhat.com \
--cc=fengguang.wu@intel.com \
--cc=herbert@gondor.apana.org.au \
--cc=linux-crypto@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=lkp@01.org \
--cc=m@bues.ch \
--cc=mpm@selenic.com \
/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).