+static int vi2c_parse(VuI2c *i2c)
+{
+ uint16_t client_addr[MAX_I2C_VDEV];
+ int32_t n_adapter = 0, n_client;
+ int64_t addr, bus;
+ const char *cp, *t;
+
+ while (device_list) {
+ /* Read <bus>:<client_addr>[:<client_addr>] entries one by one */
+ cp = strsep(&device_list, ",");
+
+ if (!cp || *cp =='\0') {
+ break;
+ }
+
+ if (n_adapter == MAX_I2C_ADAPTER) {
+ g_printerr("too many adapter (%d), only support %d \n", n_adapter,
+ MAX_I2C_ADAPTER);
+ goto out;
+ }
+
+ if (qemu_strtol(cp, &t, 10, &bus) || bus < 0) {
+ g_printerr("Invalid bus number %s\n", cp);
+ goto out;
+ }
+
+ cp = t;
+ n_client = 0;
+
+ /* Parse clients <client_addr>[:<client_addr>] entries one by one */
+ while (cp != NULL && *cp !='\0') {
+ if (*cp == ':')
+ cp++;
+
+ if (n_client == MAX_I2C_VDEV) {
+ g_printerr("too many devices (%d), only support %d \n",
+ n_client, MAX_I2C_VDEV);
+ goto out;
+ }
+
+ if (qemu_strtol(cp, &t, 16, &addr) || addr < 0 || addr >
MAX_I2C_VDEV) {
+ g_printerr("Invalid address %s : %lx\n", cp, addr);
+ goto out;
+ }
+
+ client_addr[n_client++] = addr;
+ cp = t;
+ if (verbose) {
+ g_print("i2c adapter %ld:0x%lx\n", bus, addr);
+ }
+ }
+
+ i2c->adapter[n_adapter] = vi2c_create_adapter(bus, client_addr,
n_client);
+ if (!i2c->adapter[n_adapter])
+ goto out;
+ n_adapter++;
+ }
+
+ if (!n_adapter) {
+ g_printerr("Failed to add any adapters\n");
+ return -1;
+ }
+
+ i2c->adapter_num = n_adapter;