From patchwork Mon Jun 19 12:00:08 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Github ODP bot X-Patchwork-Id: 105830 Delivered-To: patch@linaro.org Received: by 10.140.91.2 with SMTP id y2csp837277qgd; Mon, 19 Jun 2017 05:01:57 -0700 (PDT) X-Received: by 10.55.124.194 with SMTP id x185mr25380204qkc.215.1497873717094; Mon, 19 Jun 2017 05:01:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1497873717; cv=none; d=google.com; s=arc-20160816; b=uoroGC+upjQXc1U6oU/qvqb5nfJkE4wsk5FP89KuJw7JmZWg1lNCRHle9I7b5qmFGY 7RZLxE3FttzKBaj+IZfRmVdSMnVckbBhLmy41BwgHXhAhPVlk1C6gNG+L4NYxYJRBJpd uC3UEbULYPV1uDXGmjR8FH8N4BuD7GvWOZee83j7oZYSt/6q58v9sfLRTGOYuNsuRZAn SH4I21ihnmtxD3iOfE/iLFWMYNmRjdo3z7aRZT9nUtksQn9rbBJQUHnBH2VcPPLA3BRd WUJaB92L6pozHlT3EfjUJ02bnp0xWBit9uNhi8X858jyQAjn66hxwmnFNhmbap0HA/4x CF4w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:subject:github-pr-num :references:in-reply-to:message-id:date:to:from:delivered-to :arc-authentication-results; bh=ef57fBxrT67lriN2Qq6358qSlWmiB06xo59/MUH8S6w=; b=LWvGdRs0i8M27F5TeMUROoCUixL5WEvVrDKfnvg0bgzSG/SLn+6p/p5ZwEqTBX8l99 R/8GuCx2TAbpjXXgEetnIisZuvf+oWMYdV2/99YZG+IcnNdBpWTGfK6qOHKF+/yzvXuQ WIGLWmMLIvIhdk4EdD2cReqJaOsC+N1YObHKTmQG4etn5+xVKb6dwoieelPWIv2x4//V jZ9hpZb6+bRz3CjuAJCLvAcqWciGYXjk/EA6RLp2ZGHLIOuC0uow8u/MNlJIG0HiB2WI 5hZiAyGl10FCWJZumBdkiXaTQTWbLnTuT3IWngBby51V3zvZlqq6VBV4hPTicyw+L3V6 yb3Q== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of lng-odp-bounces@lists.linaro.org designates 54.225.227.206 as permitted sender) smtp.mailfrom=lng-odp-bounces@lists.linaro.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=yandex.ru Return-Path: Received: from lists.linaro.org (lists.linaro.org. [54.225.227.206]) by mx.google.com with ESMTP id i185si9074251qke.182.2017.06.19.05.01.56; Mon, 19 Jun 2017 05:01:57 -0700 (PDT) Received-SPF: pass (google.com: domain of lng-odp-bounces@lists.linaro.org designates 54.225.227.206 as permitted sender) client-ip=54.225.227.206; Authentication-Results: mx.google.com; spf=pass (google.com: domain of lng-odp-bounces@lists.linaro.org designates 54.225.227.206 as permitted sender) smtp.mailfrom=lng-odp-bounces@lists.linaro.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=yandex.ru Received: by lists.linaro.org (Postfix, from userid 109) id B9CF66095D; Mon, 19 Jun 2017 12:01:56 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on ip-10-142-244-252 X-Spam-Level: X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00,FREEMAIL_FROM, RCVD_IN_DNSWL_LOW,URIBL_BLOCKED autolearn=disabled version=3.4.0 Received: from [127.0.0.1] (localhost [127.0.0.1]) by lists.linaro.org (Postfix) with ESMTP id 9D4FD60A54; Mon, 19 Jun 2017 12:01:15 +0000 (UTC) X-Original-To: lng-odp@lists.linaro.org Delivered-To: lng-odp@lists.linaro.org Received: by lists.linaro.org (Postfix, from userid 109) id 7F0A06095D; Mon, 19 Jun 2017 12:01:08 +0000 (UTC) Received: from forward3j.cmail.yandex.net (forward3j.cmail.yandex.net [5.255.227.21]) by lists.linaro.org (Postfix) with ESMTPS id 6953560A54 for ; Mon, 19 Jun 2017 12:00:44 +0000 (UTC) Received: from smtp3m.mail.yandex.net (smtp3m.mail.yandex.net [IPv6:2a02:6b8:0:2519::125]) by forward3j.cmail.yandex.net (Yandex) with ESMTP id B587C20F1C for ; Mon, 19 Jun 2017 15:00:42 +0300 (MSK) Received: from smtp3m.mail.yandex.net (localhost.localdomain [127.0.0.1]) by smtp3m.mail.yandex.net (Yandex) with ESMTP id 6890B2840F34 for ; Mon, 19 Jun 2017 15:00:33 +0300 (MSK) Received: by smtp3m.mail.yandex.net (nwsmtp/Yandex) with ESMTPSA id NGgShgVjT9-0XKqFv0t; Mon, 19 Jun 2017 15:00:33 +0300 (using TLSv1.2 with cipher ECDHE-RSA-AES128-SHA256 (128/128 bits)) (Client certificate not present) X-Yandex-Suid-Status: 1 0 From: Github ODP bot To: lng-odp@lists.linaro.org Date: Mon, 19 Jun 2017 15:00:08 +0300 Message-Id: <1497873608-11776-2-git-send-email-odpbot@yandex.ru> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1497873608-11776-1-git-send-email-odpbot@yandex.ru> References: <1497873608-11776-1-git-send-email-odpbot@yandex.ru> Github-pr-num: 47 Subject: [lng-odp] [PATCH CLOUD-DEV v1 1/1] drv: driver: fix devio registration race X-BeenThere: lng-odp@lists.linaro.org X-Mailman-Version: 2.1.16 Precedence: list List-Id: "The OpenDataPlane \(ODP\) List" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: lng-odp-bounces@lists.linaro.org Sender: "lng-odp" From: Josep Puigdemont This fixes a race condition that could arise when registering a devio. Signed-off-by: Josep Puigdemont --- /** Email created from pull request 47 (joseppc:fix-devio-race) ** https://github.com/Linaro/odp/pull/47 ** Patch: https://github.com/Linaro/odp/pull/47.patch ** Base sha: f2a1712bdb379b2eb2c6e470a2f2d9a1302f344f ** Merge commit sha: ea375d3e4ac5b446546a8e59e03f7e88ac982377 **/ platform/linux-generic/drv_driver.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/platform/linux-generic/drv_driver.c b/platform/linux-generic/drv_driver.c index 46cbdba9..3c918def 100644 --- a/platform/linux-generic/drv_driver.c +++ b/platform/linux-generic/drv_driver.c @@ -529,7 +529,7 @@ odpdrv_devio_t odpdrv_devio_register(odpdrv_devio_param_t *param) * sure no devio providing the same interface using th esame enumerator * already exists: */ - devio_list_read_lock(); + devio_list_write_lock(); devio = devio_lst.head; while (devio) { if ((strncmp(param->api_name, devio->param.api_name, @@ -539,12 +539,11 @@ odpdrv_devio_t odpdrv_devio_register(odpdrv_devio_param_t *param) ODP_ERR("a devio providing interface '%s' for devices " "of type '%s' is already registered\n!", param->api_name, param->enumr_api_name); - devio_list_read_unlock(); + devio_list_write_unlock(); return ODPDRV_DEVIO_INVALID; } devio = devio->next; } - devio_list_read_unlock(); /* allocate memory for the new devio: * If init_global has not been done yet, then, we cannot allocate @@ -561,13 +560,16 @@ odpdrv_devio_t odpdrv_devio_register(odpdrv_devio_param_t *param) if (init_global_status == UNDONE) { devio = malloc(sizeof(_odpdrv_devio_t)); - if (!devio) + if (!devio) { + devio_list_write_unlock(); return ODPDRV_DEVIO_INVALID; + } devio->pool = NULL; } else { devio = _odp_ishm_pool_alloc(list_elt_pool, sizeof(_odpdrv_devio_t)); if (!devio) { + devio_list_write_unlock(); ODP_ERR("_odp_ishm_pool_alloc failed!\n"); return ODPDRV_DEVIO_INVALID; } @@ -576,7 +578,6 @@ odpdrv_devio_t odpdrv_devio_register(odpdrv_devio_param_t *param) /* save init parameters and insert devio in list */ devio->param = *param; - devio_list_write_lock(); devio->next = devio_lst.head; devio_lst.head = devio; devio_list_write_unlock();