Skip to content

Commit ada018b

Browse files
KAGA-KOKOsuryasaimadhu
authored andcommitted
x86/mce/amd: Do proper cleanup on error paths
Drop kobject reference counts properly on error in the banks and blocks allocation functions. [ bp: Write commit message. ] Signed-off-by: Thomas Gleixner <[email protected]> Signed-off-by: Borislav Petkov <[email protected]> Link: https://lkml.kernel.org/r/[email protected]
1 parent 8f3d9f3 commit ada018b

File tree

1 file changed

+8
-7
lines changed
  • arch/x86/kernel/cpu/mce

1 file changed

+8
-7
lines changed

arch/x86/kernel/cpu/mce/amd.c

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1267,13 +1267,12 @@ static int allocate_threshold_blocks(unsigned int cpu, struct threshold_bank *tb
12671267
if (b)
12681268
kobject_uevent(&b->kobj, KOBJ_ADD);
12691269

1270-
return err;
1270+
return 0;
12711271

12721272
out_free:
12731273
if (b) {
1274-
kobject_put(&b->kobj);
12751274
list_del(&b->miscj);
1276-
kfree(b);
1275+
kobject_put(&b->kobj);
12771276
}
12781277
return err;
12791278
}
@@ -1339,6 +1338,7 @@ static int threshold_create_bank(unsigned int cpu, unsigned int bank)
13391338
goto out;
13401339
}
13411340

1341+
/* Associate the bank with the per-CPU MCE device */
13421342
b->kobj = kobject_create_and_add(name, &dev->kobj);
13431343
if (!b->kobj) {
13441344
err = -EINVAL;
@@ -1357,16 +1357,17 @@ static int threshold_create_bank(unsigned int cpu, unsigned int bank)
13571357

13581358
err = allocate_threshold_blocks(cpu, b, bank, 0, msr_ops.misc(bank));
13591359
if (err)
1360-
goto out_free;
1360+
goto out_kobj;
13611361

13621362
per_cpu(threshold_banks, cpu)[bank] = b;
13631363

13641364
return 0;
13651365

1366-
out_free:
1366+
out_kobj:
1367+
kobject_put(b->kobj);
1368+
out_free:
13671369
kfree(b);
1368-
1369-
out:
1370+
out:
13701371
return err;
13711372
}
13721373

0 commit comments

Comments
 (0)