Skip to content

Commit ab02b61

Browse files
committed
Merge tag 'for-linus-5.6-1' of https://github.com/cminyard/linux-ipmi
Pull IPMI update from Corey Minyard: "Minor bug fixes for IPMI I know this is late; I've been travelling and, well, I've been distracted. This is just a few bug fixes and adding i2c support to the IPMB driver, which is something I wanted from the beginning for it" * tag 'for-linus-5.6-1' of https://github.com/cminyard/linux-ipmi: drivers: ipmi: fix off-by-one bounds check that leads to a out-of-bounds write ipmi:ssif: Handle a possible NULL pointer reference drivers: ipmi: Modify max length of IPMB packet drivers: ipmi: Support raw i2c packet in IPMB
2 parents 44024ad + e0354d1 commit ab02b61

File tree

3 files changed

+42
-5
lines changed

3 files changed

+42
-5
lines changed

Documentation/driver-api/ipmb.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,13 @@ b) Example for device tree::
7171
ipmb@10 {
7272
compatible = "ipmb-dev";
7373
reg = <0x10>;
74+
i2c-protocol;
7475
};
7576
};
7677

78+
If xmit of data to be done using raw i2c block vs smbus
79+
then "i2c-protocol" needs to be defined as above.
80+
7781
2) Manually from Linux::
7882

7983
modprobe ipmb-dev-int

drivers/char/ipmi/ipmb_dev_int.c

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
#include <linux/spinlock.h>
2020
#include <linux/wait.h>
2121

22-
#define MAX_MSG_LEN 128
22+
#define MAX_MSG_LEN 240
2323
#define IPMB_REQUEST_LEN_MIN 7
2424
#define NETFN_RSP_BIT_MASK 0x4
2525
#define REQUEST_QUEUE_MAX_LEN 256
@@ -63,6 +63,7 @@ struct ipmb_dev {
6363
spinlock_t lock;
6464
wait_queue_head_t wait_queue;
6565
struct mutex file_mutex;
66+
bool is_i2c_protocol;
6667
};
6768

6869
static inline struct ipmb_dev *to_ipmb_dev(struct file *file)
@@ -112,6 +113,25 @@ static ssize_t ipmb_read(struct file *file, char __user *buf, size_t count,
112113
return ret < 0 ? ret : count;
113114
}
114115

116+
static int ipmb_i2c_write(struct i2c_client *client, u8 *msg, u8 addr)
117+
{
118+
struct i2c_msg i2c_msg;
119+
120+
/*
121+
* subtract 1 byte (rq_sa) from the length of the msg passed to
122+
* raw i2c_transfer
123+
*/
124+
i2c_msg.len = msg[IPMB_MSG_LEN_IDX] - 1;
125+
126+
/* Assign message to buffer except first 2 bytes (length and address) */
127+
i2c_msg.buf = msg + 2;
128+
129+
i2c_msg.addr = addr;
130+
i2c_msg.flags = client->flags & I2C_CLIENT_PEC;
131+
132+
return i2c_transfer(client->adapter, &i2c_msg, 1);
133+
}
134+
115135
static ssize_t ipmb_write(struct file *file, const char __user *buf,
116136
size_t count, loff_t *ppos)
117137
{
@@ -133,6 +153,12 @@ static ssize_t ipmb_write(struct file *file, const char __user *buf,
133153
rq_sa = GET_7BIT_ADDR(msg[RQ_SA_8BIT_IDX]);
134154
netf_rq_lun = msg[NETFN_LUN_IDX];
135155

156+
/* Check i2c block transfer vs smbus */
157+
if (ipmb_dev->is_i2c_protocol) {
158+
ret = ipmb_i2c_write(ipmb_dev->client, msg, rq_sa);
159+
return (ret == 1) ? count : ret;
160+
}
161+
136162
/*
137163
* subtract rq_sa and netf_rq_lun from the length of the msg passed to
138164
* i2c_smbus_xfer
@@ -253,7 +279,7 @@ static int ipmb_slave_cb(struct i2c_client *client,
253279
break;
254280

255281
case I2C_SLAVE_WRITE_RECEIVED:
256-
if (ipmb_dev->msg_idx >= sizeof(struct ipmb_msg))
282+
if (ipmb_dev->msg_idx >= sizeof(struct ipmb_msg) - 1)
257283
break;
258284

259285
buf[++ipmb_dev->msg_idx] = *val;
@@ -302,6 +328,9 @@ static int ipmb_probe(struct i2c_client *client,
302328
if (ret)
303329
return ret;
304330

331+
ipmb_dev->is_i2c_protocol
332+
= device_property_read_bool(&client->dev, "i2c-protocol");
333+
305334
ipmb_dev->client = client;
306335
i2c_set_clientdata(client, ipmb_dev);
307336
ret = i2c_slave_register(client, ipmb_slave_cb);

drivers/char/ipmi/ipmi_ssif.c

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -775,10 +775,14 @@ static void msg_done_handler(struct ssif_info *ssif_info, int result,
775775
flags = ipmi_ssif_lock_cond(ssif_info, &oflags);
776776
msg = ssif_info->curr_msg;
777777
if (msg) {
778+
if (data) {
779+
if (len > IPMI_MAX_MSG_LENGTH)
780+
len = IPMI_MAX_MSG_LENGTH;
781+
memcpy(msg->rsp, data, len);
782+
} else {
783+
len = 0;
784+
}
778785
msg->rsp_size = len;
779-
if (msg->rsp_size > IPMI_MAX_MSG_LENGTH)
780-
msg->rsp_size = IPMI_MAX_MSG_LENGTH;
781-
memcpy(msg->rsp, data, msg->rsp_size);
782786
ssif_info->curr_msg = NULL;
783787
}
784788

0 commit comments

Comments
 (0)