diff options
| author | Donglin Peng <dolinux.peng@gmail.com> | 2018-01-18 00:31:26 -0500 |
|---|---|---|
| committer | Mark Brown <broonie@kernel.org> | 2018-01-18 06:52:23 -0500 |
| commit | 700c17ca8968f473631594e8a7c2cc880ba2c891 (patch) | |
| tree | 3034045cf065a50052fd6e533e6318e371d93d02 | |
| parent | 4fbd8d194f06c8a3fd2af1ce560ddb31f7ec8323 (diff) | |
ASoC: use seq_file to dump the contents of dai_list,platform_list and codec_list
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 <dolinux.peng@gmail.com>
Signed-off-by: Mark Brown <broonie@kernel.org>
| -rw-r--r-- | sound/soc/soc-core.c | 111 |
1 files 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) | |||
| 349 | "ASoC: Failed to create codec register debugfs file\n"); | 349 | "ASoC: Failed to create codec register debugfs file\n"); |
| 350 | } | 350 | } |
| 351 | 351 | ||
| 352 | static ssize_t codec_list_read_file(struct file *file, char __user *user_buf, | 352 | static int codec_list_seq_show(struct seq_file *m, void *v) |
| 353 | size_t count, loff_t *ppos) | ||
| 354 | { | 353 | { |
| 355 | char *buf = kmalloc(PAGE_SIZE, GFP_KERNEL); | ||
| 356 | ssize_t len, ret = 0; | ||
| 357 | struct snd_soc_codec *codec; | 354 | struct snd_soc_codec *codec; |
| 358 | 355 | ||
| 359 | if (!buf) | ||
| 360 | return -ENOMEM; | ||
| 361 | |||
| 362 | mutex_lock(&client_mutex); | 356 | mutex_lock(&client_mutex); |
| 363 | 357 | ||
| 364 | list_for_each_entry(codec, &codec_list, list) { | 358 | list_for_each_entry(codec, &codec_list, list) |
| 365 | len = snprintf(buf + ret, PAGE_SIZE - ret, "%s\n", | 359 | seq_printf(m, "%s\n", codec->component.name); |
| 366 | codec->component.name); | ||
| 367 | if (len >= 0) | ||
| 368 | ret += len; | ||
| 369 | if (ret > PAGE_SIZE) { | ||
| 370 | ret = PAGE_SIZE; | ||
| 371 | break; | ||
| 372 | } | ||
| 373 | } | ||
| 374 | 360 | ||
| 375 | mutex_unlock(&client_mutex); | 361 | mutex_unlock(&client_mutex); |
| 376 | 362 | ||
| 377 | if (ret >= 0) | 363 | return 0; |
| 378 | ret = simple_read_from_buffer(user_buf, count, ppos, buf, ret); | 364 | } |
| 379 | |||
| 380 | kfree(buf); | ||
| 381 | 365 | ||
| 382 | return ret; | 366 | static int codec_list_seq_open(struct inode *inode, struct file *file) |
| 367 | { | ||
| 368 | return single_open(file, codec_list_seq_show, NULL); | ||
| 383 | } | 369 | } |
| 384 | 370 | ||
| 385 | static const struct file_operations codec_list_fops = { | 371 | static const struct file_operations codec_list_fops = { |
| 386 | .read = codec_list_read_file, | 372 | .open = codec_list_seq_open, |
| 387 | .llseek = default_llseek,/* read accesses f_pos */ | 373 | .read = seq_read, |
| 374 | .llseek = seq_lseek, | ||
| 375 | .release = single_release, | ||
| 388 | }; | 376 | }; |
| 389 | 377 | ||
| 390 | static ssize_t dai_list_read_file(struct file *file, char __user *user_buf, | 378 | static int dai_list_seq_show(struct seq_file *m, void *v) |
| 391 | size_t count, loff_t *ppos) | ||
| 392 | { | 379 | { |
| 393 | char *buf = kmalloc(PAGE_SIZE, GFP_KERNEL); | ||
| 394 | ssize_t len, ret = 0; | ||
| 395 | struct snd_soc_component *component; | 380 | struct snd_soc_component *component; |
| 396 | struct snd_soc_dai *dai; | 381 | struct snd_soc_dai *dai; |
| 397 | 382 | ||
| 398 | if (!buf) | ||
| 399 | return -ENOMEM; | ||
| 400 | |||
| 401 | mutex_lock(&client_mutex); | 383 | mutex_lock(&client_mutex); |
| 402 | 384 | ||
| 403 | list_for_each_entry(component, &component_list, list) { | 385 | list_for_each_entry(component, &component_list, list) |
| 404 | list_for_each_entry(dai, &component->dai_list, list) { | 386 | list_for_each_entry(dai, &component->dai_list, list) |
| 405 | len = snprintf(buf + ret, PAGE_SIZE - ret, "%s\n", | 387 | seq_printf(m, "%s\n", dai->name); |
| 406 | dai->name); | ||
| 407 | if (len >= 0) | ||
| 408 | ret += len; | ||
| 409 | if (ret > PAGE_SIZE) { | ||
| 410 | ret = PAGE_SIZE; | ||
| 411 | break; | ||
| 412 | } | ||
| 413 | } | ||
| 414 | } | ||
| 415 | 388 | ||
| 416 | mutex_unlock(&client_mutex); | 389 | mutex_unlock(&client_mutex); |
| 417 | 390 | ||
| 418 | ret = simple_read_from_buffer(user_buf, count, ppos, buf, ret); | 391 | return 0; |
| 419 | 392 | } | |
| 420 | kfree(buf); | ||
| 421 | 393 | ||
| 422 | return ret; | 394 | static int dai_list_seq_open(struct inode *inode, struct file *file) |
| 395 | { | ||
| 396 | return single_open(file, dai_list_seq_show, NULL); | ||
| 423 | } | 397 | } |
| 424 | 398 | ||
| 425 | static const struct file_operations dai_list_fops = { | 399 | static const struct file_operations dai_list_fops = { |
| 426 | .read = dai_list_read_file, | 400 | .open = dai_list_seq_open, |
| 427 | .llseek = default_llseek,/* read accesses f_pos */ | 401 | .read = seq_read, |
| 402 | .llseek = seq_lseek, | ||
| 403 | .release = single_release, | ||
| 428 | }; | 404 | }; |
| 429 | 405 | ||
| 430 | static ssize_t platform_list_read_file(struct file *file, | 406 | static int platform_list_seq_show(struct seq_file *m, void *v) |
| 431 | char __user *user_buf, | ||
| 432 | size_t count, loff_t *ppos) | ||
| 433 | { | 407 | { |
| 434 | char *buf = kmalloc(PAGE_SIZE, GFP_KERNEL); | ||
| 435 | ssize_t len, ret = 0; | ||
| 436 | struct snd_soc_platform *platform; | 408 | struct snd_soc_platform *platform; |
| 437 | 409 | ||
| 438 | if (!buf) | ||
| 439 | return -ENOMEM; | ||
| 440 | |||
| 441 | mutex_lock(&client_mutex); | 410 | mutex_lock(&client_mutex); |
| 442 | 411 | ||
| 443 | list_for_each_entry(platform, &platform_list, list) { | 412 | list_for_each_entry(platform, &platform_list, list) |
| 444 | len = snprintf(buf + ret, PAGE_SIZE - ret, "%s\n", | 413 | seq_printf(m, "%s\n", platform->component.name); |
| 445 | platform->component.name); | ||
| 446 | if (len >= 0) | ||
| 447 | ret += len; | ||
| 448 | if (ret > PAGE_SIZE) { | ||
| 449 | ret = PAGE_SIZE; | ||
| 450 | break; | ||
| 451 | } | ||
| 452 | } | ||
| 453 | 414 | ||
| 454 | mutex_unlock(&client_mutex); | 415 | mutex_unlock(&client_mutex); |
| 455 | 416 | ||
| 456 | ret = simple_read_from_buffer(user_buf, count, ppos, buf, ret); | 417 | return 0; |
| 457 | 418 | } | |
| 458 | kfree(buf); | ||
| 459 | 419 | ||
| 460 | return ret; | 420 | static int platform_list_seq_open(struct inode *inode, struct file *file) |
| 421 | { | ||
| 422 | return single_open(file, platform_list_seq_show, NULL); | ||
| 461 | } | 423 | } |
| 462 | 424 | ||
| 463 | static const struct file_operations platform_list_fops = { | 425 | static const struct file_operations platform_list_fops = { |
| 464 | .read = platform_list_read_file, | 426 | .open = platform_list_seq_open, |
| 465 | .llseek = default_llseek,/* read accesses f_pos */ | 427 | .read = seq_read, |
| 428 | .llseek = seq_lseek, | ||
| 429 | .release = single_release, | ||
| 466 | }; | 430 | }; |
| 467 | 431 | ||
| 468 | static void soc_init_card_debugfs(struct snd_soc_card *card) | 432 | 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) | |||
| 491 | debugfs_remove_recursive(card->debugfs_card_root); | 455 | debugfs_remove_recursive(card->debugfs_card_root); |
| 492 | } | 456 | } |
| 493 | 457 | ||
| 494 | |||
| 495 | static void snd_soc_debugfs_init(void) | 458 | static void snd_soc_debugfs_init(void) |
| 496 | { | 459 | { |
| 497 | snd_soc_debugfs_root = debugfs_create_dir("asoc", NULL); | 460 | snd_soc_debugfs_root = debugfs_create_dir("asoc", NULL); |
