mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] ata: pata_pdc2027x: fix division by zero in pdc_adjust_pll
@ 2026-08-25  8:32 Yang Zi
  2026-08-28  5:48 ` Damien Le Moal
  0 siblings, 1 reply; 2+ messages in thread
From: Yang Zi @ 2026-08-25  8:32 UTC (permalink / raw)
  To: dlemoal, cassel, linux-ide; +Cc: linux-kernel

pdc_adjust_pll() divides pout_required by pll_clock_khz before checking
that pll_clock_khz is within the valid range. If the PLL input clock is
less than 1000 Hz, pll_clock_khz is 0 and the division triggers a
divide-by-zero error.

Move the sanity check ahead of the division so the invalid input is
rejected before the ratio is computed.

Signed-off-by: Yang Zi <2959243019@qq.com>
---
diff --git a/drivers/ata/pata_pdc2027x.c b/drivers/ata/pata_pdc2027x.c
index d1d1cfb22e27..c4cff4eafbe8 100644
--- a/drivers/ata/pata_pdc2027x.c
+++ b/drivers/ata/pata_pdc2027x.c
@@ -517,7 +517,7 @@ static void pdc_adjust_pll(struct ata_host *host, long pll_clock, unsigned int b
     u16 pll_ctl;
     long pll_clock_khz = pll_clock / 1000;
     long pout_required = board_idx? PDC_133_MHZ:PDC_100_MHZ;
-    long ratio = pout_required / pll_clock_khz;
+    long ratio;
     int F, R;
 
     /* Sanity check */
@@ -527,6 +527,8 @@ static void pdc_adjust_pll(struct ata_host *host, long pll_clock, unsigned int b
         return;
     }
 
+    ratio = pout_required / pll_clock_khz;
+
     dev_dbg(host->dev, "pout_required is %ld\n", pout_required);
 
     /* Show the current clock value of PLL control register


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

* Re: [PATCH] ata: pata_pdc2027x: fix division by zero in pdc_adjust_pll
  2026-08-25  8:32 [PATCH] ata: pata_pdc2027x: fix division by zero in pdc_adjust_pll Yang Zi
@ 2026-08-28  5:48 ` Damien Le Moal
  0 siblings, 0 replies; 2+ messages in thread
From: Damien Le Moal @ 2026-08-28  5:48 UTC (permalink / raw)
  To: Yang Zi, cassel, linux-ide; +Cc: linux-kernel

On 8/25/26 17:32, Yang Zi wrote:
> pdc_adjust_pll() divides pout_required by pll_clock_khz before checking
> that pll_clock_khz is within the valid range. If the PLL input clock is
> less than 1000 Hz, pll_clock_khz is 0 and the division triggers a
> divide-by-zero error.
> 
> Move the sanity check ahead of the division so the invalid input is
> rejected before the ratio is computed.
> 
> Signed-off-by: Yang Zi <2959243019@qq.com>

This is needs a fixes tag I think.

Other than that, looks OK.

Reviewed-by: Damien Le Moal <dlemoal@kernel.org>

-- 
Damien Le Moal
Western Digital Research

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

end of thread, other threads:[~2026-08-28  5:48 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-08-25  8:32 [PATCH] ata: pata_pdc2027x: fix division by zero in pdc_adjust_pll Yang Zi
2026-08-28  5:48 ` Damien Le Moal

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

all inboxes | Powered by JetHome®