mirror of
https://github.com/projectacrn/acrn-hypervisor.git
synced 2025-05-31 11:25:30 +00:00
DM USB: xHCI: Fix banned API issue.
In USB mediator, sscanf, strtok and atoi API is banned, so replace them with permitted API function. Tracked-On: #1254 Signed-off-by: Yang Liang <liang3.yang@intel.com> Reviewed-by: Xiaoguang Wu <xiaoguang.wu@intel.com> Reviewed-by: Shuo Liu <shuo.a.liu@intel.com> Reviewed-by: Yonghua Huang <yonghua.huang@intel.com> Acked-by: Yu Wang <yu1.wang@intel.com>
This commit is contained in:
parent
e835f5f5d2
commit
fbaecde6bb
@ -92,6 +92,7 @@
|
||||
#include "xhci.h"
|
||||
#include "usb_pmapper.h"
|
||||
#include "vmmapi.h"
|
||||
#include "dm_string.h"
|
||||
|
||||
#undef LOG_TAG
|
||||
#define LOG_TAG "xHCI: "
|
||||
@ -3704,18 +3705,24 @@ errout:
|
||||
static int
|
||||
pci_xhci_parse_bus_port(struct pci_xhci_vdev *xdev, char *opts)
|
||||
{
|
||||
int rc = 0, cnt;
|
||||
uint32_t port, bus, index;
|
||||
int rc = 0;
|
||||
char *tstr;
|
||||
int port, bus, index;
|
||||
struct usb_devpath path;
|
||||
struct usb_native_devinfo di;
|
||||
|
||||
assert(xdev);
|
||||
assert(opts);
|
||||
|
||||
tstr = opts;
|
||||
/* 'bus-port' format */
|
||||
cnt = sscanf(opts, "%u-%u", &bus, &port);
|
||||
if (cnt == EOF || cnt < 2 || bus >= USB_NATIVE_NUM_BUS ||
|
||||
port >= USB_NATIVE_NUM_PORT) {
|
||||
if (!tstr || dm_strtoi(tstr, &tstr, 10, &bus) || *tstr != '-' ||
|
||||
dm_strtoi(tstr + 1, &tstr, 10, &port)) {
|
||||
rc = -1;
|
||||
goto errout;
|
||||
}
|
||||
|
||||
if (bus >= USB_NATIVE_NUM_BUS || port >= USB_NATIVE_NUM_PORT) {
|
||||
rc = -1;
|
||||
goto errout;
|
||||
}
|
||||
@ -3873,7 +3880,7 @@ errout:
|
||||
static int
|
||||
pci_xhci_parse_opts(struct pci_xhci_vdev *xdev, char *opts)
|
||||
{
|
||||
char *s, *t, *n;
|
||||
char *s, *t, *n, *tptr;
|
||||
int i, rc = 0;
|
||||
struct pci_xhci_option_elem *elem;
|
||||
int (*f)(struct pci_xhci_vdev *, char *);
|
||||
@ -3900,7 +3907,7 @@ pci_xhci_parse_opts(struct pci_xhci_vdev *xdev, char *opts)
|
||||
elem = xhci_option_table;
|
||||
elem_cnt = sizeof(xhci_option_table) / sizeof(*elem);
|
||||
|
||||
for (t = strtok(s, ",:"); t; t = strtok(NULL, ",:")) {
|
||||
for (t = strtok_r(s, ",:", &tptr); t; t = strtok_r(NULL, ",:", &tptr)) {
|
||||
if (isdigit(t[0])) { /* bus-port */
|
||||
if (pci_xhci_parse_bus_port(xdev, t)) {
|
||||
rc = -3;
|
||||
|
@ -82,6 +82,7 @@
|
||||
#include <fcntl.h>
|
||||
#include <unistd.h>
|
||||
#include "usb_core.h"
|
||||
#include "dm_string.h"
|
||||
|
||||
SET_DECLARE(usb_emu_set, struct usb_devemu);
|
||||
int usb_log_level;
|
||||
@ -205,7 +206,13 @@ usb_native_is_port_existed(uint8_t bus_num, uint8_t port_num)
|
||||
return 0;
|
||||
}
|
||||
|
||||
native_port_cnt = atoi(cnt);
|
||||
rc = dm_strtoi(cnt, (char **)&cnt, 10, &native_port_cnt);
|
||||
if (rc) {
|
||||
UPRINTF(LWRN, "fail to get maxchild number\r\n");
|
||||
close(fd);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (port_num > native_port_cnt || port_num < 0) {
|
||||
UPRINTF(LWRN, "invalid port_num %d, max port count %d\r\n",
|
||||
port_num, native_port_cnt);
|
||||
@ -269,6 +276,7 @@ int
|
||||
usb_get_hub_port_num(struct usb_devpath *path)
|
||||
{
|
||||
int rc, fd;
|
||||
int icnt;
|
||||
char buf[128];
|
||||
char cnt[8];
|
||||
|
||||
@ -296,5 +304,12 @@ usb_get_hub_port_num(struct usb_devpath *path)
|
||||
}
|
||||
|
||||
close(fd);
|
||||
return atoi(cnt);
|
||||
|
||||
rc = dm_strtoi(cnt, (char **)&cnt, 10, &icnt);
|
||||
if (rc) {
|
||||
UPRINTF(LWRN, "fail to get maxchild\r\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
return icnt;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user