[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Xen-changelog] [xen-unstable] hvm: Fix PCI-passthru string parsing.
# HG changeset patch # User Keir Fraser <keir@xxxxxxxxxxxxx> # Date 1192869000 -3600 # Node ID 7231d971f78c5771655df44eb3a69837de0b701d # Parent 6df47366830c577c7dccefc20b68d7df157f454d hvm: Fix PCI-passthru string parsing. Fixes crash of xend during HVM domain ccreation. Signed-off-by: Keir Fraser <keir@xxxxxxxxxxxxx> --- tools/ioemu/hw/pass-through.c | 48 +++++++++--------------------------- tools/python/xen/lowlevel/xc/xc.c | 50 +++++++++----------------------------- 2 files changed, 25 insertions(+), 73 deletions(-) diff -r 6df47366830c -r 7231d971f78c tools/ioemu/hw/pass-through.c --- a/tools/ioemu/hw/pass-through.c Fri Oct 19 18:00:10 2007 +0100 +++ b/tools/ioemu/hw/pass-through.c Sat Oct 20 09:30:00 2007 +0100 @@ -31,48 +31,28 @@ extern FILE *logfile; static int token_value(char *token) { - token = strchr(token, 'x'); - token = token + 1; - - return ((int) strtol(token, NULL, 16)); -} - -static int first_bdf(char *pci_str, char **last, - int *seg, int *bus, int *dev, int *func) + token = strchr(token, 'x') + 1; + return strtol(token, NULL, 16); +} + +static int next_bdf(char **str, int *seg, int *bus, int *dev, int *func) { char *token; - token = strtok_r(pci_str, ",", last); + token = strchr(*str, ','); if ( !token ) return 0; + token++; *seg = token_value(token); - token = strtok_r(NULL, ",", last); + token = strchr(token, ',') + 1; *bus = token_value(token); - token = strtok_r(NULL, ",", last); + token = strchr(token, ',') + 1; *dev = token_value(token); - token = strtok_r(NULL, ",", last); + token = strchr(token, ',') + 1; *func = token_value(token); - return 1; -} - -static int next_bdf(char **last, int *seg, int *bus, int *dev, int *func) -{ - char *token; - - token = strtok_r(NULL, ",", last); - if ( !token ) - return 0; - - *seg = token_value(token); - token = strtok_r(NULL, ",", last); - *bus = token_value(token); - token = strtok_r(NULL, ",", last); - *dev = token_value(token); - token = strtok_r(NULL, ",", last); - *func = token_value(token); - + *str = token; return 1; } @@ -422,8 +402,6 @@ int pt_init(PCIBus *e_bus, char *direct_ int seg, b, d, f; struct pt_dev *pt_dev; struct pci_access *pci_access; - int get_bdf; - char *last = NULL; /* Initialize libpci */ pci_access = pci_alloc(); @@ -436,9 +414,7 @@ int pt_init(PCIBus *e_bus, char *direct_ pci_scan_bus(pci_access); /* Assign given devices to guest */ - for ( get_bdf = first_bdf(direct_pci, &last, &seg, &b, &d, &f); - get_bdf; - get_bdf = next_bdf(&last, &seg, &b, &d, &f) ) + while ( next_bdf(&direct_pci, &seg, &b, &d, &f) ) { /* Register real device with the emulated bus */ pt_dev = register_real_device(e_bus, "DIRECT PCI", PT_VIRT_DEVFN_AUTO, diff -r 6df47366830c -r 7231d971f78c tools/python/xen/lowlevel/xc/xc.c --- a/tools/python/xen/lowlevel/xc/xc.c Fri Oct 19 18:00:10 2007 +0100 +++ b/tools/python/xen/lowlevel/xc/xc.c Sat Oct 20 09:30:00 2007 +0100 @@ -531,48 +531,28 @@ static PyObject *pyxc_set_hvm_param(XcOb static int token_value(char *token) { - token = strchr(token, 'x'); - token = token + 1; - - return ((int) strtol(token, NULL, 16)); -} - -static int first_bdf(char *pci_str, char **last, - int *seg, int *bus, int *dev, int *func) + token = strchr(token, 'x') + 1; + return strtol(token, NULL, 16); +} + +static int next_bdf(char **str, int *seg, int *bus, int *dev, int *func) { char *token; - token = strtok_r(pci_str, ",", last); + token = strchr(*str, ','); if ( !token ) return 0; + token++; *seg = token_value(token); - token = strtok_r(NULL, ",", last); + token = strchr(token, ',') + 1; *bus = token_value(token); - token = strtok_r(NULL, ",", last); + token = strchr(token, ',') + 1; *dev = token_value(token); - token = strtok_r(NULL, ",", last); + token = strchr(token, ',') + 1; *func = token_value(token); - return 1; -} - -static int next_bdf(char **last, int *seg, int *bus, int *dev, int *func) -{ - char *token; - - token = strtok_r(NULL, ",", last); - if ( !token ) - return 0; - - *seg = token_value(token); - token = strtok_r(NULL, ",", last); - *bus = token_value(token); - token = strtok_r(NULL, ",", last); - *dev = token_value(token); - token = strtok_r(NULL, ",", last); - *func = token_value(token); - + *str = token; return 1; } @@ -584,17 +564,13 @@ static PyObject *pyxc_assign_device(XcOb char *pci_str; uint32_t bdf = 0; int seg, bus, dev, func; - int get_bdf; - char *last = NULL; static char *kwd_list[] = { "domid", "pci", NULL }; - if ( !PyArg_ParseTupleAndKeywords(args, kwds, "i|s", kwd_list, + if ( !PyArg_ParseTupleAndKeywords(args, kwds, "is", kwd_list, &dom, &pci_str) ) return NULL; - for ( get_bdf = first_bdf(pci_str, &last, &seg, &bus, &dev, &func); - get_bdf; - get_bdf = next_bdf(&last, &seg, &bus, &dev, &func) ) + while ( next_bdf(&pci_str, &seg, &bus, &dev, &func) ) { bdf |= (bus & 0xff) << 16; bdf |= (dev & 0x1f) << 11; _______________________________________________ Xen-changelog mailing list Xen-changelog@xxxxxxxxxxxxxxxxxxx http://lists.xensource.com/xen-changelog
|
Lists.xenproject.org is hosted with RackSpace, monitoring our |