Skip to content

Commit c659ff3

Browse files
committed
ipmi: Use a temporary BMC for an interface
This is getting ready for the ability to redo the BMC if it's information changes, we need a fallback mechanism. Signed-off-by: Corey Minyard <[email protected]>
1 parent 28f26ac commit c659ff3

File tree

1 file changed

+13
-9
lines changed

1 file changed

+13
-9
lines changed

drivers/char/ipmi/ipmi_msghandler.c

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -418,6 +418,7 @@ struct ipmi_smi {
418418
*/
419419
struct mutex bmc_reg_mutex;
420420

421+
struct bmc_device tmp_bmc;
421422
struct bmc_device *bmc;
422423
bool bmc_registered;
423424
struct list_head bmc_link;
@@ -2839,7 +2840,7 @@ static void ipmi_bmc_unregister(ipmi_smi_t intf)
28392840
mutex_lock(&bmc->dyn_mutex);
28402841
list_del(&intf->bmc_link);
28412842
mutex_unlock(&bmc->dyn_mutex);
2842-
intf->bmc = NULL;
2843+
intf->bmc = &intf->tmp_bmc;
28432844
mutex_lock(&ipmidriver_mutex);
28442845
kref_put(&bmc->usecount, cleanup_bmc_device);
28452846
mutex_unlock(&ipmidriver_mutex);
@@ -2872,7 +2873,6 @@ static int ipmi_bmc_register(ipmi_smi_t intf, int ifnum)
28722873
* otherwise register the new BMC device
28732874
*/
28742875
if (old_bmc) {
2875-
kfree(bmc);
28762876
bmc = old_bmc;
28772877
intf->bmc = old_bmc;
28782878
mutex_lock(&bmc->dyn_mutex);
@@ -2886,6 +2886,14 @@ static int ipmi_bmc_register(ipmi_smi_t intf, int ifnum)
28862886
bmc->id.product_id,
28872887
bmc->id.device_id);
28882888
} else {
2889+
bmc = kzalloc(sizeof(*bmc), GFP_KERNEL);
2890+
if (!bmc) {
2891+
rv = -ENOMEM;
2892+
goto out;
2893+
}
2894+
INIT_LIST_HEAD(&bmc->intfs);
2895+
mutex_init(&bmc->dyn_mutex);
2896+
28892897
bmc->pdev.name = "ipmi_bmc";
28902898

28912899
rv = ida_simple_get(&ipmi_bmc_ida, 0, 0, GFP_KERNEL);
@@ -2968,7 +2976,7 @@ static int ipmi_bmc_register(ipmi_smi_t intf, int ifnum)
29682976
mutex_lock(&bmc->dyn_mutex);
29692977
list_del(&intf->bmc_link);
29702978
mutex_unlock(&bmc->dyn_mutex);
2971-
intf->bmc = NULL;
2979+
intf->bmc = &intf->tmp_bmc;
29722980
mutex_lock(&ipmidriver_mutex);
29732981
kref_put(&bmc->usecount, cleanup_bmc_device);
29742982
mutex_unlock(&ipmidriver_mutex);
@@ -2978,7 +2986,7 @@ static int ipmi_bmc_register(ipmi_smi_t intf, int ifnum)
29782986
mutex_lock(&bmc->dyn_mutex);
29792987
list_del(&intf->bmc_link);
29802988
mutex_unlock(&bmc->dyn_mutex);
2981-
intf->bmc = NULL;
2989+
intf->bmc = &intf->tmp_bmc;
29822990
put_device(&bmc->pdev.dev);
29832991
goto out;
29842992
}
@@ -3204,11 +3212,7 @@ int ipmi_register_smi(const struct ipmi_smi_handlers *handlers,
32043212
if (!intf)
32053213
return -ENOMEM;
32063214

3207-
intf->bmc = kzalloc(sizeof(*intf->bmc), GFP_KERNEL);
3208-
if (!intf->bmc) {
3209-
kfree(intf);
3210-
return -ENOMEM;
3211-
}
3215+
intf->bmc = &intf->tmp_bmc;
32123216
INIT_LIST_HEAD(&intf->bmc->intfs);
32133217
mutex_init(&intf->bmc->dyn_mutex);
32143218
INIT_LIST_HEAD(&intf->bmc_link);

0 commit comments

Comments
 (0)