diff options
author | Dan Streetman <ddstreet@ieee.org> | 2015-05-28 22:21:31 +0200 |
---|---|---|
committer | Herbert Xu <herbert@gondor.apana.org.au> | 2015-06-03 04:51:23 +0200 |
commit | 3e648cbeb31be5cb84b9ec19822e2b85417f07c4 (patch) | |
tree | 4832384e797c3164b3d4321e49f13dd5a8c74c9d /drivers/crypto/nx/nx-842.c | |
parent | crypto: cryptd - Convert to new AEAD interface (diff) | |
download | linux-3e648cbeb31be5cb84b9ec19822e2b85417f07c4.tar.xz linux-3e648cbeb31be5cb84b9ec19822e2b85417f07c4.zip |
crypto: nx - prevent nx 842 load if no hw driver
Change the nx-842 common driver to wait for loading of both platform
drivers, and fail loading if the platform driver pointer is not set.
Add an independent platform driver pointer, that the platform drivers
set if they find they are able to load (i.e. if they find their platform
devicetree node(s)).
The problem is currently, the main nx-842 driver will stay loaded even
if there is no platform driver and thus no possible way it can do any
compression or decompression. This allows the crypto 842-nx driver
to load even if it won't actually work. For crypto compression users
(e.g. zswap) that expect an available crypto compression driver to
actually work, this is bad. This patch fixes that, so the 842-nx crypto
compression driver won't load if it doesn't have the driver and hardware
available to perform the compression.
Signed-off-by: Dan Streetman <ddstreet@ieee.org>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Diffstat (limited to 'drivers/crypto/nx/nx-842.c')
-rw-r--r-- | drivers/crypto/nx/nx-842.c | 130 |
1 files changed, 19 insertions, 111 deletions
diff --git a/drivers/crypto/nx/nx-842.c b/drivers/crypto/nx/nx-842.c index bf2823ceaf4e..9f391d64c722 100644 --- a/drivers/crypto/nx/nx-842.c +++ b/drivers/crypto/nx/nx-842.c @@ -21,71 +21,10 @@ #include "nx-842.h" -#define MODULE_NAME "nx-compress" MODULE_LICENSE("GPL"); MODULE_AUTHOR("Dan Streetman <ddstreet@ieee.org>"); MODULE_DESCRIPTION("842 H/W Compression driver for IBM Power processors"); -/* Only one driver is expected, based on the HW platform */ -static struct nx842_driver *nx842_driver; -static DEFINE_SPINLOCK(nx842_driver_lock); /* protects driver pointers */ - -void nx842_register_driver(struct nx842_driver *driver) -{ - spin_lock(&nx842_driver_lock); - - if (nx842_driver) { - pr_err("can't register driver %s, already using driver %s\n", - driver->owner->name, nx842_driver->owner->name); - } else { - pr_info("registering driver %s\n", driver->owner->name); - nx842_driver = driver; - } - - spin_unlock(&nx842_driver_lock); -} -EXPORT_SYMBOL_GPL(nx842_register_driver); - -void nx842_unregister_driver(struct nx842_driver *driver) -{ - spin_lock(&nx842_driver_lock); - - if (nx842_driver == driver) { - pr_info("unregistering driver %s\n", driver->owner->name); - nx842_driver = NULL; - } else if (nx842_driver) { - pr_err("can't unregister driver %s, using driver %s\n", - driver->owner->name, nx842_driver->owner->name); - } else { - pr_err("can't unregister driver %s, no driver in use\n", - driver->owner->name); - } - - spin_unlock(&nx842_driver_lock); -} -EXPORT_SYMBOL_GPL(nx842_unregister_driver); - -static struct nx842_driver *get_driver(void) -{ - struct nx842_driver *driver = NULL; - - spin_lock(&nx842_driver_lock); - - driver = nx842_driver; - - if (driver && !try_module_get(driver->owner)) - driver = NULL; - - spin_unlock(&nx842_driver_lock); - - return driver; -} - -static void put_driver(struct nx842_driver *driver) -{ - module_put(driver->owner); -} - /** * nx842_constraints * @@ -109,69 +48,38 @@ static void put_driver(struct nx842_driver *driver) */ int nx842_constraints(struct nx842_constraints *c) { - struct nx842_driver *driver = get_driver(); - int ret = 0; - - if (!driver) - return -ENODEV; - - BUG_ON(!c); - memcpy(c, driver->constraints, sizeof(*c)); - - put_driver(driver); - - return ret; + memcpy(c, nx842_platform_driver()->constraints, sizeof(*c)); + return 0; } EXPORT_SYMBOL_GPL(nx842_constraints); -int nx842_compress(const unsigned char *in, unsigned int in_len, - unsigned char *out, unsigned int *out_len, - void *wrkmem) +int nx842_compress(const unsigned char *in, unsigned int ilen, + unsigned char *out, unsigned int *olen, void *wmem) { - struct nx842_driver *driver = get_driver(); - int ret; - - if (!driver) - return -ENODEV; - - ret = driver->compress(in, in_len, out, out_len, wrkmem); - - put_driver(driver); - - return ret; + return nx842_platform_driver()->compress(in, ilen, out, olen, wmem); } EXPORT_SYMBOL_GPL(nx842_compress); -int nx842_decompress(const unsigned char *in, unsigned int in_len, - unsigned char *out, unsigned int *out_len, - void *wrkmem) +int nx842_decompress(const unsigned char *in, unsigned int ilen, + unsigned char *out, unsigned int *olen, void *wmem) { - struct nx842_driver *driver = get_driver(); - int ret; - - if (!driver) - return -ENODEV; - - ret = driver->decompress(in, in_len, out, out_len, wrkmem); - - put_driver(driver); - - return ret; + return nx842_platform_driver()->decompress(in, ilen, out, olen, wmem); } EXPORT_SYMBOL_GPL(nx842_decompress); static __init int nx842_init(void) { - pr_info("loading\n"); - - if (of_find_compatible_node(NULL, NULL, NX842_POWERNV_COMPAT_NAME)) - request_module_nowait(NX842_POWERNV_MODULE_NAME); - else if (of_find_compatible_node(NULL, NULL, NX842_PSERIES_COMPAT_NAME)) - request_module_nowait(NX842_PSERIES_MODULE_NAME); - else + request_module("nx-compress-powernv"); + request_module("nx-compress-pseries"); + + /* we prevent loading if there's no platform driver, and we get the + * module that set it so it won't unload, so we don't need to check + * if it's set in any of the above functions + */ + if (!nx842_platform_driver_get()) { pr_err("no nx842 driver found.\n"); - - pr_info("loaded\n"); + return -ENODEV; + } return 0; } @@ -179,6 +87,6 @@ module_init(nx842_init); static void __exit nx842_exit(void) { - pr_info("NX842 unloaded\n"); + nx842_platform_driver_put(); } module_exit(nx842_exit); |