linux-gpio.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] pinctrl: single: Fix potential division by zero
@ 2022-11-17 12:30 Maxim Korotkov
  2022-11-18  8:15 ` Tony Lindgren
  2022-11-21 13:42 ` Linus Walleij
  0 siblings, 2 replies; 3+ messages in thread
From: Maxim Korotkov @ 2022-11-17 12:30 UTC (permalink / raw)
  To: Tony Lindgren
  Cc: Maxim Korotkov, Haojian Zhuang, Linus Walleij,
	Manjunathappa, Prakash, linux-arm-kernel, linux-omap, linux-gpio,
	linux-kernel, lvc-project

There is a possibility of dividing by zero due to the pcs->bits_per_pin
if pcs->fmask() also has a value of zero and called fls
from asm-generic/bitops/builtin-fls.h or arch/x86/include/asm/bitops.h.
The function pcs_probe() has the branch that assigned to fmask 0 before
pcs_allocate_pin_table() was called

Found by Linux Verification Center (linuxtesting.org) with SVACE.

Fixes: 4e7e8017a80e ("pinctrl: pinctrl-single: enhance to configure multiple pins of different modules")
Signed-off-by: Maxim Korotkov <korotkov.maxim.s@gmail.com>
---
 drivers/pinctrl/pinctrl-single.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/pinctrl/pinctrl-single.c b/drivers/pinctrl/pinctrl-single.c
index 67bec7ea0f8b..414ee6bb8ac9 100644
--- a/drivers/pinctrl/pinctrl-single.c
+++ b/drivers/pinctrl/pinctrl-single.c
@@ -727,7 +727,7 @@ static int pcs_allocate_pin_table(struct pcs_device *pcs)
 
 	mux_bytes = pcs->width / BITS_PER_BYTE;
 
-	if (pcs->bits_per_mux) {
+	if (pcs->bits_per_mux && pcs->fmask) {
 		pcs->bits_per_pin = fls(pcs->fmask);
 		nr_pins = (pcs->size * BITS_PER_BYTE) / pcs->bits_per_pin;
 	} else {
-- 
2.17.1


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

* Re: [PATCH] pinctrl: single: Fix potential division by zero
  2022-11-17 12:30 [PATCH] pinctrl: single: Fix potential division by zero Maxim Korotkov
@ 2022-11-18  8:15 ` Tony Lindgren
  2022-11-21 13:42 ` Linus Walleij
  1 sibling, 0 replies; 3+ messages in thread
From: Tony Lindgren @ 2022-11-18  8:15 UTC (permalink / raw)
  To: Maxim Korotkov
  Cc: Haojian Zhuang, Linus Walleij, Manjunathappa, Prakash,
	linux-arm-kernel, linux-omap, linux-gpio, linux-kernel,
	lvc-project

* Maxim Korotkov <korotkov.maxim.s@gmail.com> [221117 12:22]:
> There is a possibility of dividing by zero due to the pcs->bits_per_pin
> if pcs->fmask() also has a value of zero and called fls
> from asm-generic/bitops/builtin-fls.h or arch/x86/include/asm/bitops.h.
> The function pcs_probe() has the branch that assigned to fmask 0 before
> pcs_allocate_pin_table() was called

Reviewed-by: Tony Lindgren <tony@atomide.com>

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

* Re: [PATCH] pinctrl: single: Fix potential division by zero
  2022-11-17 12:30 [PATCH] pinctrl: single: Fix potential division by zero Maxim Korotkov
  2022-11-18  8:15 ` Tony Lindgren
@ 2022-11-21 13:42 ` Linus Walleij
  1 sibling, 0 replies; 3+ messages in thread
From: Linus Walleij @ 2022-11-21 13:42 UTC (permalink / raw)
  To: Maxim Korotkov
  Cc: Tony Lindgren, Haojian Zhuang, Manjunathappa, Prakash,
	linux-arm-kernel, linux-omap, linux-gpio, linux-kernel,
	lvc-project

On Thu, Nov 17, 2022 at 1:32 PM Maxim Korotkov
<korotkov.maxim.s@gmail.com> wrote:

> There is a possibility of dividing by zero due to the pcs->bits_per_pin
> if pcs->fmask() also has a value of zero and called fls
> from asm-generic/bitops/builtin-fls.h or arch/x86/include/asm/bitops.h.
> The function pcs_probe() has the branch that assigned to fmask 0 before
> pcs_allocate_pin_table() was called
>
> Found by Linux Verification Center (linuxtesting.org) with SVACE.
>
> Fixes: 4e7e8017a80e ("pinctrl: pinctrl-single: enhance to configure multiple pins of different modules")
> Signed-off-by: Maxim Korotkov <korotkov.maxim.s@gmail.com>

Patch applied for fixes.

Yours,
Linus Walleij

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

end of thread, other threads:[~2022-11-21 13:43 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-11-17 12:30 [PATCH] pinctrl: single: Fix potential division by zero Maxim Korotkov
2022-11-18  8:15 ` Tony Lindgren
2022-11-21 13:42 ` Linus Walleij

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).