dm: mei: use LIST_FOREACH() to traverse lists

Remove the uses of LIST_FIRST() and LIST_NEXT() plus an extra pointer.

Also, call LIST_INIT() in vmei_me_client_destroy_host_clients() before
releasing the mutex.

v1 -> v2:
- split the cleanup commit into two parts

Tracked-On: #2763
Signed-off-by: Peter Fang <peter.fang@intel.com>
Acked-by: Anthony Xu <anthony.xu@intel.com>
This commit is contained in:
Peter Fang 2019-04-01 03:43:21 -07:00 committed by wenlingz
parent 18aebc0196
commit bb54a2c7c6
1 changed files with 5 additions and 11 deletions

View File

@ -502,17 +502,14 @@ vmei_del_me_client(struct vmei_me_client *mclient)
static void
vmei_me_client_destroy_host_clients(struct vmei_me_client *mclient)
{
struct vmei_host_client *e, *n;
struct vmei_host_client *e;
pthread_mutex_lock(&mclient->list_mutex);
e = LIST_FIRST(&mclient->connections);
while (e) {
n = LIST_NEXT(e, list);
LIST_FOREACH(e, &mclient->connections, list) {
vmei_host_client_put(e);
e = n;
}
pthread_mutex_unlock(&mclient->list_mutex);
LIST_INIT(&mclient->connections);
pthread_mutex_unlock(&mclient->list_mutex);
}
static void
@ -645,14 +642,11 @@ vmei_find_host_client(struct virtio_mei *vmei,
static void vmei_free_me_clients(struct virtio_mei *vmei)
{
struct vmei_me_client *e, *n;
struct vmei_me_client *e;
pthread_mutex_lock(&vmei->list_mutex);
e = LIST_FIRST(&vmei->active_clients);
while (e) {
n = LIST_NEXT(e, list);
LIST_FOREACH(e, &vmei->active_clients, list) {
vmei_me_client_put(e);
e = n;
}
LIST_INIT(&vmei->active_clients);
pthread_mutex_unlock(&vmei->list_mutex);