Skip to content

Commit 25db6b7

Browse files
yliu80wenlingz
authored andcommitted
IOC Mediator: Replace strtok with strsep
Replace strtok function with strsep function. Tracked-On: #1401 Signed-off-by: Yuan Liu <yuan1.liu@intel.com> Reviewed-by: Shuo Liu <shuo.a.liu@intel.com> Acked-by: Yu Wang <yu1.wang@intel.com>
1 parent 69edccc commit 25db6b7

File tree

1 file changed

+26
-16
lines changed
  • devicemodel/hw/platform

1 file changed

+26
-16
lines changed

devicemodel/hw/platform/ioc.c

Lines changed: 26 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1548,27 +1548,37 @@ vm_resume_handler(void *arg)
15481548
int
15491549
ioc_parse(const char *opts)
15501550
{
1551-
char *tmp;
1552-
char *param = strdup(opts);
1551+
char *tmp, *str, *cpy;
15531552
int rc;
15541553

1555-
tmp = strtok(param, ",");
1556-
rc = snprintf(virtual_uart_path, sizeof(virtual_uart_path), "%s", param);
1554+
cpy = str = strdup(opts);
1555+
if (!cpy)
1556+
return -ENOMEM;
1557+
1558+
/*
1559+
* IOC mediator parameters format as below:
1560+
* <virtual_uart_path>[,<wakeup_reason>]
1561+
* For e.g. "/run/acrn/ioc_vm1,0x20"
1562+
*/
1563+
tmp = strsep(&str, ",");
1564+
if (!tmp)
1565+
goto exit;
1566+
1567+
rc = snprintf(virtual_uart_path, sizeof(virtual_uart_path), "%s", tmp);
15571568
if (rc < 0 || rc >= sizeof(virtual_uart_path))
15581569
WPRINTF("ioc gets incomplete virtual uart path:%s\r\n",
15591570
virtual_uart_path);
1560-
if (tmp != NULL) {
1561-
tmp = strtok(NULL, ",");
1562-
if (tmp != NULL) {
1563-
ioc_boot_reason = strtoul(tmp, 0, 0);
1564-
1565-
/*
1566-
* Mask invalid bits of wakeup reason for IOC mediator
1567-
*/
1568-
ioc_boot_reason &= CBC_WK_RSN_ALL;
1569-
}
1570-
}
1571-
free(param);
1571+
1572+
if (!str)
1573+
goto exit;
1574+
1575+
ioc_boot_reason = strtoul(str, 0, 0);
1576+
1577+
/* Mask invalid bits of wakeup reason for IOC mediator */
1578+
ioc_boot_reason &= CBC_WK_RSN_ALL;
1579+
1580+
exit:
1581+
free(cpy);
15721582
return 0;
15731583
}
15741584

0 commit comments

Comments
 (0)