Skip to content

Commit d3bd597

Browse files
committed
Merge tag 'for-linus-4.19' of git://github.com/cminyard/linux-ipmi
Pull IPMI bugfixes from Corey Minyard: "A few fixes that came around or after the merge window, except for commit cd2315d ("ipmi: kcs_bmc: don't change device name") which is for a driver that very few people use, and those people need the change" * tag 'for-linus-4.19' of git://github.com/cminyard/linux-ipmi: ipmi: Fix NULL pointer dereference in ssif_probe ipmi: Fix I2C client removal in the SSIF driver ipmi: Move BT capabilities detection to the detect call ipmi: Rework SMI registration failure ipmi: kcs_bmc: don't change device name
2 parents 7428b2e + a8627cd commit d3bd597

File tree

5 files changed

+97
-104
lines changed

5 files changed

+97
-104
lines changed

drivers/char/ipmi/ipmi_bt_sm.c

Lines changed: 48 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,6 @@ enum bt_states {
5959
BT_STATE_RESET3,
6060
BT_STATE_RESTART,
6161
BT_STATE_PRINTME,
62-
BT_STATE_CAPABILITIES_BEGIN,
63-
BT_STATE_CAPABILITIES_END,
6462
BT_STATE_LONG_BUSY /* BT doesn't get hosed :-) */
6563
};
6664

@@ -86,7 +84,6 @@ struct si_sm_data {
8684
int error_retries; /* end of "common" fields */
8785
int nonzero_status; /* hung BMCs stay all 0 */
8886
enum bt_states complete; /* to divert the state machine */
89-
int BT_CAP_outreqs;
9087
long BT_CAP_req2rsp;
9188
int BT_CAP_retries; /* Recommended retries */
9289
};
@@ -137,8 +134,6 @@ static char *state2txt(unsigned char state)
137134
case BT_STATE_RESET3: return("RESET3");
138135
case BT_STATE_RESTART: return("RESTART");
139136
case BT_STATE_LONG_BUSY: return("LONG_BUSY");
140-
case BT_STATE_CAPABILITIES_BEGIN: return("CAP_BEGIN");
141-
case BT_STATE_CAPABILITIES_END: return("CAP_END");
142137
}
143138
return("BAD STATE");
144139
}
@@ -185,7 +180,6 @@ static unsigned int bt_init_data(struct si_sm_data *bt, struct si_sm_io *io)
185180
bt->complete = BT_STATE_IDLE; /* end here */
186181
bt->BT_CAP_req2rsp = BT_NORMAL_TIMEOUT * USEC_PER_SEC;
187182
bt->BT_CAP_retries = BT_NORMAL_RETRY_LIMIT;
188-
/* BT_CAP_outreqs == zero is a flag to read BT Capabilities */
189183
return 3; /* We claim 3 bytes of space; ought to check SPMI table */
190184
}
191185

