Skip to content

Commit be2eca9

Browse files
committed
Merge tag 'for-linus-5.5-1' of git://github.com/cminyard/linux-ipmi
Pull IPMI updates from Corey Minyard: "Some small fixes accumulated for IPMI, nothing major" * tag 'for-linus-5.5-1' of git://github.com/cminyard/linux-ipmi: ipmi: fix ipmb_poll()'s return type ipmi: kill off 'timespec' usage again drivers: ipmi: Support for both IPMB Req and Resp ipmi: Fix memory leak in __ipmi_bmc_register ipmi: bt-bmc: use devm_platform_ioremap_resource() to simplify code ipmi: use %*ph to print small buffer ipmi: Don't allow device module unload when in use
2 parents a11b696 + 8e6a5c8 commit be2eca9

File tree

5 files changed

+58
-90
lines changed

5 files changed

+58
-90
lines changed

drivers/char/ipmi/bt-bmc.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -444,15 +444,13 @@ static int bt_bmc_probe(struct platform_device *pdev)
444444

445445
bt_bmc->map = syscon_node_to_regmap(pdev->dev.parent->of_node);
446446
if (IS_ERR(bt_bmc->map)) {
447-
struct resource *res;
448447
void __iomem *base;
449448

450449
/*
451450
* Assume it's not the MFD-based devicetree description, in
452451
* which case generate a regmap ourselves
453452
*/
454-
res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
455-
base = devm_ioremap_resource(&pdev->dev, res);
453+
base = devm_platform_ioremap_resource(pdev, 0);
456454
if (IS_ERR(base))
457455
return PTR_ERR(base);
458456

drivers/char/ipmi/ipmb_dev_int.c

Lines changed: 12 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -133,9 +133,6 @@ static ssize_t ipmb_write(struct file *file, const char __user *buf,
133133
rq_sa = GET_7BIT_ADDR(msg[RQ_SA_8BIT_IDX]);
134134
netf_rq_lun = msg[NETFN_LUN_IDX];
135135

136-
if (!(netf_rq_lun & NETFN_RSP_BIT_MASK))
137-
return -EINVAL;
138-
139136
/*
140137
* subtract rq_sa and netf_rq_lun from the length of the msg passed to
141138
* i2c_smbus_xfer
@@ -154,16 +151,16 @@ static ssize_t ipmb_write(struct file *file, const char __user *buf,
154151
return ret ? : count;
155152
}
156153

157-
static unsigned int ipmb_poll(struct file *file, poll_table *wait)
154+
static __poll_t ipmb_poll(struct file *file, poll_table *wait)
158155
{
159156
struct ipmb_dev *ipmb_dev = to_ipmb_dev(file);
160-
unsigned int mask = POLLOUT;
157+
__poll_t mask = EPOLLOUT;
161158

162159
mutex_lock(&ipmb_dev->file_mutex);
163160
poll_wait(file, &ipmb_dev->wait_queue, wait);
164161

165162
if (atomic_read(&ipmb_dev->request_queue_len))
166-
mask |= POLLIN;
163+
mask |= EPOLLIN;
167164
mutex_unlock(&ipmb_dev->file_mutex);
168165

169166
return mask;
@@ -203,25 +200,16 @@ static u8 ipmb_verify_checksum1(struct ipmb_dev *ipmb_dev, u8 rs_sa)
203200
ipmb_dev->request.checksum1);
204201
}
205202

206-
static bool is_ipmb_request(struct ipmb_dev *ipmb_dev, u8 rs_sa)
203+
/*
204+
* Verify if message has proper ipmb header with minimum length
205+
* and correct checksum byte.
206+
*/
207+
static bool is_ipmb_msg(struct ipmb_dev *ipmb_dev, u8 rs_sa)
207208
{
208-
if (ipmb_dev->msg_idx >= IPMB_REQUEST_LEN_MIN) {
209-
if (ipmb_verify_checksum1(ipmb_dev, rs_sa))
210-
return false;
209+
if ((ipmb_dev->msg_idx >= IPMB_REQUEST_LEN_MIN) &&
210+
(!ipmb_verify_checksum1(ipmb_dev, rs_sa)))
211+
return true;
211212

212-
/*
213-
* Check whether this is an IPMB request or
214-
* response.
215-
* The 6 MSB of netfn_rs_lun are dedicated to the netfn
216-
* while the remaining bits are dedicated to the lun.
217-
* If the LSB of the netfn is cleared, it is associated
218-
* with an IPMB request.
219-
* If the LSB of the netfn is set, it is associated with
220-
* an IPMB response.
221-
*/
222-
if (!(ipmb_dev->request.netfn_rs_lun & NETFN_RSP_BIT_MASK))
223-
return true;
224-
}
225213
return false;
226214
}
227215

@@ -273,8 +261,7 @@ static int ipmb_slave_cb(struct i2c_client *client,
273261

274262
case I2C_SLAVE_STOP:
275263
ipmb_dev->request.len = ipmb_dev->msg_idx;
276-
277-
if (is_ipmb_request(ipmb_dev, GET_8BIT_ADDR(client->addr)))
264+
if (is_ipmb_msg(ipmb_dev, GET_8BIT_ADDR(client->addr)))
278265
ipmb_handle_request(ipmb_dev);
279266
break;
280267

drivers/char/ipmi/ipmi_msghandler.c

Lines changed: 24 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -44,25 +44,6 @@ static void need_waiter(struct ipmi_smi *intf);
4444
static int handle_one_recv_msg(struct ipmi_smi *intf,
4545
struct ipmi_smi_msg *msg);
4646

47-
#ifdef DEBUG
48-
static void ipmi_debug_msg(const char *title, unsigned char *data,
49-
unsigned int len)
50-
{
51-
int i, pos;
52-
char buf[100];
53-
54-
pos = snprintf(buf, sizeof(buf), "%s: ", title);
55-
for (i = 0; i < len; i++)
56-
pos += snprintf(buf + pos, sizeof(buf) - pos,
57-
" %2.2x", data[i]);
58-
pr_debug("%s\n", buf);
59-
}
60-
#else
61-
static void ipmi_debug_msg(const char *title, unsigned char *data,
62-
unsigned int len)
63-
{ }
64-
#endif
65-
6647
static bool initialized;
6748
static bool drvregistered;
6849

@@ -448,6 +429,8 @@ enum ipmi_stat_indexes {
448429

449430
#define IPMI_IPMB_NUM_SEQ 64
450431
struct ipmi_smi {
432+
struct module *owner;
433+
451434
/* What interface number are we? */
452435
int intf_num;
453436

@@ -1220,6 +1203,11 @@ int ipmi_create_user(unsigned int if_num,
12201203
if (rv)
12211204
goto out_kfree;
12221205

1206+
if (!try_module_get(intf->owner)) {
1207+
rv = -ENODEV;
1208+
goto out_kfree;
1209+
}
1210+
12231211
/* Note that each existing user holds a refcount to the interface. */
12241212
kref_get(&intf->refcount);
12251213

@@ -1349,6 +1337,7 @@ static void _ipmi_destroy_user(struct ipmi_user *user)
13491337
}
13501338

13511339
kref_put(&intf->refcount, intf_free);
1340+
module_put(intf->owner);
13521341
}
13531342

13541343
int ipmi_destroy_user(struct ipmi_user *user)
@@ -2267,7 +2256,7 @@ static int i_ipmi_request(struct ipmi_user *user,
22672256
ipmi_free_smi_msg(smi_msg);
22682257
ipmi_free_recv_msg(recv_msg);
22692258
} else {
2270-
ipmi_debug_msg("Send", smi_msg->data, smi_msg->data_size);
2259+
pr_debug("Send: %*ph\n", smi_msg->data_size, smi_msg->data);
22712260

22722261
smi_send(intf, intf->handlers, smi_msg, priority);
22732262
}
@@ -2459,7 +2448,7 @@ static int __get_device_id(struct ipmi_smi *intf, struct bmc_device *bmc)
24592448
* been recently fetched, this will just use the cached data. Otherwise
24602449
* it will run a new fetch.
24612450
*
2462-
* Except for the first time this is called (in ipmi_register_smi()),
2451+
* Except for the first time this is called (in ipmi_add_smi()),
24632452
* this will always return good data;
24642453
*/
24652454
static int __bmc_get_device_id(struct ipmi_smi *intf, struct bmc_device *bmc,
@@ -3031,8 +3020,11 @@ static int __ipmi_bmc_register(struct ipmi_smi *intf,
30313020
bmc->pdev.name = "ipmi_bmc";
30323021

30333022
rv = ida_simple_get(&ipmi_bmc_ida, 0, 0, GFP_KERNEL);
3034-
if (rv < 0)
3023+
if (rv < 0) {
3024+
kfree(bmc);
30353025
goto out;
3026+
}
3027+
30363028
bmc->pdev.dev.driver = &ipmidriver.driver;
30373029
bmc->pdev.id = rv;
30383030
bmc->pdev.dev.release = release_bmc_device;
@@ -3377,10 +3369,11 @@ static void redo_bmc_reg(struct work_struct *work)
33773369
kref_put(&intf->refcount, intf_free);
33783370
}
33793371

3380-
int ipmi_register_smi(const struct ipmi_smi_handlers *handlers,
3381-
void *send_info,
3382-
struct device *si_dev,
3383-
unsigned char slave_addr)
3372+
int ipmi_add_smi(struct module *owner,
3373+
const struct ipmi_smi_handlers *handlers,
3374+
void *send_info,
3375+
struct device *si_dev,
3376+
unsigned char slave_addr)
33843377
{
33853378
int i, j;
33863379
int rv;
@@ -3406,7 +3399,7 @@ int ipmi_register_smi(const struct ipmi_smi_handlers *handlers,
34063399
return rv;
34073400
}
34083401

3409-
3402+
intf->owner = owner;
34103403
intf->bmc = &intf->tmp_bmc;
34113404
INIT_LIST_HEAD(&intf->bmc->intfs);
34123405
mutex_init(&intf->bmc->dyn_mutex);
@@ -3514,7 +3507,7 @@ int ipmi_register_smi(const struct ipmi_smi_handlers *handlers,
35143507

35153508
return rv;
35163509
}
3517-
EXPORT_SYMBOL(ipmi_register_smi);
3510+
EXPORT_SYMBOL(ipmi_add_smi);
35183511

35193512
static void deliver_smi_err_response(struct ipmi_smi *intf,
35203513
struct ipmi_smi_msg *msg,
@@ -3730,7 +3723,7 @@ static int handle_ipmb_get_msg_cmd(struct ipmi_smi *intf,
37303723
msg->data[10] = ipmb_checksum(&msg->data[6], 4);
37313724
msg->data_size = 11;
37323725

3733-
ipmi_debug_msg("Invalid command:", msg->data, msg->data_size);
3726+
pr_debug("Invalid command: %*ph\n", msg->data_size, msg->data);
37343727

37353728
rcu_read_lock();
37363729
if (!intf->in_shutdown) {
@@ -4217,7 +4210,7 @@ static int handle_one_recv_msg(struct ipmi_smi *intf,
42174210
int requeue;
42184211
int chan;
42194212

4220-
ipmi_debug_msg("Recv:", msg->rsp, msg->rsp_size);
4213+
pr_debug("Recv: %*ph\n", msg->rsp_size, msg->rsp);
42214214

42224215
if ((msg->data_size >= 2)
42234216
&& (msg->data[0] == (IPMI_NETFN_APP_REQUEST << 2))
@@ -4576,7 +4569,7 @@ smi_from_recv_msg(struct ipmi_smi *intf, struct ipmi_recv_msg *recv_msg,
45764569
smi_msg->data_size = recv_msg->msg.data_len;
45774570
smi_msg->msgid = STORE_SEQ_IN_MSGID(seq, seqid);
45784571

4579-
ipmi_debug_msg("Resend: ", smi_msg->data, smi_msg->data_size);
4572+
pr_debug("Resend: %*ph\n", smi_msg->data_size, smi_msg->data);
45804573

45814574
return smi_msg;
45824575
}

drivers/char/ipmi/ipmi_si_intf.c

Lines changed: 13 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -265,10 +265,10 @@ static void cleanup_ipmi_si(void);
265265
#ifdef DEBUG_TIMING
266266
void debug_timestamp(char *msg)
267267
{
268-
struct timespec t;
268+
struct timespec64 t;
269269

270-
ktime_get_ts(&t);
271-
pr_debug("**%s: %ld.%9.9ld\n", msg, (long) t.tv_sec, t.tv_nsec);
270+
ktime_get_ts64(&t);
271+
pr_debug("**%s: %lld.%9.9ld\n", msg, t.tv_sec, t.tv_nsec);
272272
}
273273
#else
274274
#define debug_timestamp(x)
@@ -935,38 +935,25 @@ static void set_run_to_completion(void *send_info, bool i_run_to_completion)
935935
}
936936

937937
/*
938-
* Use -1 in the nsec value of the busy waiting timespec to tell that
939-
* we are spinning in kipmid looking for something and not delaying
940-
* between checks
938+
* Use -1 as a special constant to tell that we are spinning in kipmid
939+
* looking for something and not delaying between checks
941940
*/
942-
static inline void ipmi_si_set_not_busy(struct timespec *ts)
943-
{
944-
ts->tv_nsec = -1;
945-
}
946-
static inline int ipmi_si_is_busy(struct timespec *ts)
947-
{
948-
return ts->tv_nsec != -1;
949-
}
950-
941+
#define IPMI_TIME_NOT_BUSY ns_to_ktime(-1ull)
951942
static inline bool ipmi_thread_busy_wait(enum si_sm_result smi_result,
952943
const struct smi_info *smi_info,
953-
struct timespec *busy_until)
944+
ktime_t *busy_until)
954945
{
955946
unsigned int max_busy_us = 0;
956947

957948
if (smi_info->si_num < num_max_busy_us)
958949
max_busy_us = kipmid_max_busy_us[smi_info->si_num];
959950
if (max_busy_us == 0 || smi_result != SI_SM_CALL_WITH_DELAY)
960-
ipmi_si_set_not_busy(busy_until);
961-
else if (!ipmi_si_is_busy(busy_until)) {
962-
ktime_get_ts(busy_until);
963-
timespec_add_ns(busy_until, max_busy_us * NSEC_PER_USEC);
951+
*busy_until = IPMI_TIME_NOT_BUSY;
952+
else if (*busy_until == IPMI_TIME_NOT_BUSY) {
953+
*busy_until = ktime_get() + max_busy_us * NSEC_PER_USEC;
964954
} else {
965-
struct timespec now;
966-
967-
ktime_get_ts(&now);
968-
if (unlikely(timespec_compare(&now, busy_until) > 0)) {
969-
ipmi_si_set_not_busy(busy_until);
955+
if (unlikely(ktime_get() > *busy_until)) {
956+
*busy_until = IPMI_TIME_NOT_BUSY;
970957
return false;
971958
}
972959
}
@@ -988,9 +975,8 @@ static int ipmi_thread(void *data)
988975
struct smi_info *smi_info = data;
989976
unsigned long flags;
990977
enum si_sm_result smi_result;
991-
struct timespec busy_until = { 0, 0 };
978+
ktime_t busy_until = IPMI_TIME_NOT_BUSY;
992979

993-
ipmi_si_set_not_busy(&busy_until);
994980
set_user_nice(current, MAX_NICE);
995981
while (!kthread_should_stop()) {
996982
int busy_wait;

include/linux/ipmi_smi.h

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -224,10 +224,14 @@ static inline int ipmi_demangle_device_id(uint8_t netfn, uint8_t cmd,
224224
* is called, and the lower layer must get the interface from that
225225
* call.
226226
*/
227-
int ipmi_register_smi(const struct ipmi_smi_handlers *handlers,
228-
void *send_info,
229-
struct device *dev,
230-
unsigned char slave_addr);
227+
int ipmi_add_smi(struct module *owner,
228+
const struct ipmi_smi_handlers *handlers,
229+
void *send_info,
230+
struct device *dev,
231+
unsigned char slave_addr);
232+
233+
#define ipmi_register_smi(handlers, send_info, dev, slave_addr) \
234+
ipmi_add_smi(THIS_MODULE, handlers, send_info, dev, slave_addr)
231235

232236
/*
233237
* Remove a low-level interface from the IPMI driver. This will

0 commit comments

Comments
 (0)