From bb54a2c7c619d17303673b3a6801b5578477780c Mon Sep 17 00:00:00 2001 From: Peter Fang Date: Mon, 1 Apr 2019 03:43:21 -0700 Subject: [PATCH] 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 Acked-by: Anthony Xu --- devicemodel/hw/pci/virtio/virtio_mei.c | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/devicemodel/hw/pci/virtio/virtio_mei.c b/devicemodel/hw/pci/virtio/virtio_mei.c index f49dc62bf..15f5e28bf 100644 --- a/devicemodel/hw/pci/virtio/virtio_mei.c +++ b/devicemodel/hw/pci/virtio/virtio_mei.c @@ -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);