int result;
result = lu_kmem_init(ccc_caches);
- if (result == 0) {
- result = lu_device_type_init(device_type);
- ccc_inode_fini_env = cl_env_alloc(&dummy_refcheck,
- LCT_REMEMBER|LCT_NOREF);
- if (IS_ERR(ccc_inode_fini_env))
- result = PTR_ERR(ccc_inode_fini_env);
- else
- ccc_inode_fini_env->le_ctx.lc_cookie = 0x4;
+ if (result)
+ return result;
+
+ result = lu_device_type_init(device_type);
+ if (result)
+ goto out_kmem;
+
+ ccc_inode_fini_env = cl_env_alloc(&dummy_refcheck,
+ LCT_REMEMBER|LCT_NOREF);
+ if (IS_ERR(ccc_inode_fini_env)) {
+ result = PTR_ERR(ccc_inode_fini_env);
+ goto out_device;
}
+
+ ccc_inode_fini_env->le_ctx.lc_cookie = 0x4;
+ return 0;
+out_device:
+ lu_device_type_fini(device_type);
+out_kmem:
+ lu_kmem_fini(ccc_caches);
return result;
}
return result;
result = lu_kmem_init(cl_object_caches);
- if (result == 0) {
- LU_CONTEXT_KEY_INIT(&cl_key);
- result = lu_context_key_register(&cl_key);
- if (result == 0) {
- result = cl_lock_init();
- if (result == 0)
- result = cl_page_init();
- }
- }
if (result)
- cl_env_store_fini();
+ goto out_store;
+
+ LU_CONTEXT_KEY_INIT(&cl_key);
+ result = lu_context_key_register(&cl_key);
+ if (result)
+ goto out_kmem;
+
+ result = cl_lock_init();
+ if (result)
+ goto out_context;
+
+ result = cl_page_init();
+ if (result)
+ goto out_lock;
+
+ return 0;
+out_lock:
+ cl_lock_fini();
+out_context:
+ lu_context_key_degister(&cl_key);
+out_kmem:
+ lu_kmem_fini(cl_object_caches);
+out_store:
+ cl_env_store_fini();
return result;
}
int lu_kmem_init(struct lu_kmem_descr *caches)
{
int result;
+ struct lu_kmem_descr *iter = caches;
- for (result = 0; caches->ckd_cache != NULL; ++caches) {
- *caches->ckd_cache = cfs_mem_cache_create(caches->ckd_name,
- caches->ckd_size,
- 0, 0);
- if (*caches->ckd_cache == NULL) {
+ for (result = 0; iter->ckd_cache != NULL; ++iter) {
+ *iter->ckd_cache = cfs_mem_cache_create(iter->ckd_name,
+ iter->ckd_size,
+ 0, 0);
+ if (*iter->ckd_cache == NULL) {
result = -ENOMEM;
+ /* free all previously allocated caches */
+ lu_kmem_fini(caches);
break;
}
}
lprocfs_echo_init_vars(&lvars);
rc = lu_kmem_init(echo_caches);
- if (rc == 0)
+ if (rc == 0) {
rc = class_register_type(&echo_obd_ops, NULL,
lvars.module_vars,
LUSTRE_ECHO_CLIENT_NAME,
&echo_device_type);
- if (rc)
- lu_kmem_fini(echo_caches);
-
+ if (rc)
+ lu_kmem_fini(echo_caches);
+ }
return rc;
}