From patchwork Sun Sep 22 03:28:51 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ben Russell X-Patchwork-Id: 11155655 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 1591113B1 for ; Sun, 22 Sep 2019 03:32:18 +0000 (UTC) Received: from alsa0.perex.cz (alsa0.perex.cz [77.48.224.243]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 9D514214AF for ; Sun, 22 Sep 2019 03:32:17 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=alsa-project.org header.i=@alsa-project.org header.b="McEGfgGZ"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="YcfQt9mY" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 9D514214AF Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=alsa-devel-bounces@alsa-project.org Received: from alsa1.perex.cz (alsa1.perex.cz [207.180.221.201]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by alsa0.perex.cz (Postfix) with ESMTPS id 669E6167C; Sun, 22 Sep 2019 05:31:25 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa0.perex.cz 669E6167C DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alsa-project.org; s=default; t=1569123135; bh=AgOp8PB3GhQN7kwG4kCpv8lgZgAiWOPtqsVswqWWXOs=; h=From:To:Date:In-Reply-To:References:Cc:Subject:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=McEGfgGZUlsf0I2UqF/k99U9iuuks5XaS7mzRWv+5wNcxPZKhtTKc66xo5BQ2mm31 XpeAusmIYXVrVefrqOqIs1Pvgw2cH/wEVvzyX8Jwo9scwIWa2EhGo5c8i219y//vJs zkoqYKOwUpZ7voA3rQ1VIK0coxaJas+qocn4KfTs= Received: from alsa1.perex.cz (localhost.localdomain [127.0.0.1]) by alsa1.perex.cz (Postfix) with ESMTP id B1707F80535; Sun, 22 Sep 2019 05:30:31 +0200 (CEST) X-Original-To: alsa-devel@alsa-project.org Delivered-To: alsa-devel@alsa-project.org Received: by alsa1.perex.cz (Postfix, from userid 50401) id CCBD8F805AF; Sun, 22 Sep 2019 05:30:30 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on alsa1.perex.cz X-Spam-Level: X-Spam-Status: No, score=-0.1 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FROM,SPF_HELO_NONE,SPF_PASS autolearn=disabled version=3.4.0 Received: from mail-pl1-x643.google.com (mail-pl1-x643.google.com [IPv6:2607:f8b0:4864:20::643]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by alsa1.perex.cz (Postfix) with ESMTPS id ED330F8045F for ; Sun, 22 Sep 2019 05:30:27 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa1.perex.cz ED330F8045F Authentication-Results: alsa1.perex.cz; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="YcfQt9mY" Received: by mail-pl1-x643.google.com with SMTP id d22so3650362pls.0 for ; Sat, 21 Sep 2019 20:30:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=bFDDbF+0vBNAsN/PAoKiFNvh9MeZl4xEMIXmuEGtX1U=; b=YcfQt9mYJFivEnqLxUvANJEdacwplwUYnMBsGs8R4u675XKepAc6N3f0768Z6wRMEO bOHFEOkFkKQB3W1Z0Duq1v/9dHrKgGpuvErzlk42WMOXoRIOoJmNO+PcIQ32QcEGNDco Gjyx/+6opc1LtWAldiN7gg4lsf/E5Zq1OgySbFK7u4h4X9Jq1iSksVM2YnLJs21nc1NP Yen8v+1xNw+j8iNjoeCS8obiu/slAP3PRIUUNoNTAedMm6i7gl23J39diIxnz0lD4rA0 7HsqiqYM+Rn6kZP1S2hW1OEynRpkT9L20iB6qwtIbQ2ujln5/r+hQX8ZCmjLk8xrSXud TuQg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=bFDDbF+0vBNAsN/PAoKiFNvh9MeZl4xEMIXmuEGtX1U=; b=eP86Z8+XBqmLCJuVhsdAfxw8QgeIuYPzxtkUDrLxwthCm/bTJysN7OuxzbHAlsiJHV aOTTkRcqXInZ5Ggx/ajfp63YupHMokWUVwowzFAWqSO8uHwrPxNzBjbaZKM4ZAo698Os qP8tvnskG39YQ4QZKf+WzS5fIcP34rPWCSCDvN5+9U/dmUqNia3J5AnBk4/MPsHuzIF3 dUGodMIyb1VMt3fvH+Wq+rRSz6vyT0a3mmIkQdXEu8GkmOjrrHKlouHBY/f+ty4RWMZ3 MQS+khrBpiLvdoyXqTBUfJ9w/KUmzAolsMZzGmW0639XDHMPiiOd9X2n/rRJFJQa9+VJ IqUA== X-Gm-Message-State: APjAAAUVmikWPaoYblfI8asgcPy84la284LNlwpWEMF0RAbUphKPTRc1 W8lYxF2JentnssuHMhl9KNGLb7dD X-Google-Smtp-Source: APXvYqzpkeau7iPotfCVdvR8aqHq+xYEPy/b+4k7+v000GKUzeAvNUWmrsWh2ak5RvVE9jGneISedA== X-Received: by 2002:a17:902:a715:: with SMTP id w21mr24284048plq.274.1569123026278; Sat, 21 Sep 2019 20:30:26 -0700 (PDT) Received: from localhost.localdomain ([2407:7000:aa04:fb00:ce0f:a0bf:1ece:a196]) by smtp.gmail.com with ESMTPSA id l12sm4559532pgs.44.2019.09.21.20.30.24 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 21 Sep 2019 20:30:25 -0700 (PDT) From: Ben Russell To: alsa-devel@alsa-project.org Date: Sun, 22 Sep 2019 15:28:51 +1200 Message-Id: <20190922032853.6123-2-thematrixeatsyou@gmail.com> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20190922032853.6123-1-thematrixeatsyou@gmail.com> References: <20190922032853.6123-1-thematrixeatsyou@gmail.com> MIME-Version: 1.0 Cc: Ben Russell Subject: [alsa-devel] [PATCH 1/3] pcm_local: Add snd_pcm_is_locked X-BeenThere: alsa-devel@alsa-project.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: "Alsa-devel mailing list for ALSA developers - http://www.alsa-project.org" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: alsa-devel-bounces@alsa-project.org Sender: "Alsa-devel" This is needed in preparation for a fix to be applied to pcm_ioplug which will be in a following commit. Signed-off-by: Ben Russell --- src/pcm/pcm_local.h | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/src/pcm/pcm_local.h b/src/pcm/pcm_local.h index 05ed935f..649d84f2 100644 --- a/src/pcm/pcm_local.h +++ b/src/pcm/pcm_local.h @@ -1171,9 +1171,41 @@ static inline void snd_pcm_unlock(snd_pcm_t *pcm) if (pcm->lock_enabled && pcm->need_lock) pthread_mutex_unlock(&pcm->lock); } + +/* + * snd_pcm_is_locked() is used to determine if the lock is currently held. + * It is mostly provided as a workaround for pcm_ioplug, which otherwise would + * for some functions assume that the plugin is locked even when it isn't. + * + * If $LIBASOUND_THREAD_SAFE=0 is set then this always returns 0 as there + * is no mutex in that case. + */ +static inline int snd_pcm_is_locked(snd_pcm_t *pcm) +{ + int trylock_result; + int unlock_result; + + if (pcm->lock_enabled) { + trylock_result = pthread_mutex_trylock(&pcm->lock); + assert(trylock_result == 0 || trylock_result == EBUSY); + if (trylock_result == 0) { + /* we managed to grab the lock; therefore, it wasn't locked */ + unlock_result = pthread_mutex_unlock(&pcm->lock); + assert(unlock_result == 0); + return 0; + } else { + /* we failed to grab the lock; therefore, it was locked */ + return 1; + } + } else { + return 0; + } +} + #else /* THREAD_SAFE_API */ #define __snd_pcm_lock(pcm) do {} while (0) #define __snd_pcm_unlock(pcm) do {} while (0) #define snd_pcm_lock(pcm) do {} while (0) #define snd_pcm_unlock(pcm) do {} while (0) +#define snd_pcm_is_locked(pcm) 0 #endif /* THREAD_SAFE_API */ From patchwork Sun Sep 22 03:28:52 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ben Russell X-Patchwork-Id: 11155657 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 6208F13B1 for ; Sun, 22 Sep 2019 03:33:03 +0000 (UTC) Received: from alsa0.perex.cz (alsa0.perex.cz [77.48.224.243]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id E8B0120B7C for ; Sun, 22 Sep 2019 03:33:02 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=alsa-project.org header.i=@alsa-project.org header.b="m2hs+ted"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Mk76p2jA" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org E8B0120B7C Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=alsa-devel-bounces@alsa-project.org Received: from alsa1.perex.cz (alsa1.perex.cz [207.180.221.201]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by alsa0.perex.cz (Postfix) with ESMTPS id 1A20E167E; Sun, 22 Sep 2019 05:32:11 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa0.perex.cz 1A20E167E DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alsa-project.org; s=default; t=1569123181; bh=guCZ9jwqFBT3VNsXlIEQJD87yEUR+A7//eSZChQJpRw=; h=From:To:Date:In-Reply-To:References:Cc:Subject:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=m2hs+tedtgz6DeGcXwYjsk+vwk++e+x9aatsDc0usXNYUmwc2tTAPDZIYjxTWzKeS degDhiWSWQiKJExcHqnoUoyGDG5zlxSPCsRmvlabTqmDdvYkG0O+00xXjKudx8g2Xr nx6sJSADW/a7uB6fx0c3aMO9ORWpPbErAK1QfVz0= Received: from alsa1.perex.cz (localhost.localdomain [127.0.0.1]) by alsa1.perex.cz (Postfix) with ESMTP id 5A7E7F802BD; Sun, 22 Sep 2019 05:30:36 +0200 (CEST) X-Original-To: alsa-devel@alsa-project.org Delivered-To: alsa-devel@alsa-project.org Received: by alsa1.perex.cz (Postfix, from userid 50401) id 8B63DF805F9; Sun, 22 Sep 2019 05:30:34 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on alsa1.perex.cz X-Spam-Level: X-Spam-Status: No, score=-0.1 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FROM,SPF_HELO_NONE,SPF_PASS autolearn=disabled version=3.4.0 Received: from mail-pg1-x543.google.com (mail-pg1-x543.google.com [IPv6:2607:f8b0:4864:20::543]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by alsa1.perex.cz (Postfix) with ESMTPS id 07196F805F8 for ; Sun, 22 Sep 2019 05:30:31 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa1.perex.cz 07196F805F8 Authentication-Results: alsa1.perex.cz; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Mk76p2jA" Received: by mail-pg1-x543.google.com with SMTP id s1so4868816pgv.8 for ; Sat, 21 Sep 2019 20:30:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=jD3xxhG1L728SQa4pM1ums3WMPLs7qw0wrrpC+LwPYk=; b=Mk76p2jAX2GCB/ZH6yCv+R5lK2DENBPTTgBdKoWlxt7Z/DKlnhatq/xK2czhBWDx+Y yddyFd/W+aX+9a9eGIkE5nyGcZnwh3fHZ+ZRvEB2GSIkwb2C7gqqG0XHGymchgs1+yD4 MgISbmiAWb06yunQLeJGGPDcaiUEdUuvCNPwW/Kf3fs3flrbz5UFGlxcvQdMLe/dyfHV hFGHutuLabbp6lZ2w1KAZF/EqdVtSSskDK8yQj/NVOA//TjOxFiqkge0Has6INRc99+5 RXBa4aiQss15BluA34Tr0sObcHlC8lL+UgkQ09k1KKRHD0mrFiMXWGYlZXbDTn9uuQiR L4wg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=jD3xxhG1L728SQa4pM1ums3WMPLs7qw0wrrpC+LwPYk=; b=NW2Ww2MmBZ0aopAqrRjb5+BD5XFXg+Iw6KS3EnMV/7b0Cd2cgHUyUGmafjhFTqF8za VrJ1jCZ4BDJLoCqFP6kEvcaAaIW6XCEpQiTh6Sm/aWVomkGfSbQn+gF2awn/dIq8EsnP R3AOsciN1N8mdi6ohne+L8H8p6nYK/ulAJdvXlhS/cN6HI3q6eSxgyVwGOOReg8s3eN8 ZG+qI5PcKlIdJrAY771MWgZNvwp1LQB/KyPVdiJ5CuFJP0kCFjXwhCi9sBGOCOMLk9CY v5Mh3bIEqP/5Rodlo0AtO1rqPh7obk7iEAPLhZcd1DpjZX0k6dd/qnZbdoSzVA/HIH/O 4OTA== X-Gm-Message-State: APjAAAXxyRtIrY2V2R0c7neKhTnFTrGOsOyYY/x3DmYny0QWQ1zrRgKA +NswkqpJK/Qo5WXeaEP5mkJpxIAw X-Google-Smtp-Source: APXvYqwtbfJzhN0Ot2TCvMDRPWivLZO0XE905Vu9fcnTqsIwbGYbb1uqbMT0cSBnFs784Mg40HG60g== X-Received: by 2002:a62:1890:: with SMTP id 138mr27143868pfy.161.1569123029441; Sat, 21 Sep 2019 20:30:29 -0700 (PDT) Received: from localhost.localdomain ([2407:7000:aa04:fb00:ce0f:a0bf:1ece:a196]) by smtp.gmail.com with ESMTPSA id l12sm4559532pgs.44.2019.09.21.20.30.27 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 21 Sep 2019 20:30:28 -0700 (PDT) From: Ben Russell To: alsa-devel@alsa-project.org Date: Sun, 22 Sep 2019 15:28:52 +1200 Message-Id: <20190922032853.6123-3-thematrixeatsyou@gmail.com> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20190922032853.6123-1-thematrixeatsyou@gmail.com> References: <20190922032853.6123-1-thematrixeatsyou@gmail.com> MIME-Version: 1.0 Cc: Ben Russell Subject: [alsa-devel] [PATCH 2/3] pcm_ioplug: Don't unlock+lock if we're not locked X-BeenThere: alsa-devel@alsa-project.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: "Alsa-devel mailing list for ALSA developers - http://www.alsa-project.org" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: alsa-devel-bounces@alsa-project.org Sender: "Alsa-devel" This fixes a deadlock when using the pcm_jack plugin via a plug. Some snd_pcm_ioplug_* functions assumed that they were being called with the pcm mutex locked, and would perform an unlock-act-lock sequence in order to allow the relevant function to lock the mutex itself. If the mutex was not locked before calling these functions, it would silently fail on unlocking the mutex, and then erroneously leave the mutex locked as it left the function. This patch checks to see if the mutex is locked before attempting the unlock-act-lock sequence. If the mutex is not locked when entering these functions, then we act and leave the mutex unlocked. Signed-off-by: Ben Russell --- src/pcm/pcm_ioplug.c | 50 +++++++++++++++++++++++++++++++------------- 1 file changed, 35 insertions(+), 15 deletions(-) diff --git a/src/pcm/pcm_ioplug.c b/src/pcm/pcm_ioplug.c index a437ca32..a94ecd96 100644 --- a/src/pcm/pcm_ioplug.c +++ b/src/pcm/pcm_ioplug.c @@ -164,9 +164,13 @@ static int snd_pcm_ioplug_prepare(snd_pcm_t *pcm) snd_pcm_ioplug_reset(pcm); if (io->data->callback->prepare) { - snd_pcm_unlock(pcm); /* to avoid deadlock */ - err = io->data->callback->prepare(io->data); - snd_pcm_lock(pcm); + if (snd_pcm_is_locked(pcm)) { + snd_pcm_unlock(pcm); /* to avoid deadlock */ + err = io->data->callback->prepare(io->data); + snd_pcm_lock(pcm); + } else { + err = io->data->callback->prepare(io->data); + } } if (err < 0) return err; @@ -463,9 +467,13 @@ static int snd_pcm_ioplug_sw_params(snd_pcm_t *pcm, snd_pcm_sw_params_t *params) if (!io->data->callback->sw_params) return 0; - snd_pcm_unlock(pcm); /* to avoid deadlock */ - err = io->data->callback->sw_params(io->data, params); - snd_pcm_lock(pcm); + if (snd_pcm_is_locked(pcm)) { + snd_pcm_unlock(pcm); /* to avoid deadlock */ + err = io->data->callback->sw_params(io->data, params); + snd_pcm_lock(pcm); + } else { + err = io->data->callback->sw_params(io->data, params); + } return err; } @@ -764,9 +772,13 @@ static int snd_pcm_ioplug_poll_descriptors_count(snd_pcm_t *pcm) int err = 1; if (io->data->callback->poll_descriptors_count) { - snd_pcm_unlock(pcm); /* to avoid deadlock */ - err = io->data->callback->poll_descriptors_count(io->data); - snd_pcm_lock(pcm); + if (snd_pcm_is_locked(pcm)) { + snd_pcm_unlock(pcm); /* to avoid deadlock */ + err = io->data->callback->poll_descriptors_count(io->data); + snd_pcm_lock(pcm); + } else { + err = io->data->callback->poll_descriptors_count(io->data); + } } return err; } @@ -777,9 +789,13 @@ static int snd_pcm_ioplug_poll_descriptors(snd_pcm_t *pcm, struct pollfd *pfds, int err; if (io->data->callback->poll_descriptors) { - snd_pcm_unlock(pcm); /* to avoid deadlock */ - err = io->data->callback->poll_descriptors(io->data, pfds, space); - snd_pcm_lock(pcm); + if (snd_pcm_is_locked(pcm)) { + snd_pcm_unlock(pcm); /* to avoid deadlock */ + err = io->data->callback->poll_descriptors(io->data, pfds, space); + snd_pcm_lock(pcm); + } else { + err = io->data->callback->poll_descriptors(io->data, pfds, space); + } return err; } if (pcm->poll_fd < 0) @@ -799,9 +815,13 @@ static int snd_pcm_ioplug_poll_revents(snd_pcm_t *pcm, struct pollfd *pfds, unsi int err; if (io->data->callback->poll_revents) { - snd_pcm_unlock(pcm); /* to avoid deadlock */ - err = io->data->callback->poll_revents(io->data, pfds, nfds, revents); - snd_pcm_lock(pcm); + if (snd_pcm_is_locked(pcm)) { + snd_pcm_unlock(pcm); /* to avoid deadlock */ + err = io->data->callback->poll_revents(io->data, pfds, nfds, revents); + snd_pcm_lock(pcm); + } else { + err = io->data->callback->poll_revents(io->data, pfds, nfds, revents); + } } else { *revents = pfds->revents; err = 0; From patchwork Sun Sep 22 03:28:53 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ben Russell X-Patchwork-Id: 11155659 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 47FE113B1 for ; Sun, 22 Sep 2019 03:33:30 +0000 (UTC) Received: from alsa0.perex.cz (alsa0.perex.cz [77.48.224.243]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id D020F20B7C for ; Sun, 22 Sep 2019 03:33:29 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=alsa-project.org header.i=@alsa-project.org header.b="kcq4Z8/Y"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="tESkEsjo" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org D020F20B7C Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=alsa-devel-bounces@alsa-project.org Received: from alsa1.perex.cz (alsa1.perex.cz [207.180.221.201]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by alsa0.perex.cz (Postfix) with ESMTPS id 265F11675; Sun, 22 Sep 2019 05:32:38 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa0.perex.cz 265F11675 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alsa-project.org; s=default; t=1569123208; bh=GiMFFrj2h5XDmnK2Bro/gZsKvNKdRi/nwiR/pmOoQpw=; h=From:To:Date:In-Reply-To:References:Cc:Subject:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=kcq4Z8/YEwBvT4cvTC2QBc/EvFBs3vFKudHptXJL9iiUM/BxBHJbXo7GSOrS70aV7 e/tvpKUAF2vRGKDvpWukduCBgaZUIjFW+6QAqjk7ufVsYPn6qb7zl0hGp/bgiqsbpj PVfWP4rU5M1TFB4IH+tPeQgBBJ9B6Dsy7brMO+Zc= Received: from alsa1.perex.cz (localhost.localdomain [127.0.0.1]) by alsa1.perex.cz (Postfix) with ESMTP id 9C195F805F7; Sun, 22 Sep 2019 05:30:38 +0200 (CEST) X-Original-To: alsa-devel@alsa-project.org Delivered-To: alsa-devel@alsa-project.org Received: by alsa1.perex.cz (Postfix, from userid 50401) id 6AA69F805FE; Sun, 22 Sep 2019 05:30:37 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on alsa1.perex.cz X-Spam-Level: X-Spam-Status: No, score=-0.1 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FROM,SPF_HELO_NONE,SPF_PASS autolearn=disabled version=3.4.0 Received: from mail-pg1-x533.google.com (mail-pg1-x533.google.com [IPv6:2607:f8b0:4864:20::533]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by alsa1.perex.cz (Postfix) with ESMTPS id CC85CF805F7 for ; Sun, 22 Sep 2019 05:30:34 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa1.perex.cz CC85CF805F7 Authentication-Results: alsa1.perex.cz; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="tESkEsjo" Received: by mail-pg1-x533.google.com with SMTP id 4so5965054pgm.12 for ; Sat, 21 Sep 2019 20:30:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=9Sm5R9yykGoPjeHN7OkLR+8HnHRjBpk/gYjTySZNOLU=; b=tESkEsjoc/5465aPQ3SLR5qOZcy6Cm68bJNIBRp1nW73PG9U1Lt/ESEfXwG+8jfeUq 0XFZuj5zW+Okw7bv9xDIP5w34tI9R9QcEtQBYaGnIW1/dEoigaWZcpG2Pcy1H9vF4mXn ETPyLHq6LQaSoepg6a6RB+pSCfYewClICMuQeHCq7ES8xD78M4mOaPeCH0FKe5Yv+B7U qKHvx2bLJC1MBBo+/edTw7eHEcO4Jnee5YK5UOlrq5hMlAOgllZNkmwEciS0kxpOZSkD 2V8yJ/AGX9D792fe0nLh7KK7s1AJ7DZ/tgpcyYEqyqZ723+aoErTB3cZ/0ssFX/nxQcY ojog== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=9Sm5R9yykGoPjeHN7OkLR+8HnHRjBpk/gYjTySZNOLU=; b=cQFVgvXnwZKHhJKyxMTVWCEsPdUyh0gL9u+02uf+S22TqkweJm+XHxb7WYUzJDwVkQ mi8zK8ssy3gexOsBsjKWZUjV8MlwYYMjpiIFMsakte9k2nYowHHAA1DclbwJ2XxQJb14 vKiChub+GE+Yn/egBki+CU5UUR5osOmFTPX+GD+06nQsRlJzwIsIFqiXDpqVox2Jq3dH NYYHHoUifUTSrL6Ifjq3APC7bQ/UNTAJiDaPE5hsM2iTyeZu3+GslQKHQti+kOdmnXPL zkhayLYov+i4F7UPF7HqjhKnzEeJd6RVj/iZsthjOEFa4OIIHlISu9nnBwJK1BIqHH9t 4z0Q== X-Gm-Message-State: APjAAAWoYaTWUVYjs01ye0MH1pqXlTSqqRaz0kQ+8yJD+0NXp5GwVSYI OSztrlZFp2Ktl0+debcplUul0pac X-Google-Smtp-Source: APXvYqyOo5yYgeWcoOIvrSvQbj64krzBOCuRSXkwC2Om8FT1rpwzvU3/UdzLcOQ8di31WtfY9+bgmA== X-Received: by 2002:a62:2702:: with SMTP id n2mr26759787pfn.73.1569123032645; Sat, 21 Sep 2019 20:30:32 -0700 (PDT) Received: from localhost.localdomain ([2407:7000:aa04:fb00:ce0f:a0bf:1ece:a196]) by smtp.gmail.com with ESMTPSA id l12sm4559532pgs.44.2019.09.21.20.30.30 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 21 Sep 2019 20:30:32 -0700 (PDT) From: Ben Russell To: alsa-devel@alsa-project.org Date: Sun, 22 Sep 2019 15:28:53 +1200 Message-Id: <20190922032853.6123-4-thematrixeatsyou@gmail.com> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20190922032853.6123-1-thematrixeatsyou@gmail.com> References: <20190922032853.6123-1-thematrixeatsyou@gmail.com> MIME-Version: 1.0 Cc: Ben Russell Subject: [alsa-devel] [PATCH 3/3] pcm_local: assert() when using mutexes incorrectly X-BeenThere: alsa-devel@alsa-project.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: "Alsa-devel mailing list for ALSA developers - http://www.alsa-project.org" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: alsa-devel-bounces@alsa-project.org Sender: "Alsa-devel" This makes it easier to find pcm mutex handling errors. Signed-off-by: Ben Russell --- src/pcm/pcm_local.h | 32 ++++++++++++++++++++++++-------- 1 file changed, 24 insertions(+), 8 deletions(-) diff --git a/src/pcm/pcm_local.h b/src/pcm/pcm_local.h index 649d84f2..c1f881a6 100644 --- a/src/pcm/pcm_local.h +++ b/src/pcm/pcm_local.h @@ -1153,23 +1153,39 @@ static inline void sw_set_period_event(snd_pcm_sw_params_t *params, int val) */ static inline void __snd_pcm_lock(snd_pcm_t *pcm) { - if (pcm->lock_enabled) - pthread_mutex_lock(&pcm->lock); + int lock_err; + + if (pcm->lock_enabled) { + lock_err = pthread_mutex_lock(&pcm->lock); + assert(lock_err == 0); + } } static inline void __snd_pcm_unlock(snd_pcm_t *pcm) { - if (pcm->lock_enabled) - pthread_mutex_unlock(&pcm->lock); + int unlock_err; + + if (pcm->lock_enabled) { + unlock_err = pthread_mutex_unlock(&pcm->lock); + assert(unlock_err == 0); + } } static inline void snd_pcm_lock(snd_pcm_t *pcm) { - if (pcm->lock_enabled && pcm->need_lock) - pthread_mutex_lock(&pcm->lock); + int lock_err; + + if (pcm->lock_enabled && pcm->need_lock) { + lock_err = pthread_mutex_lock(&pcm->lock); + assert(lock_err == 0); + } } static inline void snd_pcm_unlock(snd_pcm_t *pcm) { - if (pcm->lock_enabled && pcm->need_lock) - pthread_mutex_unlock(&pcm->lock); + int unlock_err; + + if (pcm->lock_enabled && pcm->need_lock) { + unlock_err = pthread_mutex_unlock(&pcm->lock); + assert(unlock_err == 0); + } } /*