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

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 <groeck@chromium.org>
Signed-off-by: Tzung-Bi Shih <tzungbi@kernel.org>
Link: https://lore.kernel.org/r/20220513044143.1045728-4-tzungbi@kernel.org

+5 -2
+5 -2
drivers/platform/chrome/cros_ec_proto.c
··· 60 60 int i; 61 61 u8 csum = 0; 62 62 63 - BUG_ON(msg->outsize + sizeof(*request) > ec_dev->dout_size); 63 + if (msg->outsize + sizeof(*request) > ec_dev->dout_size) 64 + return -EINVAL; 64 65 65 66 out = ec_dev->dout; 66 67 request = (struct ec_host_request *)out; ··· 177 176 if (ec_dev->proto_version > 2) 178 177 return prepare_packet(ec_dev, msg); 179 178 180 - BUG_ON(msg->outsize > EC_PROTO2_MAX_PARAM_SIZE); 179 + if (msg->outsize > EC_PROTO2_MAX_PARAM_SIZE) 180 + return -EINVAL; 181 + 181 182 out = ec_dev->dout; 182 183 out[0] = EC_CMD_VERSION0 + msg->version; 183 184 out[1] = msg->command;