From patchwork Thu Jan 18 05:31:26 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Donglin Peng X-Patchwork-Id: 10172395 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id D1529602DC for ; Thu, 18 Jan 2018 05:32:09 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C101E1FE8D for ; Thu, 18 Jan 2018 05:32:09 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B565620072; Thu, 18 Jan 2018 05:32:09 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-1.8 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_NONE, T_DKIM_INVALID autolearn=no version=3.3.1 Received: from alsa0.perex.cz (alsa0.perex.cz [77.48.224.243]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 64F341FE8D for ; Thu, 18 Jan 2018 05:32:07 +0000 (UTC) Received: from alsa0.perex.cz (localhost [127.0.0.1]) by alsa0.perex.cz (Postfix) with ESMTP id DD9F4267187; Thu, 18 Jan 2018 06:32:05 +0100 (CET) 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 4336726718B; Thu, 18 Jan 2018 06:32:04 +0100 (CET) Received: from mail-pg0-f65.google.com (mail-pg0-f65.google.com [74.125.83.65]) by alsa0.perex.cz (Postfix) with ESMTP id 270B4266A74 for ; Thu, 18 Jan 2018 06:31:59 +0100 (CET) Received: by mail-pg0-f65.google.com with SMTP id z17so13133189pgc.4 for ; Wed, 17 Jan 2018 21:31:59 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=jo2Z0BmyF8wUY2tGJ0zlD/M2Lq5H5ZsRkv2Ei1+rxbw=; b=auIzltWZUi5gjjKKxQlA1NNV5DfFr5cMmSCHkoajFfz7jkTmPuUnahz4xnq0m5IyZy ByKXlZqTUwM/krKVj7Zb9ebVjLDKV5G0Sxcvliz6XGlamET7avt07nAQjxudFV24cw5V hoNxeTELz5MVQuShIKnfS5jQSYRcQv6PbN8rzw21p4W0GVxp7oUvBNs64rhkx3c8SwGO J9NEVqlMGfQMvixcA00LFhpKhty66BN1/CNVkthYhHk4Byv6ziLOHImmDHmtNQYZLLZz ht1WCBn5MhsQerYEpS48CwvRDb2MwPbLY368/EloyzA59/B/s8gkenE49Bmyi4Pq9eln xHfw== 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; bh=jo2Z0BmyF8wUY2tGJ0zlD/M2Lq5H5ZsRkv2Ei1+rxbw=; b=m+++lGbmEfLOFyfY2EKzf+kI0vK9yOTHzzkvVqXF9+xUFDVOxtgTcxql07J3ZdtDkd FFTqpO7AZyGa1ddyfUzTIcdBxD6B9u0jdo/0qiEkJkuwmGqwobU/AYjDedqcsVxfhnQi S8/Kr94qwhNEh688mVXIWYNyRwlQGXTpRgbrWBcXLAtyaFbGMcJVI4MkrpuSChysHife 6473/HjFRtqtVJzx6Jl79S44M/B4FG4w2tIpygWFlHO5hZbcgUtW0Gl4k9+I2+9dZ6uA rXb9lD6CyPOWjrn9aaCDYcmwdwSIgdf7JxJpP1hk5KgL4eRkTpqNE2YnnEqIhUNPXKlL dymw== X-Gm-Message-State: AKwxytegBL6V2+V9nhU7hn+Vumn8SbqJCloUWQs9Cc+O5PInTRe0xVOZ eGlRTZ3ab42teqz7YKtOgq0= X-Google-Smtp-Source: ACJfBou07g1oWuS9OudqhJ5vOFTm8/6nrLF1sQXhSJ86kN+B6Z5Nj1K/n6YGaBq2BOBITHFN71672g== X-Received: by 10.84.235.73 with SMTP id g9mr20406924plt.9.1516253518895; Wed, 17 Jan 2018 21:31:58 -0800 (PST) Received: from localhost.localdomain ([111.207.121.248]) by smtp.gmail.com with ESMTPSA id k62sm9263880pga.42.2018.01.17.21.31.56 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 17 Jan 2018 21:31:58 -0800 (PST) From: Donglin Peng To: lgirdwood@gmail.com, broonie@kernel.org, perex@perex.cz, tiwai@suse.com Date: Thu, 18 Jan 2018 13:31:26 +0800 Message-Id: <20180118053126.22082-1-dolinux.peng@gmail.com> X-Mailer: git-send-email 2.15.1 Cc: alsa-devel@alsa-project.org, linux-kernel@vger.kernel.org, Donglin Peng Subject: [alsa-devel] [PATCH v2] ASoC: use seq_file to dump the contents of dai_list, platform_list and codec_list 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 Now the debugfs files dais/platforms/codecs have a size limit PAGE_SIZE and the user can not see the whole contents of dai_list/platform_list/codec_list when they are larger than this limit. This patch uses seq_file instead to make sure dais/platforms/codecs show the full contents of dai_list/platform_list/codec_list. Signed-off-by: Donglin Peng --- Changelog v2 -fix commit log error sound/soc/soc-core.c | 111 +++++++++++++++++---------------------------------- 1 file changed, 37 insertions(+), 74 deletions(-) diff --git a/sound/soc/soc-core.c b/sound/soc/soc-core.c index c0edac80df34..7b582112e3fc 100644 --- a/sound/soc/soc-core.c +++ b/sound/soc/soc-core.c @@ -349,120 +349,84 @@ static void soc_init_codec_debugfs(struct snd_soc_component *component) "ASoC: Failed to create codec register debugfs file\n"); } -static ssize_t codec_list_read_file(struct file *file, char __user *user_buf, - size_t count, loff_t *ppos) +static int codec_list_seq_show(struct seq_file *m, void *v) { - char *buf = kmalloc(PAGE_SIZE, GFP_KERNEL); - ssize_t len, ret = 0; struct snd_soc_codec *codec; - if (!buf) - return -ENOMEM; - mutex_lock(&client_mutex); - list_for_each_entry(codec, &codec_list, list) { - len = snprintf(buf + ret, PAGE_SIZE - ret, "%s\n", - codec->component.name); - if (len >= 0) - ret += len; - if (ret > PAGE_SIZE) { - ret = PAGE_SIZE; - break; - } - } + list_for_each_entry(codec, &codec_list, list) + seq_printf(m, "%s\n", codec->component.name); mutex_unlock(&client_mutex); - if (ret >= 0) - ret = simple_read_from_buffer(user_buf, count, ppos, buf, ret); - - kfree(buf); + return 0; +} - return ret; +static int codec_list_seq_open(struct inode *inode, struct file *file) +{ + return single_open(file, codec_list_seq_show, NULL); } static const struct file_operations codec_list_fops = { - .read = codec_list_read_file, - .llseek = default_llseek,/* read accesses f_pos */ + .open = codec_list_seq_open, + .read = seq_read, + .llseek = seq_lseek, + .release = single_release, }; -static ssize_t dai_list_read_file(struct file *file, char __user *user_buf, - size_t count, loff_t *ppos) +static int dai_list_seq_show(struct seq_file *m, void *v) { - char *buf = kmalloc(PAGE_SIZE, GFP_KERNEL); - ssize_t len, ret = 0; struct snd_soc_component *component; struct snd_soc_dai *dai; - if (!buf) - return -ENOMEM; - mutex_lock(&client_mutex); - list_for_each_entry(component, &component_list, list) { - list_for_each_entry(dai, &component->dai_list, list) { - len = snprintf(buf + ret, PAGE_SIZE - ret, "%s\n", - dai->name); - if (len >= 0) - ret += len; - if (ret > PAGE_SIZE) { - ret = PAGE_SIZE; - break; - } - } - } + list_for_each_entry(component, &component_list, list) + list_for_each_entry(dai, &component->dai_list, list) + seq_printf(m, "%s\n", dai->name); mutex_unlock(&client_mutex); - ret = simple_read_from_buffer(user_buf, count, ppos, buf, ret); - - kfree(buf); + return 0; +} - return ret; +static int dai_list_seq_open(struct inode *inode, struct file *file) +{ + return single_open(file, dai_list_seq_show, NULL); } static const struct file_operations dai_list_fops = { - .read = dai_list_read_file, - .llseek = default_llseek,/* read accesses f_pos */ + .open = dai_list_seq_open, + .read = seq_read, + .llseek = seq_lseek, + .release = single_release, }; -static ssize_t platform_list_read_file(struct file *file, - char __user *user_buf, - size_t count, loff_t *ppos) +static int platform_list_seq_show(struct seq_file *m, void *v) { - char *buf = kmalloc(PAGE_SIZE, GFP_KERNEL); - ssize_t len, ret = 0; struct snd_soc_platform *platform; - if (!buf) - return -ENOMEM; - mutex_lock(&client_mutex); - list_for_each_entry(platform, &platform_list, list) { - len = snprintf(buf + ret, PAGE_SIZE - ret, "%s\n", - platform->component.name); - if (len >= 0) - ret += len; - if (ret > PAGE_SIZE) { - ret = PAGE_SIZE; - break; - } - } + list_for_each_entry(platform, &platform_list, list) + seq_printf(m, "%s\n", platform->component.name); mutex_unlock(&client_mutex); - ret = simple_read_from_buffer(user_buf, count, ppos, buf, ret); - - kfree(buf); + return 0; +} - return ret; +static int platform_list_seq_open(struct inode *inode, struct file *file) +{ + return single_open(file, platform_list_seq_show, NULL); } static const struct file_operations platform_list_fops = { - .read = platform_list_read_file, - .llseek = default_llseek,/* read accesses f_pos */ + .open = platform_list_seq_open, + .read = seq_read, + .llseek = seq_lseek, + .release = single_release, }; static void soc_init_card_debugfs(struct snd_soc_card *card) @@ -491,7 +455,6 @@ static void soc_cleanup_card_debugfs(struct snd_soc_card *card) debugfs_remove_recursive(card->debugfs_card_root); } - static void snd_soc_debugfs_init(void) { snd_soc_debugfs_root = debugfs_create_dir("asoc", NULL);