From patchwork Mon Jun 20 13:10:44 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Marchand X-Patchwork-Id: 113124 X-Patchwork-Delegate: maxime.coquelin@redhat.com Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 331B6A0545; Mon, 20 Jun 2022 15:10:59 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 199504069C; Mon, 20 Jun 2022 15:10:59 +0200 (CEST) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by mails.dpdk.org (Postfix) with ESMTP id 533CD40151 for ; Mon, 20 Jun 2022 15:10:57 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1655730656; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=MJoAGpEtYaGdj02Hc8S59gNO9rJttvih9UQizAzwOgQ=; b=Fj/DGaIT318HlsaLnXAud2bfmvQ9ZQzO4EKpz1FZ7ERqFUciVDJsmMLUMEcG8kmRhndu+d gmysKE4uCia5M1SS80h+Ykd4uKEnvKyGGsx+o2fpzm5L5TN8JTNoh14oZ1sRVnKHhWkPxf 6Arrtxt6zQseeMl10hGS0g/zq/4E4Pw= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-444-CCsOFaCmPl2VFB0W_nuc-g-1; Mon, 20 Jun 2022 09:10:53 -0400 X-MC-Unique: CCsOFaCmPl2VFB0W_nuc-g-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 54519185A7A4; Mon, 20 Jun 2022 13:10:53 +0000 (UTC) Received: from fchome.redhat.com (unknown [10.40.193.132]) by smtp.corp.redhat.com (Postfix) with ESMTP id 10F852166B26; Mon, 20 Jun 2022 13:10:51 +0000 (UTC) From: David Marchand To: dev@dpdk.org Cc: stable@dpdk.org, Matan Azrad , Viacheslav Ovsiienko , Xueming Li , Maxime Coquelin Subject: [PATCH] vdpa/mlx5: fix leak on event thread creation Date: Mon, 20 Jun 2022 15:10:44 +0200 Message-Id: <20220620131044.1858049-1-david.marchand@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=david.marchand@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org As stated in the manual, pthread_attr_init return value should be checked. Besides, a pthread_attr_t should be destroyed once unused. In practice, we may have no leak (from what I read in glibc current code), but this may change in the future. Stick to a correct use of the API. Fixes: 5cf3fd3af4df ("vdpa/mlx5: add CPU core parameter to bind polling thread") Cc: stable@dpdk.org Signed-off-by: David Marchand Reviewed-by: Maxime Coquelin Acked-by: Matan Azrad --- Note: this is only compile tested. --- drivers/vdpa/mlx5/mlx5_vdpa_event.c | 30 +++++++++++++++++++---------- 1 file changed, 20 insertions(+), 10 deletions(-) diff --git a/drivers/vdpa/mlx5/mlx5_vdpa_event.c b/drivers/vdpa/mlx5/mlx5_vdpa_event.c index 7167a98db0..f40a68d187 100644 --- a/drivers/vdpa/mlx5/mlx5_vdpa_event.c +++ b/drivers/vdpa/mlx5/mlx5_vdpa_event.c @@ -467,6 +467,7 @@ mlx5_vdpa_cqe_event_setup(struct mlx5_vdpa_priv *priv) { int ret; rte_cpuset_t cpuset; + pthread_attr_t *attrp = NULL; pthread_attr_t attr; char name[16]; const struct sched_param sp = { @@ -476,22 +477,27 @@ mlx5_vdpa_cqe_event_setup(struct mlx5_vdpa_priv *priv) if (!priv->eventc) /* All virtqs are in poll mode. */ return 0; - pthread_attr_init(&attr); - ret = pthread_attr_setschedpolicy(&attr, SCHED_RR); + ret = pthread_attr_init(&attr); + if (ret != 0) { + DRV_LOG(ERR, "Failed to initialize thread attributes"); + goto out; + } + attrp = &attr; + ret = pthread_attr_setschedpolicy(attrp, SCHED_RR); if (ret) { DRV_LOG(ERR, "Failed to set thread sched policy = RR."); - return -1; + goto out; } - ret = pthread_attr_setschedparam(&attr, &sp); + ret = pthread_attr_setschedparam(attrp, &sp); if (ret) { DRV_LOG(ERR, "Failed to set thread priority."); - return -1; + goto out; } - ret = pthread_create(&priv->timer_tid, &attr, mlx5_vdpa_event_handle, + ret = pthread_create(&priv->timer_tid, attrp, mlx5_vdpa_event_handle, (void *)priv); if (ret) { DRV_LOG(ERR, "Failed to create timer thread."); - return -1; + goto out; } CPU_ZERO(&cpuset); if (priv->event_core != -1) @@ -501,12 +507,16 @@ mlx5_vdpa_cqe_event_setup(struct mlx5_vdpa_priv *priv) ret = pthread_setaffinity_np(priv->timer_tid, sizeof(cpuset), &cpuset); if (ret) { DRV_LOG(ERR, "Failed to set thread affinity."); - return -1; + goto out; } snprintf(name, sizeof(name), "vDPA-mlx5-%d", priv->vid); - ret = rte_thread_setname(priv->timer_tid, name); - if (ret) + if (rte_thread_setname(priv->timer_tid, name) != 0) DRV_LOG(DEBUG, "Cannot set timer thread name."); +out: + if (attrp != NULL) + pthread_attr_destroy(attrp); + if (ret != 0) + return -1; return 0; }