Merge tag 'for-v5.19' of git://git.kernel.org/pub/scm/linux/kernel/git/sre/linux...
[linux-2.6-microblaze.git] / drivers / platform / chrome / cros_ec_proto.c
index db1c8ba..ff767dc 100644 (file)
@@ -60,7 +60,8 @@ static int prepare_packet(struct cros_ec_device *ec_dev,
        int i;
        u8 csum = 0;
 
-       BUG_ON(msg->outsize + sizeof(*request) > ec_dev->dout_size);
+       if (msg->outsize + sizeof(*request) > ec_dev->dout_size)
+               return -EINVAL;
 
        out = ec_dev->dout;
        request = (struct ec_host_request *)out;
@@ -164,7 +165,7 @@ static int send_command(struct cros_ec_device *ec_dev,
  * only SPI uses it. Once LPC uses the same protocol it can start using it.
  * I2C could use it now, with a refactor of the existing code.
  *
- * Return: 0 on success or negative error code.
+ * Return: number of prepared bytes on success or negative error code.
  */
 int cros_ec_prepare_tx(struct cros_ec_device *ec_dev,
                       struct cros_ec_command *msg)
@@ -176,7 +177,9 @@ int cros_ec_prepare_tx(struct cros_ec_device *ec_dev,
        if (ec_dev->proto_version > 2)
                return prepare_packet(ec_dev, msg);
 
-       BUG_ON(msg->outsize > EC_PROTO2_MAX_PARAM_SIZE);
+       if (msg->outsize > EC_PROTO2_MAX_PARAM_SIZE)
+               return -EINVAL;
+
        out = ec_dev->dout;
        out[0] = EC_CMD_VERSION0 + msg->version;
        out[1] = msg->command;
@@ -814,7 +817,8 @@ u32 cros_ec_get_host_event(struct cros_ec_device *ec_dev)
 {
        u32 host_event;
 
-       BUG_ON(!ec_dev->mkbp_event_supported);
+       if (!ec_dev->mkbp_event_supported)
+               return 0;
 
        if (ec_dev->event_data.event_type != EC_MKBP_EVENT_HOST_EVENT)
                return 0;