From patchwork Sun May 1 12:43:42 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Patrakov X-Patchwork-Id: 8988801 Return-Path: X-Original-To: patchwork-alsa-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id AD40DBF29F for ; Sun, 1 May 2016 12:44:11 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 8DB642012D for ; Sun, 1 May 2016 12:44:10 +0000 (UTC) Received: from alsa0.perex.cz (alsa0.perex.cz [77.48.224.243]) by mail.kernel.org (Postfix) with ESMTP id 3D215200FF for ; Sun, 1 May 2016 12:44:08 +0000 (UTC) Received: by alsa0.perex.cz (Postfix, from userid 1000) id 85C772617A4; Sun, 1 May 2016 14:44:05 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Spam-Level: X-Spam-Status: No, score=-1.8 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_NONE, T_DKIM_INVALID, UNPARSEABLE_RELAY autolearn=no version=3.3.1 Received: from alsa0.perex.cz (localhost [127.0.0.1]) by alsa0.perex.cz (Postfix) with ESMTP id 62AB626068F; Sun, 1 May 2016 14:44:02 +0200 (CEST) X-Original-To: alsa-devel@alsa-project.org Delivered-To: alsa-devel@alsa-project.org Received: by alsa0.perex.cz (Postfix, from userid 1000) id A19D32606C7; Sun, 1 May 2016 14:44:00 +0200 (CEST) Received: from mail-wm0-f46.google.com (mail-wm0-f46.google.com [74.125.82.46]) by alsa0.perex.cz (Postfix) with ESMTP id 23F542604DF for ; Sun, 1 May 2016 14:43:55 +0200 (CEST) Received: by mail-wm0-f46.google.com with SMTP id a17so103916213wme.0 for ; Sun, 01 May 2016 05:43:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id; bh=FfWZs9S8xmXvlh7i3STX5WQGE2QAaS805gkzxkBnm+k=; b=RtRzikq7DyQ8VBmZA0ftK090DkWaGZX568Wj2WEBmHB3uUnWyiNUCHIuwduWujo6Jy BOjvY9w/qa46og+jPGf2FIIRNftcd8eNinyLjFfeITdAxRYWUp64XX9AX80bd9raT1+D CLhH4ETNzUMNQ4PNysQXyBQ8EdSGy+6eRioDYejt+diWkorRoUOGzNZvzjqorE9UNCeQ WTicfK2+7w/C5XvquHIUr+1q86sZLufr/BqZ1L+JJE13iR7ivfdr6guUKNgVBnw0jquU 8PDIkFsTIQvhIvdLBFBRv60GRnodtI0u9oGASANJNX9z+reNZpLncLyTviYAe1r67Px2 98gg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=FfWZs9S8xmXvlh7i3STX5WQGE2QAaS805gkzxkBnm+k=; b=GuAJc2XBaMF+WCI3Fa8ISjWqlVUSJZes0sDR0eHqmztGDjCHyeijuu0Z/bIv1Ymw6i BgAW9jnpFAtWSKvevjFoQ6PvjE43Ldph1XyjYLP+8IqAN55jMQqisbhYfc8xT5GoI36b RRPlYRsCPCtYDQISSPos9RBom/ps5PaGYRLPoQmtMCidslnr5OoPBYVEy4NJRT1j0GXu aB0KNSC4QWplvfm3+yuJkItSgkRs6EeHPt3oTbz4oFQku1ti5BgXpgwyjuoMDjmg9G8q SXnzoBD7qgZb+wOhPo+ljFGjWnvqPAfbEiBzhI0RV1Wb/vuvVF12Usv5I6eaBzjq6hr8 iomA== X-Gm-Message-State: AOPr4FWgIGrOKcnt7yOud9aPwoWn/E/6jFTIj1370DqRdE3BSvEfCU0fPZq9P3tw8RS8GQ== X-Received: by 10.194.19.197 with SMTP id h5mr31560683wje.139.1462106634779; Sun, 01 May 2016 05:43:54 -0700 (PDT) Received: from aep-haswell.lan ([2001:470:28:8b0:96de:80ff:fe6f:9ad4]) by smtp.gmail.com with ESMTPSA id r123sm13186413wmg.20.2016.05.01.05.43.52 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sun, 01 May 2016 05:43:53 -0700 (PDT) From: "Alexander E. Patrakov" To: alsa-devel@alsa-project.org Date: Sun, 1 May 2016 17:43:42 +0500 Message-Id: <1462106622-29461-1-git-send-email-patrakov@gmail.com> X-Mailer: git-send-email 2.8.0 Cc: tiwai@suse.de, tanuk@iki.fi, "Alexander E. Patrakov" Subject: [alsa-devel] [PATCH] conf: don't check if config files are up to date X-BeenThere: alsa-devel@alsa-project.org X-Mailman-Version: 2.1.14 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: , MIME-Version: 1.0 Errors-To: alsa-devel-bounces@alsa-project.org Sender: alsa-devel-bounces@alsa-project.org X-Virus-Scanned: ClamAV using ClamSMTP Even if no files have been changed, the config may become outdated due to hot-plugged devices. Note: this patch has a huge potential to crash badly-written applications that keep config pointers and strings for too long. But I see no other way to support hot-pluggable devices. Fixes: https://bugs.freedesktop.org/show_bug.cgi?id=54029 Signed-off-by: Alexander E. Patrakov --- src/conf.c | 63 ++++++++++++++++++++++++---------------------------------- src/confmisc.c | 4 +++- 2 files changed, 29 insertions(+), 38 deletions(-) diff --git a/src/conf.c b/src/conf.c index f8b7a66..34576aa 100644 --- a/src/conf.c +++ b/src/conf.c @@ -3661,14 +3661,15 @@ SND_DLSYM_BUILD_VERSION(snd_config_hook_load_for_all_cards, SND_CONFIG_DLSYM_VER #endif /** - * \brief Updates a configuration tree by rereading the configuration files (if needed). + * \brief Updates a configuration tree by rereading the configuration files. * \param[in,out] _top Address of the handle to the top-level node. * \param[in,out] _update Address of a pointer to private update information. * \param[in] cfgs A list of configuration file names, delimited with ':'. * If \p cfgs is \c NULL, the default global * configuration file is used. - * \return 0 if \a _top was up to date, 1 if the configuration files - * have been reread, otherwise a negative error code. + * \return 0 if \a _top was up to date (this can happen only in previous + * ALSA-lib versions), 1 if the configuration files have been + * reread successfully, otherwise a negative error code. * * The variables pointed to by \a _top and \a _update can be initialized * to \c NULL before the first call to this function. The private @@ -3679,7 +3680,8 @@ SND_DLSYM_BUILD_VERSION(snd_config_hook_load_for_all_cards, SND_CONFIG_DLSYM_VER * The global configuration files are specified in the environment variable * \c ALSA_CONFIG_PATH. * - * \warning If the configuration tree is reread, all string pointers and + * \warning In order to deal with hot-pluggable devices, the configuration + * tree is always reread, even if nothing changed. All string pointers and * configuration node handles previously obtained from this tree become * invalid. * @@ -3754,35 +3756,6 @@ int snd_config_update_r(snd_config_t **_top, snd_config_update_t **_update, cons local->count--; } } - if (!update) - goto _reread; - if (local->count != update->count) - goto _reread; - for (k = 0; k < local->count; ++k) { - struct finfo *lf = &local->finfo[k]; - struct finfo *uf = &update->finfo[k]; - if (strcmp(lf->name, uf->name) != 0 || - lf->dev != uf->dev || - lf->ino != uf->ino || - lf->mtime != uf->mtime) - goto _reread; - } - err = 0; - - _end: - if (err < 0) { - if (top) { - snd_config_delete(top); - *_top = NULL; - } - if (update) { - snd_config_update_free(update); - *_update = NULL; - } - } - if (local) - snd_config_update_free(local); - return err; _reread: *_top = NULL; @@ -3823,15 +3796,31 @@ int snd_config_update_r(snd_config_t **_top, snd_config_update_t **_update, cons *_top = top; *_update = local; return 1; + +_end: + if (err < 0) { + if (top) { + snd_config_delete(top); + *_top = NULL; + } + if (update) { + snd_config_update_free(update); + *_update = NULL; + } + } + if (local) + snd_config_update_free(local); + return err; } /** - * \brief Updates #snd_config by rereading the global configuration files (if needed). - * \return 0 if #snd_config was up to date, 1 if #snd_config was - * updated, otherwise a negative error code. + * \brief Updates #snd_config by rereading the global configuration files. + * \return 0 if #snd_config was up to date (this can happen only in previous + * ALSA-lib versions), 1 if #snd_config was updated successfully, + * otherwise a negative error code. * * \warning Whenever #snd_config is updated, all string pointers and - * configuration node handles previously obtained from it may become + * configuration node handles previously obtained from it become * invalid. * * \par Errors: diff --git a/src/confmisc.c b/src/confmisc.c index ae0275f..8f97b72 100644 --- a/src/confmisc.c +++ b/src/confmisc.c @@ -599,7 +599,9 @@ static int open_ctl(long card, snd_ctl_t **ctl) char name[16]; snprintf(name, sizeof(name), "hw:%li", card); name[sizeof(name)-1] = '\0'; - return snd_ctl_open(ctl, name, 0); + + /* Take care not to update the config - we may be running hooks on pcms right now */ + return snd_ctl_open_lconf(ctl, name, 0, snd_config); } #if 0