dm: mei: destroy mutex attribute on error path

Simplify the flow by adding mutex_type variable
and call pthread_mutexattr_destroy() on the error path.

Tracked-On: #1630
Signed-off-by: Tomas Winkler <tomas.winkler@intel.com>
Signed-off-by: Alexander Usyskin <alexander.usyskin@intel.com>
This commit is contained in:
Tomas Winkler 2018-10-29 00:38:14 +02:00 committed by lijinxia
parent 8abc931791
commit b4fbef4659
1 changed files with 11 additions and 14 deletions

View File

@ -2123,6 +2123,7 @@ vmei_init(struct vmctx *ctx, struct pci_vdev *dev, char *opts)
struct virtio_mei *vmei;
char tname[MAXCOMLEN + 1];
pthread_mutexattr_t attr;
int mutex_type;
int i, rc;
char *endptr = NULL;
char *opt;
@ -2197,21 +2198,17 @@ init:
goto fail;
}
if (virtio_uses_msix()) {
rc = pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_DEFAULT);
if (rc) {
WPRINTF("init: mutexattr_settype failed, error %d!\n",
rc);
goto fail;
}
} else {
rc = pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE);
if (rc) {
WPRINTF("init: mutexattr_settype failed, error %d!\n",
rc);
goto fail;
}
mutex_type = virtio_uses_msix() ?
PTHREAD_MUTEX_DEFAULT :
PTHREAD_MUTEX_RECURSIVE;
rc = pthread_mutexattr_settype(&attr, mutex_type);
if (rc) {
pthread_mutexattr_destroy(&attr);
WPRINTF("init: mutexattr_settype failed, error %d!\n", rc);
goto fail;
}
rc = pthread_mutex_init(&vmei->mutex, &attr);
pthread_mutexattr_destroy(&attr);
if (rc) {