Commit 4d9b519c authored by Dmitry Torokhov's avatar Dmitry Torokhov Committed by Herbert Xu

hwrng: add devm_* interfaces

This change adds devm_hwrng_register and devm_hwrng_unregister which
use can simplify error unwinding and unbinding code paths in device
drivers.
Signed-off-by: default avatarDmitry Torokhov <dmitry.torokhov@gmail.com>
Signed-off-by: default avatarHerbert Xu <herbert@gondor.apana.org.au>
parent 05713ba9
...@@ -536,6 +536,48 @@ void hwrng_unregister(struct hwrng *rng) ...@@ -536,6 +536,48 @@ void hwrng_unregister(struct hwrng *rng)
} }
EXPORT_SYMBOL_GPL(hwrng_unregister); EXPORT_SYMBOL_GPL(hwrng_unregister);
static void devm_hwrng_release(struct device *dev, void *res)
{
hwrng_unregister(*(struct hwrng **)res);
}
static int devm_hwrng_match(struct device *dev, void *res, void *data)
{
struct hwrng **r = res;
if (WARN_ON(!r || !*r))
return 0;
return *r == data;
}
int devm_hwrng_register(struct device *dev, struct hwrng *rng)
{
struct hwrng **ptr;
int error;
ptr = devres_alloc(devm_hwrng_release, sizeof(*ptr), GFP_KERNEL);
if (!ptr)
return -ENOMEM;
error = hwrng_register(rng);
if (error) {
devres_free(ptr);
return error;
}
*ptr = rng;
devres_add(dev, ptr);
return 0;
}
EXPORT_SYMBOL_GPL(devm_hwrng_register);
void devm_hwrng_unregister(struct device *dev, struct hwrng *rng)
{
devres_release(dev, devm_hwrng_release, devm_hwrng_match, rng);
}
EXPORT_SYMBOL_GPL(devm_hwrng_unregister);
static int __init hwrng_modinit(void) static int __init hwrng_modinit(void)
{ {
return register_miscdev(); return register_miscdev();
......
...@@ -50,10 +50,14 @@ struct hwrng { ...@@ -50,10 +50,14 @@ struct hwrng {
struct completion cleanup_done; struct completion cleanup_done;
}; };
struct device;
/** Register a new Hardware Random Number Generator driver. */ /** Register a new Hardware Random Number Generator driver. */
extern int hwrng_register(struct hwrng *rng); extern int hwrng_register(struct hwrng *rng);
extern int devm_hwrng_register(struct device *dev, struct hwrng *rng);
/** Unregister a Hardware Random Number Generator driver. */ /** Unregister a Hardware Random Number Generator driver. */
extern void hwrng_unregister(struct hwrng *rng); extern void hwrng_unregister(struct hwrng *rng);
extern void devm_hwrng_unregister(struct device *dve, struct hwrng *rng);
/** Feed random bits into the pool. */ /** Feed random bits into the pool. */
extern void add_hwgenerator_randomness(const char *buffer, size_t count, size_t entropy); extern void add_hwgenerator_randomness(const char *buffer, size_t count, size_t entropy);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment