Skip to content

Commit 2512e40

Browse files
committed
ipmi: Rework SMI registration failure
There were certain situations where ipmi_register_smi() would return a failure, but the interface would still be registered and would need to be unregistered. This is obviously a bad design and resulted in an oops in certain failure cases. If the interface is started up in ipmi_register_smi(), then an error occurs, shut down the interface there so the cleanup can be done properly. Fix the various smi users, too. Signed-off-by: Corey Minyard <cminyard@mvista.com> Reported-by: Justin Ernst <justin.ernst@hpe.com> Tested-by: Justin Ernst <justin.ernst@hpe.com> Cc: Andrew Banman <abanman@hpe.com> Cc: Russ Anderson <russ.anderson@hpe.com> Cc: <stable@vger.kernel.org> # 4.18.x
1 parent cd2315d commit 2512e40

3 files changed

Lines changed: 37 additions & 46 deletions

File tree

‎drivers/char/ipmi/ipmi_msghandler.c‎

Lines changed: 30 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -3381,39 +3381,45 @@ int ipmi_register_smi(const struct ipmi_smi_handlers *handlers,
33813381

33823382
rv = handlers->start_processing(send_info, intf);
33833383
if (rv)
3384-
goto out;
3384+
goto out_err;
33853385

33863386
rv = __bmc_get_device_id(intf, NULL, &id, NULL, NULL, i);
33873387
if (rv) {
33883388
dev_err(si_dev, "Unable to get the device id: %d\n", rv);
3389-
goto out;
3389+
goto out_err_started;
33903390
}
33913391

33923392
mutex_lock(&intf->bmc_reg_mutex);
33933393
rv = __scan_channels(intf, &id);
33943394
mutex_unlock(&intf->bmc_reg_mutex);
3395+
if (rv)
3396+
goto out_err_bmc_reg;
33953397

3396-
out:
3397-
if (rv) {
3398-
ipmi_bmc_unregister(intf);
3399-
list_del_rcu(&intf->link);
3400-
mutex_unlock(&ipmi_interfaces_mutex);
3401-
synchronize_srcu(&ipmi_interfaces_srcu);
3402-
cleanup_srcu_struct(&intf->users_srcu);
3403-
kref_put(&intf->refcount, intf_free);
3404-
} else {
3405-
/*
3406-
* Keep memory order straight for RCU readers. Make
3407-
* sure everything else is committed to memory before
3408-
* setting intf_num to mark the interface valid.
3409-
*/
3410-
smp_wmb();
3411-
intf->intf_num = i;
3412-
mutex_unlock(&ipmi_interfaces_mutex);
3398+
/*
3399+
* Keep memory order straight for RCU readers. Make
3400+
* sure everything else is committed to memory before
3401+
* setting intf_num to mark the interface valid.
3402+
*/
3403+
smp_wmb();
3404+
intf->intf_num = i;
3405+
mutex_unlock(&ipmi_interfaces_mutex);
34133406

3414-
/* After this point the interface is legal to use. */
3415-
call_smi_watchers(i, intf->si_dev);
3416-
}
3407+
/* After this point the interface is legal to use. */
3408+
call_smi_watchers(i, intf->si_dev);
3409+
3410+
return 0;
3411+
3412+
out_err_bmc_reg:
3413+
ipmi_bmc_unregister(intf);
3414+
out_err_started:
3415+
if (intf->handlers->shutdown)
3416+
intf->handlers->shutdown(intf->send_info);
3417+
out_err:
3418+
list_del_rcu(&intf->link);
3419+
mutex_unlock(&ipmi_interfaces_mutex);
3420+
synchronize_srcu(&ipmi_interfaces_srcu);
3421+
cleanup_srcu_struct(&intf->users_srcu);
3422+
kref_put(&intf->refcount, intf_free);
34173423

34183424
return rv;
34193425
}
@@ -3504,7 +3510,8 @@ void ipmi_unregister_smi(struct ipmi_smi *intf)
35043510
}
35053511
srcu_read_unlock(&intf->users_srcu, index);
35063512

3507-
intf->handlers->shutdown(intf->send_info);
3513+
if (intf->handlers->shutdown)
3514+
intf->handlers->shutdown(intf->send_info);
35083515

35093516
cleanup_smi_msgs(intf);
35103517

‎drivers/char/ipmi/ipmi_si_intf.c‎

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2083,18 +2083,9 @@ static int try_smi_init(struct smi_info *new_smi)
20832083
si_to_str[new_smi->io.si_type]);
20842084

20852085
WARN_ON(new_smi->io.dev->init_name != NULL);
2086-
kfree(init_name);
2087-
2088-
return 0;
2089-
2090-
out_err:
2091-
if (new_smi->intf) {
2092-
ipmi_unregister_smi(new_smi->intf);
2093-
new_smi->intf = NULL;
2094-
}
20952086

2087+
out_err:
20962088
kfree(init_name);
2097-
20982089
return rv;
20992090
}
21002091

@@ -2227,6 +2218,8 @@ static void shutdown_smi(void *send_info)
22272218

22282219
kfree(smi_info->si_sm);
22292220
smi_info->si_sm = NULL;
2221+
2222+
smi_info->intf = NULL;
22302223
}
22312224

22322225
/*
@@ -2240,10 +2233,8 @@ static void cleanup_one_si(struct smi_info *smi_info)
22402233

22412234
list_del(&smi_info->link);
22422235

2243-
if (smi_info->intf) {
2236+
if (smi_info->intf)
22442237
ipmi_unregister_smi(smi_info->intf);
2245-
smi_info->intf = NULL;
2246-
}
22472238

22482239
if (smi_info->pdev) {
22492240
if (smi_info->pdev_registered)

‎drivers/char/ipmi/ipmi_ssif.c‎

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1214,18 +1214,11 @@ static void shutdown_ssif(void *send_info)
12141214
complete(&ssif_info->wake_thread);
12151215
kthread_stop(ssif_info->thread);
12161216
}
1217-
1218-
/*
1219-
* No message can be outstanding now, we have removed the
1220-
* upper layer and it permitted us to do so.
1221-
*/
1222-
kfree(ssif_info);
12231217
}
12241218

12251219
static int ssif_remove(struct i2c_client *client)
12261220
{
12271221
struct ssif_info *ssif_info = i2c_get_clientdata(client);
1228-
struct ipmi_smi *intf;
12291222
struct ssif_addr_info *addr_info;
12301223

12311224
if (!ssif_info)
@@ -1235,9 +1228,7 @@ static int ssif_remove(struct i2c_client *client)
12351228
* After this point, we won't deliver anything asychronously
12361229
* to the message handler. We can unregister ourself.
12371230
*/
1238-
intf = ssif_info->intf;
1239-
ssif_info->intf = NULL;
1240-
ipmi_unregister_smi(intf);
1231+
ipmi_unregister_smi(ssif_info->intf);
12411232

12421233
list_for_each_entry(addr_info, &ssif_infos, link) {
12431234
if (addr_info->client == client) {
@@ -1246,6 +1237,8 @@ static int ssif_remove(struct i2c_client *client)
12461237
}
12471238
}
12481239

1240+
kfree(ssif_info);
1241+
12491242
return 0;
12501243
}
12511244

0 commit comments

Comments
 (0)