diff options
Diffstat (limited to 'drivers/i2c')
-rw-r--r-- | drivers/i2c/busses/i2c-cros-ec-tunnel.c | 51 |
1 files changed, 10 insertions, 41 deletions
diff --git a/drivers/i2c/busses/i2c-cros-ec-tunnel.c b/drivers/i2c/busses/i2c-cros-ec-tunnel.c index 875c22ae5400..fa8dedd8c3a2 100644 --- a/drivers/i2c/busses/i2c-cros-ec-tunnel.c +++ b/drivers/i2c/busses/i2c-cros-ec-tunnel.c | |||
@@ -182,72 +182,41 @@ static int ec_i2c_xfer(struct i2c_adapter *adap, struct i2c_msg i2c_msgs[], | |||
182 | const u16 bus_num = bus->remote_bus; | 182 | const u16 bus_num = bus->remote_bus; |
183 | int request_len; | 183 | int request_len; |
184 | int response_len; | 184 | int response_len; |
185 | u8 *request = NULL; | ||
186 | u8 *response = NULL; | ||
187 | int result; | 185 | int result; |
188 | struct cros_ec_command msg; | 186 | struct cros_ec_command msg = { }; |
189 | 187 | ||
190 | request_len = ec_i2c_count_message(i2c_msgs, num); | 188 | request_len = ec_i2c_count_message(i2c_msgs, num); |
191 | if (request_len < 0) { | 189 | if (request_len < 0) { |
192 | dev_warn(dev, "Error constructing message %d\n", request_len); | 190 | dev_warn(dev, "Error constructing message %d\n", request_len); |
193 | result = request_len; | 191 | return request_len; |
194 | goto exit; | ||
195 | } | 192 | } |
193 | |||
196 | response_len = ec_i2c_count_response(i2c_msgs, num); | 194 | response_len = ec_i2c_count_response(i2c_msgs, num); |
197 | if (response_len < 0) { | 195 | if (response_len < 0) { |
198 | /* Unexpected; no errors should come when NULL response */ | 196 | /* Unexpected; no errors should come when NULL response */ |
199 | dev_warn(dev, "Error preparing response %d\n", response_len); | 197 | dev_warn(dev, "Error preparing response %d\n", response_len); |
200 | result = response_len; | 198 | return response_len; |
201 | goto exit; | ||
202 | } | ||
203 | |||
204 | if (request_len <= ARRAY_SIZE(bus->request_buf)) { | ||
205 | request = bus->request_buf; | ||
206 | } else { | ||
207 | request = kzalloc(request_len, GFP_KERNEL); | ||
208 | if (request == NULL) { | ||
209 | result = -ENOMEM; | ||
210 | goto exit; | ||
211 | } | ||
212 | } | ||
213 | if (response_len <= ARRAY_SIZE(bus->response_buf)) { | ||
214 | response = bus->response_buf; | ||
215 | } else { | ||
216 | response = kzalloc(response_len, GFP_KERNEL); | ||
217 | if (response == NULL) { | ||
218 | result = -ENOMEM; | ||
219 | goto exit; | ||
220 | } | ||
221 | } | 199 | } |
222 | 200 | ||
223 | result = ec_i2c_construct_message(request, i2c_msgs, num, bus_num); | 201 | result = ec_i2c_construct_message(msg.outdata, i2c_msgs, num, bus_num); |
224 | if (result) | 202 | if (result) |
225 | goto exit; | 203 | return result; |
226 | 204 | ||
227 | msg.version = 0; | 205 | msg.version = 0; |
228 | msg.command = EC_CMD_I2C_PASSTHRU; | 206 | msg.command = EC_CMD_I2C_PASSTHRU; |
229 | msg.outdata = request; | ||
230 | msg.outsize = request_len; | 207 | msg.outsize = request_len; |
231 | msg.indata = response; | ||
232 | msg.insize = response_len; | 208 | msg.insize = response_len; |
233 | 209 | ||
234 | result = cros_ec_cmd_xfer(bus->ec, &msg); | 210 | result = cros_ec_cmd_xfer(bus->ec, &msg); |
235 | if (result < 0) | 211 | if (result < 0) |
236 | goto exit; | 212 | return result; |
237 | 213 | ||
238 | result = ec_i2c_parse_response(response, i2c_msgs, &num); | 214 | result = ec_i2c_parse_response(msg.indata, i2c_msgs, &num); |
239 | if (result < 0) | 215 | if (result < 0) |
240 | goto exit; | 216 | return result; |
241 | 217 | ||
242 | /* Indicate success by saying how many messages were sent */ | 218 | /* Indicate success by saying how many messages were sent */ |
243 | result = num; | 219 | return num; |
244 | exit: | ||
245 | if (request != bus->request_buf) | ||
246 | kfree(request); | ||
247 | if (response != bus->response_buf) | ||
248 | kfree(response); | ||
249 | |||
250 | return result; | ||
251 | } | 220 | } |
252 | 221 | ||
253 | static u32 ec_i2c_functionality(struct i2c_adapter *adap) | 222 | static u32 ec_i2c_functionality(struct i2c_adapter *adap) |