Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

ipmi: remove open coded version of SMBus block write

The block-write function of the core was not used because there was no
client-struct to use. However, in this case it seems apropriate to use a
temporary client struct. Because we are answering a request we recieved
when being a client ourselves. So, convert the code to use a temporary
client and use the block-write function of the I2C core.

Signed-off-by: Wolfram Sang <wsa+renesas@sang-engineering.com>
Reviewed-by: Asmaa Mnebhi <asmaa@nvidia.com>
Acked-by: Corey Minyard <cminyard@mvista.com>
Message-Id: <20210128085544.7609-1-wsa+renesas@sang-engineering.com>
Signed-off-by: Corey Minyard <cminyard@mvista.com>

authored by

Wolfram Sang and committed by
Corey Minyard
fc26067c 76c057c8

+12 -12
+12 -12
drivers/char/ipmi/ipmb_dev_int.c
··· 137 137 { 138 138 struct ipmb_dev *ipmb_dev = to_ipmb_dev(file); 139 139 u8 rq_sa, netf_rq_lun, msg_len; 140 - union i2c_smbus_data data; 140 + struct i2c_client *temp_client; 141 141 u8 msg[MAX_MSG_LEN]; 142 142 ssize_t ret; 143 143 ··· 160 160 } 161 161 162 162 /* 163 - * subtract rq_sa and netf_rq_lun from the length of the msg passed to 164 - * i2c_smbus_xfer 163 + * subtract rq_sa and netf_rq_lun from the length of the msg. Fill the 164 + * temporary client. Note that its use is an exception for IPMI. 165 165 */ 166 166 msg_len = msg[IPMB_MSG_LEN_IDX] - SMBUS_MSG_HEADER_LENGTH; 167 - if (msg_len > I2C_SMBUS_BLOCK_MAX) 168 - msg_len = I2C_SMBUS_BLOCK_MAX; 167 + temp_client = kmemdup(ipmb_dev->client, sizeof(*temp_client), GFP_KERNEL); 168 + if (!temp_client) 169 + return -ENOMEM; 169 170 170 - data.block[0] = msg_len; 171 - memcpy(&data.block[1], msg + SMBUS_MSG_IDX_OFFSET, msg_len); 172 - ret = i2c_smbus_xfer(ipmb_dev->client->adapter, rq_sa, 173 - ipmb_dev->client->flags, 174 - I2C_SMBUS_WRITE, netf_rq_lun, 175 - I2C_SMBUS_BLOCK_DATA, &data); 171 + temp_client->addr = rq_sa; 176 172 177 - return ret ? : count; 173 + ret = i2c_smbus_write_block_data(temp_client, netf_rq_lun, msg_len, 174 + msg + SMBUS_MSG_IDX_OFFSET); 175 + kfree(temp_client); 176 + 177 + return ret < 0 ? ret : count; 178 178 } 179 179 180 180 static __poll_t ipmb_poll(struct file *file, poll_table *wait)