Message ID | 20231219171903.3530985-14-hugo@hugovil.com |
---|---|
State | New |
Headers | show |
Series | serial: sc16is7xx: fixes, cleanups and improvements | expand |
On Tue, Dec 19, 2023 at 12:18:57PM -0500, Hugo Villeneuve wrote: > From: Hugo Villeneuve <hvilleneuve@dimonoff.com> > > Improve code readability and efficiency by using in_range() when checking > device tree properties bound. ... > 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; Okay, looking at this, it becomes uglier than initial code, means my suggestion was not good. Please, drop this patch.
On Wed, 20 Dec 2023 17:54:07 +0200 Andy Shevchenko <andy.shevchenko@gmail.com> wrote: > On Tue, Dec 19, 2023 at 12:18:57PM -0500, Hugo Villeneuve wrote: > > From: Hugo Villeneuve <hvilleneuve@dimonoff.com> > > > > Improve code readability and efficiency by using in_range() when checking > > device tree properties bound. > > ... > > > 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; > > Okay, looking at this, it becomes uglier than initial code, > means my suggestion was not good. Please, drop this patch. Ok, will drop it for V2. Hugo Villeneuve
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",