[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20231219171903.3530985-14-hugo@hugovil.com>
Date: Tue, 19 Dec 2023 12:18:57 -0500
From: Hugo Villeneuve <hugo@...ovil.com>
To: gregkh@...uxfoundation.org,
jirislaby@...nel.org,
jringle@...dpoint.com,
kubakici@...pl,
phil@...pberrypi.org,
bo.svangard@...eddedart.se
Cc: linux-kernel@...r.kernel.org,
linux-serial@...r.kernel.org,
hugo@...ovil.com,
Hugo Villeneuve <hvilleneuve@...onoff.com>,
Andy Shevchenko <andy.shevchenko@...il.com>
Subject: [PATCH 13/18] serial: sc16is7xx: use in_range() for DT properties bound checks
From: Hugo Villeneuve <hvilleneuve@...onoff.com>
Improve code readability and efficiency by using in_range() when checking
device tree properties bound.
Suggested-by: Andy Shevchenko <andy.shevchenko@...il.com>
Signed-off-by: Hugo Villeneuve <hvilleneuve@...onoff.com>
---
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
Powered by blists - more mailing lists