public inbox for linux-gpio@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] gpio: gpio-exar: replace division condition with direct comparison
@ 2024-11-12 20:16 Suraj Sonawane
  2024-11-13 15:31 ` Bartosz Golaszewski
  2024-11-15  9:36 ` Andy Shevchenko
  0 siblings, 2 replies; 8+ messages in thread
From: Suraj Sonawane @ 2024-11-12 20:16 UTC (permalink / raw)
  To: Linus Walleij, Bartosz Golaszewski
  Cc: linux-gpio, linux-kernel, Suraj Sonawane

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@gmail.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


^ permalink raw reply related	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2024-11-18  9:23 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-11-12 20:16 [PATCH] gpio: gpio-exar: replace division condition with direct comparison Suraj Sonawane
2024-11-13 15:31 ` Bartosz Golaszewski
2024-11-14  8:55   ` Suraj Sonawane
2024-11-15  9:36 ` Andy Shevchenko
2024-11-15 11:55   ` Dan Carpenter
2024-11-15 11:58     ` Bartosz Golaszewski
2024-11-15 13:25   ` Suraj Sonawane
2024-11-18  9:23     ` Andy Shevchenko

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox