linux-ide.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] ata: pata_hpt3x2n: prevent potential forever loop in hpt3xn_calibrate_dpll()
@ 2023-02-01 14:10 Dan Carpenter
  2023-02-01 15:02 ` Sergey Shtylyov
  2023-02-14  3:47 ` Damien Le Moal
  0 siblings, 2 replies; 4+ messages in thread
From: Dan Carpenter @ 2023-02-01 14:10 UTC (permalink / raw)
  To: Sergey Shtylyov; +Cc: Damien Le Moal, linux-ide, kernel-janitors

This code accidentally reuses "tries" as the iterator for both the inside
and outside loops.  It means that the potentially the "tries" could be
reset to 0x1000 and never reach 0x5000.

Fixes: 669a5db411d8 ("[libata] Add a bunch of PATA drivers.")
Signed-off-by: Dan Carpenter <error27@gmail.com>
---
 drivers/ata/pata_hpt3x2n.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/ata/pata_hpt3x2n.c b/drivers/ata/pata_hpt3x2n.c
index 617c95522f43..447dc287a2d4 100644
--- a/drivers/ata/pata_hpt3x2n.c
+++ b/drivers/ata/pata_hpt3x2n.c
@@ -380,14 +380,14 @@ static int hpt3xn_calibrate_dpll(struct pci_dev *dev)
 {
 	u8 reg5b;
 	u32 reg5c;
-	int tries;
+	int tries, tries2;
 
 	for (tries = 0; tries < 0x5000; tries++) {
 		udelay(50);
 		pci_read_config_byte(dev, 0x5b, &reg5b);
 		if (reg5b & 0x80) {
 			/* See if it stays set */
-			for (tries = 0; tries < 0x1000; tries++) {
+			for (tries2 = 0; tries2 < 0x1000; tries2++) {
 				pci_read_config_byte(dev, 0x5b, &reg5b);
 				/* Failed ? */
 				if ((reg5b & 0x80) == 0)
-- 
2.35.1


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

* Re: [PATCH] ata: pata_hpt3x2n: prevent potential forever loop in hpt3xn_calibrate_dpll()
  2023-02-01 14:10 [PATCH] ata: pata_hpt3x2n: prevent potential forever loop in hpt3xn_calibrate_dpll() Dan Carpenter
@ 2023-02-01 15:02 ` Sergey Shtylyov
  2023-02-14  3:47 ` Damien Le Moal
  1 sibling, 0 replies; 4+ messages in thread
From: Sergey Shtylyov @ 2023-02-01 15:02 UTC (permalink / raw)
  To: Dan Carpenter; +Cc: Damien Le Moal, linux-ide, kernel-janitors

On 2/1/23 5:10 PM, Dan Carpenter wrote:

> This code accidentally reuses "tries" as the iterator for both the inside
> and outside loops.  It means that the potentially the "tries" could be
> reset to 0x1000 and never reach 0x5000.
> 
> Fixes: 669a5db411d8 ("[libata] Add a bunch of PATA drivers.")
> Signed-off-by: Dan Carpenter <error27@gmail.com>
[...]

   Again, I'm OK with this simplistic fix:

Reviewed-by: Sergey Shtylyov <s.shtylyov@omp.ru>

[...]

MBR, Sergey

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

* Re: [PATCH] ata: pata_hpt3x2n: prevent potential forever loop in hpt3xn_calibrate_dpll()
  2023-02-01 14:10 [PATCH] ata: pata_hpt3x2n: prevent potential forever loop in hpt3xn_calibrate_dpll() Dan Carpenter
  2023-02-01 15:02 ` Sergey Shtylyov
@ 2023-02-14  3:47 ` Damien Le Moal
  2023-02-14  7:06   ` Dan Carpenter
  1 sibling, 1 reply; 4+ messages in thread
From: Damien Le Moal @ 2023-02-14  3:47 UTC (permalink / raw)
  To: Dan Carpenter, Sergey Shtylyov; +Cc: linux-ide, kernel-janitors

On 2/1/23 23:10, Dan Carpenter wrote:
> This code accidentally reuses "tries" as the iterator for both the inside
> and outside loops.  It means that the potentially the "tries" could be
> reset to 0x1000 and never reach 0x5000.
> 
> Fixes: 669a5db411d8 ("[libata] Add a bunch of PATA drivers.")
> Signed-off-by: Dan Carpenter <error27@gmail.com>
> ---
>  drivers/ata/pata_hpt3x2n.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/ata/pata_hpt3x2n.c b/drivers/ata/pata_hpt3x2n.c
> index 617c95522f43..447dc287a2d4 100644
> --- a/drivers/ata/pata_hpt3x2n.c
> +++ b/drivers/ata/pata_hpt3x2n.c
> @@ -380,14 +380,14 @@ static int hpt3xn_calibrate_dpll(struct pci_dev *dev)
>  {
>  	u8 reg5b;
>  	u32 reg5c;
> -	int tries;
> +	int tries, tries2;
>  
>  	for (tries = 0; tries < 0x5000; tries++) {
>  		udelay(50);
>  		pci_read_config_byte(dev, 0x5b, &reg5b);
>  		if (reg5b & 0x80) {
>  			/* See if it stays set */
> -			for (tries = 0; tries < 0x1000; tries++) {
> +			for (tries2 = 0; tries2 < 0x1000; tries2++) {
>  				pci_read_config_byte(dev, 0x5b, &reg5b);
>  				/* Failed ? */
>  				if ((reg5b & 0x80) == 0)

I am assuming this one is the same as for pata_hpt37x: a false positive ?

-- 
Damien Le Moal
Western Digital Research


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

* Re: [PATCH] ata: pata_hpt3x2n: prevent potential forever loop in hpt3xn_calibrate_dpll()
  2023-02-14  3:47 ` Damien Le Moal
@ 2023-02-14  7:06   ` Dan Carpenter
  0 siblings, 0 replies; 4+ messages in thread
From: Dan Carpenter @ 2023-02-14  7:06 UTC (permalink / raw)
  To: Damien Le Moal; +Cc: Sergey Shtylyov, linux-ide, kernel-janitors

On Tue, Feb 14, 2023 at 12:47:52PM +0900, Damien Le Moal wrote:
> On 2/1/23 23:10, Dan Carpenter wrote:
> > This code accidentally reuses "tries" as the iterator for both the inside
> > and outside loops.  It means that the potentially the "tries" could be
> > reset to 0x1000 and never reach 0x5000.
> > 
> > Fixes: 669a5db411d8 ("[libata] Add a bunch of PATA drivers.")
> > Signed-off-by: Dan Carpenter <error27@gmail.com>
> > ---
> >  drivers/ata/pata_hpt3x2n.c | 4 ++--
> >  1 file changed, 2 insertions(+), 2 deletions(-)
> > 
> > diff --git a/drivers/ata/pata_hpt3x2n.c b/drivers/ata/pata_hpt3x2n.c
> > index 617c95522f43..447dc287a2d4 100644
> > --- a/drivers/ata/pata_hpt3x2n.c
> > +++ b/drivers/ata/pata_hpt3x2n.c
> > @@ -380,14 +380,14 @@ static int hpt3xn_calibrate_dpll(struct pci_dev *dev)
> >  {
> >  	u8 reg5b;
> >  	u32 reg5c;
> > -	int tries;
> > +	int tries, tries2;
> >  
> >  	for (tries = 0; tries < 0x5000; tries++) {
> >  		udelay(50);
> >  		pci_read_config_byte(dev, 0x5b, &reg5b);
> >  		if (reg5b & 0x80) {
> >  			/* See if it stays set */
> > -			for (tries = 0; tries < 0x1000; tries++) {
> > +			for (tries2 = 0; tries2 < 0x1000; tries2++) {
> >  				pci_read_config_byte(dev, 0x5b, &reg5b);
> >  				/* Failed ? */
> >  				if ((reg5b & 0x80) == 0)
> 
> I am assuming this one is the same as for pata_hpt37x: a false positive ?

Yes, sorry.

regards,
dan carpenter


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

end of thread, other threads:[~2023-02-14  7:07 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-02-01 14:10 [PATCH] ata: pata_hpt3x2n: prevent potential forever loop in hpt3xn_calibrate_dpll() Dan Carpenter
2023-02-01 15:02 ` Sergey Shtylyov
2023-02-14  3:47 ` Damien Le Moal
2023-02-14  7:06   ` Dan Carpenter

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).