platform/chrome: cros_ec_i2c: drop BUG_ON() in cros_ec_pkt_xfer_i2c()
authorTzung-Bi Shih <tzungbi@kernel.org>
Fri, 13 May 2022 04:41:41 +0000 (12:41 +0800)
committerTzung-Bi Shih <tzungbi@kernel.org>
Mon, 16 May 2022 02:01:51 +0000 (10:01 +0800)
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-6-tzungbi@kernel.org
drivers/platform/chrome/cros_ec_i2c.c

index a4f305f1eb0eaf3da01dd346df36c4f38a3bec93..9f5b95763173cca7b5926823c1c7f4745300db2e 100644 (file)
@@ -72,13 +72,19 @@ static int cros_ec_pkt_xfer_i2c(struct cros_ec_device *ec_dev,
        i2c_msg[1].flags = I2C_M_RD;
 
        packet_len = msg->insize + response_header_size;
-       BUG_ON(packet_len > ec_dev->din_size);
+       if (packet_len > ec_dev->din_size) {
+               ret = -EINVAL;
+               goto done;
+       }
        in_buf = ec_dev->din;
        i2c_msg[1].len = packet_len;
        i2c_msg[1].buf = (char *) in_buf;
 
        packet_len = msg->outsize + request_header_size;
-       BUG_ON(packet_len > ec_dev->dout_size);
+       if (packet_len > ec_dev->dout_size) {
+               ret = -EINVAL;
+               goto done;
+       }
        out_buf = ec_dev->dout;
        i2c_msg[0].len = packet_len;
        i2c_msg[0].buf = (char *) out_buf;