On 2019年08月16日 21:39, Dan Carpenter wrote:
On Fri, Aug 16, 2019 at 10:25:52AM +0800, Zhao Yakui wrote:
+int acrn_ioreq_create_client(unsigned short vmid,
+                            ioreq_handler_t handler,
+                            void *client_priv,
+                            char *name)
+{
+       struct acrn_vm *vm;
+       struct ioreq_client *client;
+       int client_id;
+
+       might_sleep();
+
+       vm = find_get_vm(vmid);
+       if (unlikely(!vm || !vm->req_buf)) {
+               pr_err("acrn-ioreq: failed to find vm from vmid %d\n", vmid);
+               put_vm(vm);
+               return -EINVAL;
+       }
+
+       client_id = alloc_client();
+       if (unlikely(client_id < 0)) {
+               pr_err("acrn-ioreq: vm[%d] failed to alloc ioreq client\n",
+                      vmid);
+               put_vm(vm);
+               return -EINVAL;
+       }
+
+       client = acrn_ioreq_get_client(client_id);
+       if (unlikely(!client)) {
+               pr_err("failed to get the client.\n");
+               put_vm(vm);
+               return -EINVAL;

Do we need to clean up the alloc_client() allocation?

Thanks for the review.

The function of acrn_iocreq_get_client is used to return the client for the given client_id. (The ref_count of client is also added). If it is NULL, it indicates that it is already released in another place.

In the function of acrn_ioreq_create_client, we don't need to clean up the alloc_client as it always exists in course of creating_client.


regards,
dan carpenter

+       }
+
+       if (handler) {
+               client->handler = handler;
+               client->acrn_create_kthread = true;
+       }
+
+       client->ref_vm = vm;
+       client->vmid = vmid;
+       client->client_priv = client_priv;
+       if (name)
+               strncpy(client->name, name, sizeof(client->name) - 1);
+       rwlock_init(&client->range_lock);
+       INIT_LIST_HEAD(&client->range_list);
+       init_waitqueue_head(&client->wq);
+
+       /* When it is added to ioreq_client_list, the refcnt is increased */
+       spin_lock_bh(&vm->ioreq_client_lock);
+       list_add(&client->list, &vm->ioreq_client_list);
+       spin_unlock_bh(&vm->ioreq_client_lock);
+
+       pr_info("acrn-ioreq: created ioreq client %d\n", client_id);
+
+       return client_id;
+}

_______________________________________________
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel

Reply via email to