@@ -451,7 +445,7 @@ static enum si_sm_result error_recovery(struct si_sm_data *bt,
451445

452446
static enum si_sm_result bt_event(struct si_sm_data *bt, long time)
453447
{
454-
unsigned char status, BT_CAP[8];
448+
unsigned char status;
455449
static enum bt_states last_printed = BT_STATE_PRINTME;
456450
int i;
457451

@@ -504,12 +498,6 @@ static enum si_sm_result bt_event(struct si_sm_data *bt, long time)
504498
if (status & BT_H_BUSY) /* clear a leftover H_BUSY */
505499
BT_CONTROL(BT_H_BUSY);
506500

507-
bt->timeout = bt->BT_CAP_req2rsp;
508-
509-
/* Read BT capabilities if it hasn't been done yet */
510-
if (!bt->BT_CAP_outreqs)
511-
BT_STATE_CHANGE(BT_STATE_CAPABILITIES_BEGIN,
512-
SI_SM_CALL_WITHOUT_DELAY);
513501
BT_SI_SM_RETURN(SI_SM_IDLE);
514502

515503
case BT_STATE_XACTION_START:
@@ -614,37 +602,6 @@ static enum si_sm_result bt_event(struct si_sm_data *bt, long time)
614602
BT_STATE_CHANGE(BT_STATE_XACTION_START,
615603
SI_SM_CALL_WITH_DELAY);
616604

617-
/*
618-
* Get BT Capabilities, using timing of upper level state machine.
619-
* Set outreqs to prevent infinite loop on timeout.
620-
*/
621-
case BT_STATE_CAPABILITIES_BEGIN:
622-
bt->BT_CAP_outreqs = 1;
623-
{
624-
unsigned char GetBT_CAP[] = { 0x18, 0x36 };
625-
bt->state = BT_STATE_IDLE;
626-
bt_start_transaction(bt, GetBT_CAP, sizeof(GetBT_CAP));
627-
}
628-
bt->complete = BT_STATE_CAPABILITIES_END;
629-
BT_STATE_CHANGE(BT_STATE_XACTION_START,
630-
SI_SM_CALL_WITH_DELAY);
631-
632-
case BT_STATE_CAPABILITIES_END:
633-
i = bt_get_result(bt, BT_CAP, sizeof(BT_CAP));
634-
bt_init_data(bt, bt->io);
635-
if ((i == 8) && !BT_CAP[2]) {
636-
bt->BT_CAP_outreqs = BT_CAP[3];
637-
bt->BT_CAP_req2rsp = BT_CAP[6] * USEC_PER_SEC;
638-
bt->BT_CAP_retries = BT_CAP[7];
639-
} else
640-
printk(KERN_WARNING "IPMI BT: using default values\n");
641-
if (!bt->BT_CAP_outreqs)
642-
bt->BT_CAP_outreqs = 1;
643-
printk(KERN_WARNING "IPMI BT: req2rsp=%ld secs retries=%d\n",
644-
bt->BT_CAP_req2rsp / USEC_PER_SEC, bt->BT_CAP_retries);
645-
bt->timeout = bt->BT_CAP_req2rsp;
646-
return SI_SM_CALL_WITHOUT_DELAY;
647-
648605
default: /* should never occur */
649606
return error_recovery(bt,
650607
status,
@@ -655,6 +612,11 @@ static enum si_sm_result bt_event(struct si_sm_data *bt, long time)
655612

656613
static int bt_detect(struct si_sm_data *bt)
657614
{
615+
unsigned char GetBT_CAP[] = { 0x18, 0x36 };
616+
unsigned char BT_CAP[8];
617+
enum si_sm_result smi_result;
618+
int rv;
619+
658620
/*
659621
* It's impossible for the BT status and interrupt registers to be
660622
* all 1's, (assuming a properly functioning, self-initialized BMC)
@@ -665,6 +627,48 @@ static int bt_detect(struct si_sm_data *bt)
665627
if ((BT_STATUS == 0xFF) && (BT_INTMASK_R == 0xFF))
666628
return 1;
667629
reset_flags(bt);
630+
631+
/*
632+
* Try getting the BT capabilities here.
633+
*/
634+
rv = bt_start_transaction(bt, GetBT_CAP, sizeof(GetBT_CAP));
635+
if (rv) {
636+
dev_warn(bt->io->dev,
637+
"Can't start capabilities transaction: %d\n", rv);
638+
goto out_no_bt_cap;
639+
}
640+
641+
smi_result = SI_SM_CALL_WITHOUT_DELAY;
642+
for (;;) {
643+
if (smi_result == SI_SM_CALL_WITH_DELAY ||
644+
smi_result == SI_SM_CALL_WITH_TICK_DELAY) {
645+
schedule_timeout_uninterruptible(1);
646+
smi_result = bt_event(bt, jiffies_to_usecs(1));
647+
} else if (smi_result == SI_SM_CALL_WITHOUT_DELAY) {
648+
smi_result = bt_event(bt, 0);
649+
} else
650+
break;
651+
}
652+
653+
rv = bt_get_result(bt, BT_CAP, sizeof(BT_CAP));
654+
bt_init_data(bt, bt->io);
655+
if (rv < 8) {
656+
dev_warn(bt->io->dev, "bt cap response too short: %d\n", rv);
657+
goto out_no_bt_cap;
658+
}
659+
660+
if (BT_CAP[2]) {
661+
dev_warn(bt->io->dev, "Error fetching bt cap: %x\n", BT_CAP[2]);
662+
out_no_bt_cap:
663+
dev_warn(bt->io->dev, "using default values\n");
664+
} else {
665+
bt->BT_CAP_req2rsp = BT_CAP[6] * USEC_PER_SEC;
666+
bt->BT_CAP_retries = BT_CAP[7];
667+
}
668+
669+
dev_info(bt->io->dev, "req2rsp=%ld secs retries=%d\n",
670+
bt->BT_CAP_req2rsp / USEC_PER_SEC, bt->BT_CAP_retries);
671+
668672
return 0;
669673
}
670674

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: 11 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,8 @@ struct ssif_addr_info {
181181
struct device *dev;
182182
struct i2c_client *client;
183183

184+
struct i2c_client *added_client;
185+
184186
struct mutex clients_mutex;
185187
struct list_head clients;
186188

@@ -1214,18 +1216,11 @@ static void shutdown_ssif(void *send_info)
12141216
complete(&ssif_info->wake_thread);
12151217
kthread_stop(ssif_info->thread);
12161218
}
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);
12231219
}
12241220

12251221
static int ssif_remove(struct i2c_client *client)
12261222
{
12271223
struct ssif_info *ssif_info = i2c_get_clientdata(client);
1228-
struct ipmi_smi *intf;
12291224
struct ssif_addr_info *addr_info;
12301225

12311226
if (!ssif_info)
@@ -1235,9 +1230,7 @@ static int ssif_remove(struct i2c_client *client)
12351230
* After this point, we won't deliver anything asychronously
12361231
* to the message handler. We can unregister ourself.
12371232
*/
1238-
intf = ssif_info->intf;
1239-
ssif_info->intf = NULL;
1240-
ipmi_unregister_smi(intf);
1233+
ipmi_unregister_smi(ssif_info->intf);
12411234

12421235
list_for_each_entry(addr_info, &ssif_infos, link) {
12431236
if (addr_info->client == client) {
@@ -1246,6 +1239,8 @@ static int ssif_remove(struct i2c_client *client)
12461239
}
12471240
}
12481241

1242+
kfree(ssif_info);
1243+
12491244
return 0;
12501245
}
12511246

@@ -1648,15 +1643,9 @@ static int ssif_probe(struct i2c_client *client, const struct i2c_device_id *id)
16481643

16491644
out:
16501645
if (rv) {
1651-
/*
1652-
* Note that if addr_info->client is assigned, we
1653-
* leave it. The i2c client hangs around even if we
1654-
* return a failure here, and the failure here is not
1655-
* propagated back to the i2c code. This seems to be
1656-
* design intent, strange as it may be. But if we
1657-
* don't leave it, ssif_platform_remove will not remove
1658-
* the client like it should.
1659-
*/
1646+
if (addr_info)
1647+
addr_info->client = NULL;
1648+
16601649
dev_err(&client->dev, "Unable to start IPMI SSIF: %d\n", rv);
16611650
kfree(ssif_info);
16621651
}
@@ -1676,7 +1665,8 @@ static int ssif_adapter_handler(struct device *adev, void *opaque)
16761665
if (adev->type != &i2c_adapter_type)
16771666
return 0;
16781667

1679-
i2c_new_device(to_i2c_adapter(adev), &addr_info->binfo);
1668+
addr_info->added_client = i2c_new_device(to_i2c_adapter(adev),
1669+
&addr_info->binfo);
16801670

16811671
if (!addr_info->adapter_name)
16821672
return 1; /* Only try the first I2C adapter by default. */
@@ -1849,7 +1839,7 @@ static int ssif_platform_remove(struct platform_device *dev)
18491839
return 0;
18501840

18511841
mutex_lock(&ssif_infos_mutex);
1852-
i2c_unregister_device(addr_info->client);
1842+
i2c_unregister_device(addr_info->added_client);
18531843

18541844
list_del(&addr_info->link);
18551845
kfree(addr_info);

drivers/char/ipmi/kcs_bmc.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616

1717
#include "kcs_bmc.h"
1818

19+
#define DEVICE_NAME "ipmi-kcs"
20+
1921
#define KCS_MSG_BUFSIZ 1000
2022

2123
#define KCS_ZERO_DATA 0
@@ -429,8 +431,6 @@ struct kcs_bmc *kcs_bmc_alloc(struct device *dev, int sizeof_priv, u32 channel)
429431
if (!kcs_bmc)
430432
return NULL;
431433

432-
dev_set_name(dev, "ipmi-kcs%u", channel);
433-
434434
spin_lock_init(&kcs_bmc->lock);
435435
kcs_bmc->channel = channel;
436436

@@ -444,7 +444,8 @@ struct kcs_bmc *kcs_bmc_alloc(struct device *dev, int sizeof_priv, u32 channel)
444444
return NULL;
445445

446446
kcs_bmc->miscdev.minor = MISC_DYNAMIC_MINOR;
447-
kcs_bmc->miscdev.name = dev_name(dev);
447+
kcs_bmc->miscdev.name = devm_kasprintf(dev, GFP_KERNEL, "%s%u",
448+
DEVICE_NAME, channel);
448449
kcs_bmc->miscdev.fops = &kcs_bmc_fops;
449450

450451
return kcs_bmc;

0 commit comments

Comments
 (0)