Lustre code lacks checking the result of register_shrinker()
in several places. register_shrinker() was tagged __must_check
recently so that sparse has started reporting it.

Signed-off-by: Aliaksei Karaliou <akaraliou....@gmail.com>
---
 drivers/staging/lustre/lustre/ldlm/ldlm_pool.c     | 12 +++++++++---
 drivers/staging/lustre/lustre/obdclass/lu_object.c |  5 +++--
 drivers/staging/lustre/lustre/osc/osc_request.c    |  4 +++-
 drivers/staging/lustre/lustre/ptlrpc/sec_bulk.c    |  8 +++++++-
 4 files changed, 22 insertions(+), 7 deletions(-)

v2: Style fixes, as suggested by Cheers, Andreas and Dan Carpenter.
    Added one more patch to address resource cleanup, suggested by Dan 
Carpenter.

diff --git a/drivers/staging/lustre/lustre/ldlm/ldlm_pool.c 
b/drivers/staging/lustre/lustre/ldlm/ldlm_pool.c
index da65d00a7811..9fef2d52d6c2 100644
--- a/drivers/staging/lustre/lustre/ldlm/ldlm_pool.c
+++ b/drivers/staging/lustre/lustre/ldlm/ldlm_pool.c
@@ -1086,10 +1086,16 @@ int ldlm_pools_init(void)
        int rc;
 
        rc = ldlm_pools_thread_start();
-       if (rc == 0)
-               register_shrinker(&ldlm_pools_cli_shrinker);
+       if (rc)
+               return rc;
 
-       return rc;
+       rc = register_shrinker(&ldlm_pools_cli_shrinker);
+       if (rc) {
+               ldlm_pools_thread_stop();
+               return rc;
+       }
+
+       return 0;
 }
 
 void ldlm_pools_fini(void)
diff --git a/drivers/staging/lustre/lustre/obdclass/lu_object.c 
b/drivers/staging/lustre/lustre/obdclass/lu_object.c
index b938a3f9d50a..9e0256ca2079 100644
--- a/drivers/staging/lustre/lustre/obdclass/lu_object.c
+++ b/drivers/staging/lustre/lustre/obdclass/lu_object.c
@@ -1951,7 +1951,7 @@ int lu_global_init(void)
         * inode, one for ea. Unfortunately setting this high value results in
         * lu_object/inode cache consuming all the memory.
         */
-       register_shrinker(&lu_site_shrinker);
+       result = register_shrinker(&lu_site_shrinker);
 
        return result;
 }
@@ -1961,7 +1961,8 @@ int lu_global_init(void)
  */
 void lu_global_fini(void)
 {
-       unregister_shrinker(&lu_site_shrinker);
+       if (lu_site_shrinker.nr_deferred)
+               unregister_shrinker(&lu_site_shrinker);
        lu_context_key_degister(&lu_global_key);
 
        /*
diff --git a/drivers/staging/lustre/lustre/osc/osc_request.c 
b/drivers/staging/lustre/lustre/osc/osc_request.c
index 53eda4c99142..45b1ebf33363 100644
--- a/drivers/staging/lustre/lustre/osc/osc_request.c
+++ b/drivers/staging/lustre/lustre/osc/osc_request.c
@@ -2844,7 +2844,9 @@ static int __init osc_init(void)
        if (rc)
                goto out_kmem;
 
-       register_shrinker(&osc_cache_shrinker);
+       rc = register_shrinker(&osc_cache_shrinker);
+       if (rc)
+               goto out_type;
 
        /* This is obviously too much memory, only prevent overflow here */
        if (osc_reqpool_mem_max >= 1 << 12 || osc_reqpool_mem_max == 0) {
diff --git a/drivers/staging/lustre/lustre/ptlrpc/sec_bulk.c 
b/drivers/staging/lustre/lustre/ptlrpc/sec_bulk.c
index 77a3721beaee..485e7f15d850 100644
--- a/drivers/staging/lustre/lustre/ptlrpc/sec_bulk.c
+++ b/drivers/staging/lustre/lustre/ptlrpc/sec_bulk.c
@@ -396,6 +396,8 @@ static struct shrinker pools_shrinker = {
 
 int sptlrpc_enc_pool_init(void)
 {
+       int rc;
+
        /*
         * maximum capacity is 1/8 of total physical memory.
         * is the 1/8 a good number?
@@ -432,7 +434,11 @@ int sptlrpc_enc_pool_init(void)
        if (!page_pools.epp_pools)
                return -ENOMEM;
 
-       register_shrinker(&pools_shrinker);
+       rc = register_shrinker(&pools_shrinker);
+       if (rc) {
+               enc_pools_free();
+               return rc;
+       }
 
        return 0;
 }
-- 
2.11.0

_______________________________________________
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel

Reply via email to