Skip to content

Commit c2dcb1b

Browse files
author
Tzung-Bi Shih
committed
platform/chrome: cros_ec_proto: drop BUG_ON() in cros_ec_prepare_tx()
It is overkill to crash the kernel if the given message is oversize. Drop the BUG_ON() and return -EINVAL instead. Reviewed-by: Guenter Roeck <[email protected]> Signed-off-by: Tzung-Bi Shih <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent 71d3ae7 commit c2dcb1b

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

drivers/platform/chrome/cros_ec_proto.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,8 @@ static int prepare_packet(struct cros_ec_device *ec_dev,
6060
int i;
6161
u8 csum = 0;
6262

63-
BUG_ON(msg->outsize + sizeof(*request) > ec_dev->dout_size);
63+
if (msg->outsize + sizeof(*request) > ec_dev->dout_size)
64+
return -EINVAL;
6465

6566
out = ec_dev->dout;
6667
request = (struct ec_host_request *)out;
@@ -176,7 +177,9 @@ int cros_ec_prepare_tx(struct cros_ec_device *ec_dev,
176177
if (ec_dev->proto_version > 2)
177178
return prepare_packet(ec_dev, msg);
178179

179-
BUG_ON(msg->outsize > EC_PROTO2_MAX_PARAM_SIZE);
180+
if (msg->outsize > EC_PROTO2_MAX_PARAM_SIZE)
181+
return -EINVAL;
182+
180183
out = ec_dev->dout;
181184
out[0] = EC_CMD_VERSION0 + msg->version;
182185
out[1] = msg->command;

0 commit comments

Comments
 (0)