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

platform/chrome: cros_ec_spi: drop BUG_ON() if `din` isn't large enough

It is overkill to crash the kernel if the `din` buffer is going to full
or overflow.

Drop the BUG_ON() and return -EINVAL instead.

Signed-off-by: Tzung-Bi Shih <tzungbi@kernel.org>
Reviewed-by: Guenter Roeck <groeck@chromium.org>
Link: https://lore.kernel.org/r/20220513044143.1045728-8-tzungbi@kernel.org

+6 -3
+6 -3
drivers/platform/chrome/cros_ec_spi.c
··· 160 160 struct spi_message msg; 161 161 int ret; 162 162 163 - BUG_ON(buf - ec_dev->din + n > ec_dev->din_size); 163 + if (buf - ec_dev->din + n > ec_dev->din_size) 164 + return -EINVAL; 164 165 165 166 memset(&trans, 0, sizeof(trans)); 166 167 trans.cs_change = 1; ··· 198 197 unsigned long deadline; 199 198 int todo; 200 199 201 - BUG_ON(ec_dev->din_size < EC_MSG_PREAMBLE_COUNT); 200 + if (ec_dev->din_size < EC_MSG_PREAMBLE_COUNT) 201 + return -EINVAL; 202 202 203 203 /* Receive data until we see the header byte */ 204 204 deadline = jiffies + msecs_to_jiffies(EC_MSG_DEADLINE_MS); ··· 306 304 unsigned long deadline; 307 305 int todo; 308 306 309 - BUG_ON(ec_dev->din_size < EC_MSG_PREAMBLE_COUNT); 307 + if (ec_dev->din_size < EC_MSG_PREAMBLE_COUNT) 308 + return -EINVAL; 310 309 311 310 /* Receive data until we see the header byte */ 312 311 deadline = jiffies + msecs_to_jiffies(EC_MSG_DEADLINE_MS);