* [PATCH] ata: pata_hpt37x: fix potential forever loop
@ 2023-02-01 14:10 Dan Carpenter
2023-02-01 14:59 ` Sergey Shtylyov
0 siblings, 1 reply; 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 the "tries" iterator for both the inside
and outside loops. It could result in a forever loop if the "tries"
variable gets reset to 0x1000 and never reaches 0x5000.
Fixes: 669a5db411d8 ("[libata] Add a bunch of PATA drivers.")
Signed-off-by: Dan Carpenter <error27@gmail.com>
---
drivers/ata/pata_hpt37x.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/drivers/ata/pata_hpt37x.c b/drivers/ata/pata_hpt37x.c
index ce3c5eaa7e76..35be9a095b18 100644
--- a/drivers/ata/pata_hpt37x.c
+++ b/drivers/ata/pata_hpt37x.c
@@ -621,14 +621,14 @@ static int hpt37x_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, ®5b);
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, ®5b);
/* Failed ? */
if ((reg5b & 0x80) == 0)
--
2.35.1
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH] ata: pata_hpt37x: fix potential forever loop
2023-02-01 14:10 [PATCH] ata: pata_hpt37x: fix potential forever loop Dan Carpenter
@ 2023-02-01 14:59 ` Sergey Shtylyov
2023-02-01 17:18 ` Sergey Shtylyov
0 siblings, 1 reply; 4+ messages in thread
From: Sergey Shtylyov @ 2023-02-01 14:59 UTC (permalink / raw)
To: Dan Carpenter; +Cc: Damien Le Moal, linux-ide, kernel-janitors
Hello!
On 2/1/23 5:10 PM, Dan Carpenter wrote:
> This code accidentally reuses the "tries" iterator for both the inside
> and outside loops. It could result in a forever loop if the "tries"
> variable gets reset to 0x1000 and never reaches 0x5000.
>
> Fixes: 669a5db411d8 ("[libata] Add a bunch of PATA drivers.")
> Signed-off-by: Dan Carpenter <error27@gmail.com>
> ---
> drivers/ata/pata_hpt37x.c | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/ata/pata_hpt37x.c b/drivers/ata/pata_hpt37x.c
> index ce3c5eaa7e76..35be9a095b18 100644
> --- a/drivers/ata/pata_hpt37x.c
> +++ b/drivers/ata/pata_hpt37x.c
> @@ -621,14 +621,14 @@ static int hpt37x_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, ®5b);
> 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, ®5b);
> /* Failed ? */
> if ((reg5b & 0x80) == 0)
Looks like Alan tried to "fix" the DPLL calibration code imported from drivers/ide/hpt366.c
and failed at that... :-) The iriginal code has 2 sequential loops (thus 'tries' could be used
for both). In principle, I agree with a simplistic patch:
Reviewed-by: Sergey Shtylyov <s.shtylyov@omp.ru>
MBR, Sergey
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] ata: pata_hpt37x: fix potential forever loop
2023-02-01 14:59 ` Sergey Shtylyov
@ 2023-02-01 17:18 ` Sergey Shtylyov
2023-02-02 6:42 ` Dan Carpenter
0 siblings, 1 reply; 4+ messages in thread
From: Sergey Shtylyov @ 2023-02-01 17:18 UTC (permalink / raw)
To: Dan Carpenter; +Cc: Damien Le Moal, linux-ide, kernel-janitors
On 2/1/23 5:59 PM, Sergey Shtylyov wrote:
[...]
>> This code accidentally reuses the "tries" iterator for both the inside
>> and outside loops. It could result in a forever loop if the "tries"
>> variable gets reset to 0x1000 and never reaches 0x5000.
Have you actually seen this happening?
>>
>> Fixes: 669a5db411d8 ("[libata] Add a bunch of PATA drivers.")
>> Signed-off-by: Dan Carpenter <error27@gmail.com>
>> ---
>> drivers/ata/pata_hpt37x.c | 4 ++--
>> 1 file changed, 2 insertions(+), 2 deletions(-)
>>
>> diff --git a/drivers/ata/pata_hpt37x.c b/drivers/ata/pata_hpt37x.c
>> index ce3c5eaa7e76..35be9a095b18 100644
>> --- a/drivers/ata/pata_hpt37x.c
>> +++ b/drivers/ata/pata_hpt37x.c
>> @@ -621,14 +621,14 @@ static int hpt37x_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, ®5b);
>> 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, ®5b);
>> /* Failed ? */
>> if ((reg5b & 0x80) == 0)
>
> Looks like Alan tried to "fix" the DPLL calibration code imported from drivers/ide/hpt366.c
> and failed at that... :-) The iriginal code has 2 sequential loops (thus 'tries' could be used
> for both). In principle, I agree with a simplistic patch:
Err, wait! Once we have bit 7 of the PCI register at 0x5b set, we'll never
return to the outer loop... So, I'm ot seeing the bug here...
> Reviewed-by: Sergey Shtylyov <s.shtylyov@omp.ru>
So I have to take this back...
MBR, Sergey
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] ata: pata_hpt37x: fix potential forever loop
2023-02-01 17:18 ` Sergey Shtylyov
@ 2023-02-02 6:42 ` Dan Carpenter
0 siblings, 0 replies; 4+ messages in thread
From: Dan Carpenter @ 2023-02-02 6:42 UTC (permalink / raw)
To: Sergey Shtylyov; +Cc: Damien Le Moal, linux-ide, kernel-janitors
On Wed, Feb 01, 2023 at 08:18:13PM +0300, Sergey Shtylyov wrote:
> On 2/1/23 5:59 PM, Sergey Shtylyov wrote:
> [...]
> >> This code accidentally reuses the "tries" iterator for both the inside
> >> and outside loops. It could result in a forever loop if the "tries"
> >> variable gets reset to 0x1000 and never reaches 0x5000.
>
> Have you actually seen this happening?
>
No, this is from static analysis.
drivers/ata/pata_hpt3x2n.c:390 hpt3xn_calibrate_dpll() warn: reusing outside iterator: 'tries'
You're right that this is a false positive. I thought I had addressed
that particular type of false positive so the check wouldn't warn about
it but apparently I hadn't. Sorry!
Thanks again for reviewing this.
regards,
dan carpenter
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2023-02-02 6:42 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_hpt37x: fix potential forever loop Dan Carpenter
2023-02-01 14:59 ` Sergey Shtylyov
2023-02-01 17:18 ` Sergey Shtylyov
2023-02-02 6:42 ` 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).