[RESEND PATCH 1/2] crypto: caam/jr - Fix race by statically initializing global data

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



There is a race condition, when driver is not initialized
yet (jr_driver_init() was not called yet), but another kernel
code calls caam_jr_alloc(). This results in warnings about
uninitialized lock and NULL pointer dereference error.

Fix that by statically initializing global driver data, so
caam_jr_alloc() always works on initialized variables.

Signed-off-by: Marcin Niestroj <m.niestroj@xxxxxxxxxxxxxxxx>
---
 drivers/crypto/caam/jr.c | 20 +++++---------------
 1 file changed, 5 insertions(+), 15 deletions(-)

diff --git a/drivers/crypto/caam/jr.c b/drivers/crypto/caam/jr.c
index f4f258075b89..1352a4875d5a 100644
--- a/drivers/crypto/caam/jr.c
+++ b/drivers/crypto/caam/jr.c
@@ -21,7 +21,10 @@ struct jr_driver_data {
 	spinlock_t		jr_alloc_lock;	/* jr_list lock */
 } ____cacheline_aligned;
 
-static struct jr_driver_data driver_data;
+static struct jr_driver_data driver_data = {
+	.jr_list = LIST_HEAD_INIT(driver_data.jr_list),
+	.jr_alloc_lock = __SPIN_LOCK_UNLOCKED(driver_data.jr_alloc_lock),
+};
 
 static int caam_reset_hw_jr(struct device *dev)
 {
@@ -561,20 +564,7 @@ static struct platform_driver caam_jr_driver = {
 	.remove      = caam_jr_remove,
 };
 
-static int __init jr_driver_init(void)
-{
-	spin_lock_init(&driver_data.jr_alloc_lock);
-	INIT_LIST_HEAD(&driver_data.jr_list);
-	return platform_driver_register(&caam_jr_driver);
-}
-
-static void __exit jr_driver_exit(void)
-{
-	platform_driver_unregister(&caam_jr_driver);
-}
-
-module_init(jr_driver_init);
-module_exit(jr_driver_exit);
+module_platform_driver(caam_jr_driver);
 
 MODULE_LICENSE("GPL");
 MODULE_DESCRIPTION("FSL CAAM JR request backend");
-- 
2.18.0




[Index of Archives]     [Kernel]     [Gnu Classpath]     [Gnu Crypto]     [DM Crypt]     [Netfilter]     [Bugtraq]

  Powered by Linux