@@ -1118,20 +1118,33 @@ static int fill_super(struct super_block *sb, struct gfs2_args *args, int silent
1118
1118
}
1119
1119
1120
1120
error = init_names (sdp , silent );
1121
- if (error )
1122
- goto fail ;
1121
+ if (error ) {
1122
+ /* In this case, we haven't initialized sysfs, so we have to
1123
+ manually free the sdp. */
1124
+ free_percpu (sdp -> sd_lkstats );
1125
+ kfree (sdp );
1126
+ sb -> s_fs_info = NULL ;
1127
+ return error ;
1128
+ }
1123
1129
1124
1130
snprintf (sdp -> sd_fsname , GFS2_FSNAME_LEN , "%s" , sdp -> sd_table_name );
1125
1131
1126
- gfs2_create_debugfs_file (sdp );
1127
-
1128
1132
error = gfs2_sys_fs_add (sdp );
1133
+ /*
1134
+ * If we hit an error here, gfs2_sys_fs_add will have called function
1135
+ * kobject_put which causes the sysfs usage count to go to zero, which
1136
+ * causes sysfs to call function gfs2_sbd_release, which frees sdp.
1137
+ * Subsequent error paths here will call gfs2_sys_fs_del, which also
1138
+ * kobject_put to free sdp.
1139
+ */
1129
1140
if (error )
1130
- goto fail ;
1141
+ return error ;
1142
+
1143
+ gfs2_create_debugfs_file (sdp );
1131
1144
1132
1145
error = gfs2_lm_mount (sdp , silent );
1133
1146
if (error )
1134
- goto fail_sys ;
1147
+ goto fail_debug ;
1135
1148
1136
1149
error = init_locking (sdp , & mount_gh , DO );
1137
1150
if (error )
@@ -1215,12 +1228,12 @@ static int fill_super(struct super_block *sb, struct gfs2_args *args, int silent
1215
1228
fail_lm :
1216
1229
gfs2_gl_hash_clear (sdp );
1217
1230
gfs2_lm_unmount (sdp );
1218
- fail_sys :
1219
- gfs2_sys_fs_del (sdp );
1220
- fail :
1231
+ fail_debug :
1221
1232
gfs2_delete_debugfs_file (sdp );
1222
1233
free_percpu (sdp -> sd_lkstats );
1223
- kfree (sdp );
1234
+ /* gfs2_sys_fs_del must be the last thing we do, since it causes
1235
+ * sysfs to call function gfs2_sbd_release, which frees sdp. */
1236
+ gfs2_sys_fs_del (sdp );
1224
1237
sb -> s_fs_info = NULL ;
1225
1238
return error ;
1226
1239
}
@@ -1390,10 +1403,9 @@ static void gfs2_kill_sb(struct super_block *sb)
1390
1403
sdp -> sd_root_dir = NULL ;
1391
1404
sdp -> sd_master_dir = NULL ;
1392
1405
shrink_dcache_sb (sb );
1393
- kill_block_super (sb );
1394
1406
gfs2_delete_debugfs_file (sdp );
1395
1407
free_percpu (sdp -> sd_lkstats );
1396
- kfree ( sdp );
1408
+ kill_block_super ( sb );
1397
1409
}
1398
1410
1399
1411
struct file_system_type gfs2_fs_type = {
0 commit comments