Bug 188791 - Function lanai_dev_open() does not set error code when the call to ioremap() fails.
Summary: Function lanai_dev_open() does not set error code when the call to ioremap() ...
Status: RESOLVED CODE_FIX
Alias: None
Product: Drivers
Classification: Unclassified
Component: Other (show other bugs)
Hardware: All Linux
: P1 normal
Assignee: drivers_other
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2016-11-25 10:59 UTC by bianpan
Modified: 2017-05-11 23:55 UTC (History)
0 users

See Also:
Kernel Version: linux-4.9-rc6
Subsystem:
Regression: No
Bisected commit-id:


Attachments
The patch fixes the bug (1.05 KB, patch)
2017-05-11 23:55 UTC, bianpan
Details | Diff

Description bianpan 2016-11-25 10:59:01 UTC
Function ioremap() returns a NULL pointer on failures. In function lanai_dev_open() defined in file drivers/atm/lanai.c, function ioremap() is called and its return value is checked against NULL (at line 2144). If the return value is NULL, it will jump to label "error_pci", and returns the value of variable result. The value of result is 0 after the check of it at line 2140. As a result, 0 may be returned even if the call to ioremap() fails. Maybe it is better to explicitly assign "-ENOMEM" to variable result before the jump instruction at line 2146. Codes related to this bug are summarised as follows.

lanai_dev_open @@ drivers/atm/lanai.c
2112 /* setup a newly detected device */
2113 static int lanai_dev_open(struct atm_dev *atmdev)
2114 {
2115     struct lanai_dev *lanai = (struct lanai_dev *) atmdev->dev_data;
2116     unsigned long raw_base;
2117     int result;
         ...
2139     /* 3.2: PCI initialization */
2140     if ((result = lanai_pci_start(lanai)) != 0)
2141         goto error;
2142     raw_base = lanai->pci->resource[0].start;
2143     lanai->base = (bus_addr_t) ioremap(raw_base, LANAI_MAPPING_SIZE);
2144     if (lanai->base == NULL) {
2145         printk(KERN_ERR DEV_LABEL ": couldn't remap I/O space\n");
2146         goto error_pci;       // insert "result = -ENOMEM" before this jump instruction?
2147     }
         ...
2229     return 0;
2230 
         ...
2242     error_pci:
2243     pci_disable_device(lanai->pci);
2244     error:
2245     return result;
2246 }

Thanks very much!
Comment 1 bianpan 2017-05-11 23:55:05 UTC
Created attachment 256419 [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.

Note You need to log in before you can comment on or make changes to this bug.