drivers: lustre: obdclass: check result of register_shrinker()
authorAliaksei Karaliou <akaraliou.dev@gmail.com>
Thu, 7 Dec 2017 07:25:53 +0000 (10:25 +0300)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 13 Dec 2017 11:37:50 +0000 (12:37 +0100)
lu_global_init() does not check result of register_shrinker()
which was tagged __must_check recently, reported by sparse.
Patch also fixes missed cleanup of resources allocated prior to
register_shrinker() invocation and not freed after any failure.

Signed-off-by: Aliaksei Karaliou <akaraliou.dev@gmail.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/staging/lustre/lustre/obdclass/lu_object.c

index b938a3f..8e2e6b8 100644 (file)
@@ -1932,8 +1932,10 @@ int lu_global_init(void)
 
        LU_CONTEXT_KEY_INIT(&lu_global_key);
        result = lu_context_key_register(&lu_global_key);
-       if (result != 0)
+       if (result != 0) {
+               lu_ref_global_fini();
                return result;
+       }
 
        /*
         * At this level, we don't know what tags are needed, so allocate them
@@ -1943,17 +1945,31 @@ int lu_global_init(void)
        down_write(&lu_sites_guard);
        result = lu_env_init(&lu_shrink_env, LCT_SHRINKER);
        up_write(&lu_sites_guard);
-       if (result != 0)
+       if (result != 0) {
+               lu_context_key_degister(&lu_global_key);
+               lu_ref_global_fini();
                return result;
+       }
 
        /*
         * seeks estimation: 3 seeks to read a record from oi, one to read
         * 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);
+       if (result != 0) {
+               /* Order explained in lu_global_fini(). */
+               lu_context_key_degister(&lu_global_key);
 
-       return result;
+               down_write(&lu_sites_guard);
+               lu_env_fini(&lu_shrink_env);
+               up_write(&lu_sites_guard);
+
+               lu_ref_global_fini();
+               return result;
+       }
+
+       return 0;
 }
 
 /**
@@ -1961,7 +1977,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);
 
        /*