aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristian Engelmayer <cengelma@gmx.at>2015-07-18 13:30:33 -0400
committerOlof Johansson <olof@lixom.net>2015-10-07 17:34:26 -0400
commit88dfb8b43d557ee9b1c1ffd2c8d275dd479a66d4 (patch)
tree28b6c0730aaf7861ef271c4e6fd1402c48e0c999
parent23ecee32b91cf732226bd7a3ee9fa7a9127645ab (diff)
platform/chrome: cros_ec: Fix leak in sequence_store()
The allocated cros_ec_command message structure is not freed in function sequence_store(). Make sure that 'msg' is freed in all exit paths. Detected by Coverity CID 1309667. Signed-off-by: Christian Engelmayer <cengelma@gmx.at> Signed-off-by: Olof Johansson <olof@lixom.net>
-rw-r--r--drivers/platform/chrome/cros_ec_lightbar.c23
1 files changed, 14 insertions, 9 deletions
diff --git a/drivers/platform/chrome/cros_ec_lightbar.c b/drivers/platform/chrome/cros_ec_lightbar.c
index 144e09df9b84..fc30a991b738 100644
--- a/drivers/platform/chrome/cros_ec_lightbar.c
+++ b/drivers/platform/chrome/cros_ec_lightbar.c
@@ -352,10 +352,6 @@ static ssize_t sequence_store(struct device *dev, struct device_attribute *attr,
352 struct cros_ec_dev *ec = container_of(dev, 352 struct cros_ec_dev *ec = container_of(dev,
353 struct cros_ec_dev, class_dev); 353 struct cros_ec_dev, class_dev);
354 354
355 msg = alloc_lightbar_cmd_msg(ec);
356 if (!msg)
357 return -ENOMEM;
358
359 for (len = 0; len < count; len++) 355 for (len = 0; len < count; len++)
360 if (!isalnum(buf[len])) 356 if (!isalnum(buf[len]))
361 break; 357 break;
@@ -370,21 +366,30 @@ static ssize_t sequence_store(struct device *dev, struct device_attribute *attr,
370 return ret; 366 return ret;
371 } 367 }
372 368
369 msg = alloc_lightbar_cmd_msg(ec);
370 if (!msg)
371 return -ENOMEM;
372
373 param = (struct ec_params_lightbar *)msg->data; 373 param = (struct ec_params_lightbar *)msg->data;
374 param->cmd = LIGHTBAR_CMD_SEQ; 374 param->cmd = LIGHTBAR_CMD_SEQ;
375 param->seq.num = num; 375 param->seq.num = num;
376 ret = lb_throttle(); 376 ret = lb_throttle();
377 if (ret) 377 if (ret)
378 return ret; 378 goto exit;
379 379
380 ret = cros_ec_cmd_xfer(ec->ec_dev, msg); 380 ret = cros_ec_cmd_xfer(ec->ec_dev, msg);
381 if (ret < 0) 381 if (ret < 0)
382 return ret; 382 goto exit;
383 383
384 if (msg->result != EC_RES_SUCCESS) 384 if (msg->result != EC_RES_SUCCESS) {
385 return -EINVAL; 385 ret = -EINVAL;
386 goto exit;
387 }
386 388
387 return count; 389 ret = count;
390exit:
391 kfree(msg);
392 return ret;
388} 393}
389 394
390/* Module initialization */ 395/* Module initialization */