From mboxrd@z Thu Jan 1 00:00:00 1970 From: yakui.zhao@intel.com (Zhao, Yakui) Date: Mon, 19 Aug 2019 12:54:04 +0800 Subject: [RFC PATCH 11/15] drivers/acrn: add the support of handling emulated ioreq In-Reply-To: <20190816133511.GC3632@kadam> References: <1565922356-4488-1-git-send-email-yakui.zhao@intel.com> <1565922356-4488-12-git-send-email-yakui.zhao@intel.com> <20190816133511.GC3632@kadam> Message-ID: <0986d89b-c428-6e66-315c-dc2343ec4699@intel.com> List-Id: Linux Driver Project Developer List On 2019?08?16? 21:39, Dan Carpenter wrote: > On Fri, Aug 16, 2019@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; >> +} >