From: Hugo Villeneuve <hvilleneuve@xxxxxxxxxxxx> Improve code readability and efficiency by using in_range() when checking device tree properties bound. Suggested-by: Andy Shevchenko <andy.shevchenko@xxxxxxxxx> Signed-off-by: Hugo Villeneuve <hvilleneuve@xxxxxxxxxxxx> --- drivers/tty/serial/sc16is7xx.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/drivers/tty/serial/sc16is7xx.c b/drivers/tty/serial/sc16is7xx.c index 133538f91390..29089b11f6f1 100644 --- a/drivers/tty/serial/sc16is7xx.c +++ b/drivers/tty/serial/sc16is7xx.c @@ -14,6 +14,7 @@ #include <linux/device.h> #include <linux/gpio/driver.h> #include <linux/i2c.h> +#include <linux/minmax.h> #include <linux/mod_devicetable.h> #include <linux/module.h> #include <linux/property.h> @@ -1398,7 +1399,7 @@ static void sc16is7xx_setup_irda_ports(struct sc16is7xx_port *s) struct device *dev = s->p[0].port.dev; count = device_property_count_u32(dev, "irda-mode-ports"); - if (count < 0 || count > SC16IS7XX_MAX_PORTS) + if (!in_range(count, 0, SC16IS7XX_MAX_PORTS + 1)) return; ret = device_property_read_u32_array(dev, "irda-mode-ports", @@ -1425,7 +1426,7 @@ static int sc16is7xx_setup_mctrl_ports(struct sc16is7xx_port *s, struct device *dev = s->p[0].port.dev; count = device_property_count_u32(dev, "nxp,modem-control-line-ports"); - if (count < 0 || count > SC16IS7XX_MAX_PORTS) + if (!in_range(count, 0, SC16IS7XX_MAX_PORTS + 1)) return 0; ret = device_property_read_u32_array(dev, "nxp,modem-control-line-ports", -- 2.39.2