aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/misc/mei/bus.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/misc/mei/bus.c')
-rw-r--r--drivers/misc/mei/bus.c69
1 files changed, 37 insertions, 32 deletions
diff --git a/drivers/misc/mei/bus.c b/drivers/misc/mei/bus.c
index b3a72bca5242..be767f4db26a 100644
--- a/drivers/misc/mei/bus.c
+++ b/drivers/misc/mei/bus.c
@@ -224,46 +224,53 @@ void mei_cl_driver_unregister(struct mei_cl_driver *driver)
224} 224}
225EXPORT_SYMBOL_GPL(mei_cl_driver_unregister); 225EXPORT_SYMBOL_GPL(mei_cl_driver_unregister);
226 226
227static int ___mei_cl_send(struct mei_cl *cl, u8 *buf, size_t length, 227static ssize_t ___mei_cl_send(struct mei_cl *cl, u8 *buf, size_t length,
228 bool blocking) 228 bool blocking)
229{ 229{
230 struct mei_device *dev; 230 struct mei_device *dev;
231 struct mei_me_client *me_cl; 231 struct mei_me_client *me_cl = NULL;
232 struct mei_cl_cb *cb; 232 struct mei_cl_cb *cb = NULL;
233 int rets; 233 ssize_t rets;
234 234
235 if (WARN_ON(!cl || !cl->dev)) 235 if (WARN_ON(!cl || !cl->dev))
236 return -ENODEV; 236 return -ENODEV;
237 237
238 dev = cl->dev; 238 dev = cl->dev;
239 239
240 if (cl->state != MEI_FILE_CONNECTED) 240 mutex_lock(&dev->device_lock);
241 return -ENODEV; 241 if (cl->state != MEI_FILE_CONNECTED) {
242 rets = -ENODEV;
243 goto out;
244 }
242 245
243 /* Check if we have an ME client device */ 246 /* Check if we have an ME client device */
244 me_cl = mei_me_cl_by_uuid_id(dev, &cl->cl_uuid, cl->me_client_id); 247 me_cl = mei_me_cl_by_uuid_id(dev, &cl->cl_uuid, cl->me_client_id);
245 if (!me_cl) 248 if (!me_cl) {
246 return -ENOTTY; 249 rets = -ENOTTY;
250 goto out;
251 }
247 252
248 if (length > me_cl->props.max_msg_length) 253 if (length > me_cl->props.max_msg_length) {
249 return -EFBIG; 254 rets = -EFBIG;
255 goto out;
256 }
250 257
251 cb = mei_io_cb_init(cl, NULL); 258 cb = mei_io_cb_init(cl, NULL);
252 if (!cb) 259 if (!cb) {
253 return -ENOMEM; 260 rets = -ENOMEM;
261 goto out;
262 }
254 263
255 rets = mei_io_cb_alloc_req_buf(cb, length); 264 rets = mei_io_cb_alloc_req_buf(cb, length);
256 if (rets < 0) { 265 if (rets < 0)
257 mei_io_cb_free(cb); 266 goto out;
258 return rets;
259 }
260 267
261 memcpy(cb->request_buffer.data, buf, length); 268 memcpy(cb->request_buffer.data, buf, length);
262 269
263 mutex_lock(&dev->device_lock);
264
265 rets = mei_cl_write(cl, cb, blocking); 270 rets = mei_cl_write(cl, cb, blocking);
266 271
272out:
273 mei_me_cl_put(me_cl);
267 mutex_unlock(&dev->device_lock); 274 mutex_unlock(&dev->device_lock);
268 if (rets < 0) 275 if (rets < 0)
269 mei_io_cb_free(cb); 276 mei_io_cb_free(cb);
@@ -271,12 +278,12 @@ static int ___mei_cl_send(struct mei_cl *cl, u8 *buf, size_t length,
271 return rets; 278 return rets;
272} 279}
273 280
274int __mei_cl_recv(struct mei_cl *cl, u8 *buf, size_t length) 281ssize_t __mei_cl_recv(struct mei_cl *cl, u8 *buf, size_t length)
275{ 282{
276 struct mei_device *dev; 283 struct mei_device *dev;
277 struct mei_cl_cb *cb; 284 struct mei_cl_cb *cb;
278 size_t r_length; 285 size_t r_length;
279 int err; 286 ssize_t rets;
280 287
281 if (WARN_ON(!cl || !cl->dev)) 288 if (WARN_ON(!cl || !cl->dev))
282 return -ENODEV; 289 return -ENODEV;
@@ -286,11 +293,9 @@ int __mei_cl_recv(struct mei_cl *cl, u8 *buf, size_t length)
286 mutex_lock(&dev->device_lock); 293 mutex_lock(&dev->device_lock);
287 294
288 if (!cl->read_cb) { 295 if (!cl->read_cb) {
289 err = mei_cl_read_start(cl, length); 296 rets = mei_cl_read_start(cl, length);
290 if (err < 0) { 297 if (rets < 0)
291 mutex_unlock(&dev->device_lock); 298 goto out;
292 return err;
293 }
294 } 299 }
295 300
296 if (cl->reading_state != MEI_READ_COMPLETE && 301 if (cl->reading_state != MEI_READ_COMPLETE &&
@@ -313,13 +318,13 @@ int __mei_cl_recv(struct mei_cl *cl, u8 *buf, size_t length)
313 cb = cl->read_cb; 318 cb = cl->read_cb;
314 319
315 if (cl->reading_state != MEI_READ_COMPLETE) { 320 if (cl->reading_state != MEI_READ_COMPLETE) {
316 r_length = 0; 321 rets = 0;
317 goto out; 322 goto out;
318 } 323 }
319 324
320 r_length = min_t(size_t, length, cb->buf_idx); 325 r_length = min_t(size_t, length, cb->buf_idx);
321
322 memcpy(buf, cb->response_buffer.data, r_length); 326 memcpy(buf, cb->response_buffer.data, r_length);
327 rets = r_length;
323 328
324 mei_io_cb_free(cb); 329 mei_io_cb_free(cb);
325 cl->reading_state = MEI_IDLE; 330 cl->reading_state = MEI_IDLE;
@@ -328,20 +333,20 @@ int __mei_cl_recv(struct mei_cl *cl, u8 *buf, size_t length)
328out: 333out:
329 mutex_unlock(&dev->device_lock); 334 mutex_unlock(&dev->device_lock);
330 335
331 return r_length; 336 return rets;
332} 337}
333 338
334inline int __mei_cl_async_send(struct mei_cl *cl, u8 *buf, size_t length) 339inline ssize_t __mei_cl_async_send(struct mei_cl *cl, u8 *buf, size_t length)
335{ 340{
336 return ___mei_cl_send(cl, buf, length, 0); 341 return ___mei_cl_send(cl, buf, length, 0);
337} 342}
338 343
339inline int __mei_cl_send(struct mei_cl *cl, u8 *buf, size_t length) 344inline ssize_t __mei_cl_send(struct mei_cl *cl, u8 *buf, size_t length)
340{ 345{
341 return ___mei_cl_send(cl, buf, length, 1); 346 return ___mei_cl_send(cl, buf, length, 1);
342} 347}
343 348
344int mei_cl_send(struct mei_cl_device *device, u8 *buf, size_t length) 349ssize_t mei_cl_send(struct mei_cl_device *device, u8 *buf, size_t length)
345{ 350{
346 struct mei_cl *cl = device->cl; 351 struct mei_cl *cl = device->cl;
347 352
@@ -355,7 +360,7 @@ int mei_cl_send(struct mei_cl_device *device, u8 *buf, size_t length)
355} 360}
356EXPORT_SYMBOL_GPL(mei_cl_send); 361EXPORT_SYMBOL_GPL(mei_cl_send);
357 362
358int mei_cl_recv(struct mei_cl_device *device, u8 *buf, size_t length) 363ssize_t mei_cl_recv(struct mei_cl_device *device, u8 *buf, size_t length)
359{ 364{
360 struct mei_cl *cl = device->cl; 365 struct mei_cl *cl = device->cl;
361 366