platform/chrome: cros_ec_spi: drop unneeded BUG_ON()
authorTzung-Bi Shih <tzungbi@kernel.org>
Fri, 13 May 2022 04:41:42 +0000 (12:41 +0800)
committerTzung-Bi Shih <tzungbi@kernel.org>
Mon, 16 May 2022 02:01:51 +0000 (10:01 +0800)
In the context, the following conditions are always false:

- `todo` < 0
Suppose that EC_SPI_FRAME_START is found at the last byte of transfer.

In the case, `ptr` == `end` - 1.  As a result, `todo` must be 0.

- `todo` > `ec_dev->din_size`
Suppose that there is no preamble bytes.  EC_SPI_FRAME_START is found at
the first byte of transfer.

In the case, `end` == `ptr` + EC_MSG_PREAMBLE_COUNT.
As a result, `todo` == EC_MSG_PREAMBLE_COUNT - 1.
However, it already checked `ec_dev->din_size` < EC_MSG_PREAMBLE_COUNT at
the beginning of function.

Drop the unneeded BUG_ON().

Signed-off-by: Tzung-Bi Shih <tzungbi@kernel.org>
Reviewed-by: Guenter Roeck <groeck@chromium.org>
Link: https://lore.kernel.org/r/20220513044143.1045728-7-tzungbi@kernel.org
drivers/platform/chrome/cros_ec_spi.c

index 589f18e9537d959cb1b79f87e9ca75762649f20e..5264615f46aff1d6dc559cca49fd5060b78d590c 100644 (file)
@@ -237,7 +237,6 @@ static int cros_ec_spi_receive_packet(struct cros_ec_device *ec_dev,
         * start of our buffer
         */
        todo = end - ++ptr;
-       BUG_ON(todo < 0 || todo > ec_dev->din_size);
        todo = min(todo, need_len);
        memmove(ec_dev->din, ptr, todo);
        ptr = ec_dev->din + todo;
@@ -345,7 +344,6 @@ static int cros_ec_spi_receive_response(struct cros_ec_device *ec_dev,
         * start of our buffer
         */
        todo = end - ++ptr;
-       BUG_ON(todo < 0 || todo > ec_dev->din_size);
        todo = min(todo, need_len);
        memmove(ec_dev->din, ptr, todo);
        ptr = ec_dev->din + todo;