Bug 188931

Summary: Function hfc4s8s_probe() does not set error code when the call to request_region() fails
Product: Drivers Reporter: bianpan (bianpan2010)
Component: ISDNAssignee: drivers_isdn
Status: RESOLVED CODE_FIX    
Severity: normal    
Priority: P1    
Hardware: All   
OS: Linux   
Kernel Version: linux-4.9-rc6 Subsystem:
Regression: No Bisected commit-id:
Attachments: The patch fixes the bug

Description bianpan 2016-11-25 11:09:38 UTC
Function request_region() returns a NULL pointer on failures. In the function hfc4s8s_probe() defined in file drivers/isdn/hisax/hfc4s8s_l1.c, it is called and its return value is checked against NULL. When the return value is NULL, the control flow jumps to label "out" and returns variable err. However, the value of variable err is 0. The check of err at line 1484 guarantees that the value of err must be 0 when request_region() is called. As a result, hfc4s8s_probe() will return 0 (indicates success) even if request_region() fails. Maybe it is better to explicitly assign "-ENOMEM" to err when request_region() returns a NULL pointer. Codes and comments related to this bug are summarised as below.

hfc4s8s_probe @@ drivers/isdn/hisax/hfc4s8s_l1.c
1469 static int
1470 hfc4s8s_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
1471 {
1472     int err = -ENOMEM;
         ...
1482     err = pci_enable_device(pdev);
1483 
1484     if (err)
1485         goto out;
         ...
1498     if (!request_region(hw->iobase, 8, hw->card_name)) {
1499         printk(KERN_INFO
1500                "HFC-4S/8S: failed to request address space at 0x%04x\n",
1501                hw->iobase);
             // insert "err = -ENOMEM;" here?
1502         goto out;
1503     }
         ...
1511 out:
1512     kfree(hw);
1513     return (err);
1514 }

Thanks very much!
Comment 1 bianpan 2017-05-12 00:11:36 UTC
Created attachment 256437 [details]
The patch fixes the bug

The patch has been merged into the latest version of the Linux kernel. So I will close the bug.