lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-Id: <20241112201659.16785-1-surajsonawane0215@gmail.com>
Date: Wed, 13 Nov 2024 01:46:59 +0530
From: Suraj Sonawane <surajsonawane0215@...il.com>
To: Linus Walleij <linus.walleij@...aro.org>,
	Bartosz Golaszewski <brgl@...ev.pl>
Cc: linux-gpio@...r.kernel.org,
	linux-kernel@...r.kernel.org,
	Suraj Sonawane <surajsonawane0215@...il.com>
Subject: [PATCH] gpio: gpio-exar: replace division condition with direct comparison

Fix an issue detected by the Smatch tool:

drivers/gpio/gpio-exar.c:52 exar_offset_to_sel_addr() warn:
replace divide condition 'pin / 8' with 'pin >= 8'
drivers/gpio/gpio-exar.c:62 exar_offset_to_lvl_addr() warn:
replace divide condition 'pin / 8' with 'pin >= 8'

The division 'pin / 8' was used to check if the pin number is 8 or greater,
which can be confusing and less readable. Replacing it with 'pin >= 8'
makes the code clearer by directly comparing the pin number. This also
removes reliance on integer division, which can be harder to understand
and may introduce subtle bugs in the future.

Signed-off-by: Suraj Sonawane <surajsonawane0215@...il.com>
---
 drivers/gpio/gpio-exar.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/gpio/gpio-exar.c b/drivers/gpio/gpio-exar.c
index 5170fe759..400cc3a0b 100644
--- a/drivers/gpio/gpio-exar.c
+++ b/drivers/gpio/gpio-exar.c
@@ -49,7 +49,7 @@ exar_offset_to_sel_addr(struct exar_gpio_chip *exar_gpio, unsigned int offset)
 {
 	unsigned int pin = exar_gpio->first_pin + (offset % 16);
 	unsigned int cascaded = offset / 16;
-	unsigned int addr = pin / 8 ? EXAR_OFFSET_MPIOSEL_HI : EXAR_OFFSET_MPIOSEL_LO;
+	unsigned int addr = pin >= 8 ? EXAR_OFFSET_MPIOSEL_HI : EXAR_OFFSET_MPIOSEL_LO;
 
 	return addr + (cascaded ? exar_gpio->cascaded_offset : 0);
 }
@@ -59,7 +59,7 @@ exar_offset_to_lvl_addr(struct exar_gpio_chip *exar_gpio, unsigned int offset)
 {
 	unsigned int pin = exar_gpio->first_pin + (offset % 16);
 	unsigned int cascaded = offset / 16;
-	unsigned int addr = pin / 8 ? EXAR_OFFSET_MPIOLVL_HI : EXAR_OFFSET_MPIOLVL_LO;
+	unsigned int addr = pin >= 8 ? EXAR_OFFSET_MPIOLVL_HI : EXAR_OFFSET_MPIOLVL_LO;
 
 	return addr + (cascaded ? exar_gpio->cascaded_offset : 0);
 }
-- 
2.34.1


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