diff options
author | Badhri Jagan Sridharan <Badhri@google.com> | 2017-02-24 05:49:29 -0800 |
---|---|---|
committer | Badhri Jagan Sridharan <Badhri@google.com> | 2017-02-24 05:52:25 -0800 |
commit | b31cbe945338d80ffceb40694fc51d88b01ebeea (patch) | |
tree | 89b30d2bee23f8bd0d0070cf0d613f0bc040bb46 | |
parent | 393f3907ec2945824315834b14a510ab3b85f3d8 (diff) |
USB HAL: Fix infinite loop.
Bug: 35726475
Test: usb-service no longer consumes 100% CPU
Change-Id: I274caec45e7527cbacf57f9a735d711dcb481bfd
-rw-r--r-- | usb/1.0/default/Usb.cpp | 19 |
1 files changed, 12 insertions, 7 deletions
diff --git a/usb/1.0/default/Usb.cpp b/usb/1.0/default/Usb.cpp index f46ff66534..174e3c5357 100644 --- a/usb/1.0/default/Usb.cpp +++ b/usb/1.0/default/Usb.cpp @@ -172,17 +172,22 @@ rescan: ports++; } } + + if (ports == 0) { + closedir(dp); + return Status::SUCCESS; + } + names.resize(ports); rewinddir(dp); while ((ep = readdir (dp))) { - /* Check to see if new ports were added since the first pass. */ - if (current >= ports) { - rewinddir(dp); - goto rescan; - } - if (ep->d_type == DT_LNK) { + /* Check to see if new ports were added since the first pass. */ + if (current >= ports) { + rewinddir(dp); + goto rescan; + } names[current++] = ep->d_name; } } @@ -234,7 +239,7 @@ Status getPortStatusHelper (hidl_vec<PortStatus>& currentPortStatus) { if (result == Status::SUCCESS) { currentPortStatus.resize(names.size()); - for(std::vector<std::string>::size_type i = 0; i != names.size(); i++) { + for(std::vector<std::string>::size_type i = 0; i < names.size(); i++) { ALOGI("%s", names[i].c_str()); currentPortStatus[i].portName = names[i]; |