Skip to content

Commit d5a5bd1

Browse files
andy-shevcjb
authored andcommitted
mmc: mmc_test: avoid stalled file in debugfs
During card removal and inserting cycle the test file in the debugfs could be stalled until the host driver removes it. Let's keep the file in the linked list and destroy it when card is removed. Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com> Acked-by: Per Forlin <per.forlin@linaro.org> Signed-off-by: Chris Ball <cjb@laptop.org>
1 parent 7199e2b commit d5a5bd1

1 file changed

Lines changed: 30 additions & 26 deletions

File tree

‎drivers/mmc/card/mmc_test.c‎

Lines changed: 30 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -2900,7 +2900,7 @@ static const struct file_operations mmc_test_fops_testlist = {
29002900
.release = single_release,
29012901
};
29022902

2903-
static void mmc_test_free_file_test(struct mmc_card *card)
2903+
static void mmc_test_free_dbgfs_file(struct mmc_card *card)
29042904
{
29052905
struct mmc_test_dbgfs_file *df, *dfs;
29062906

@@ -2917,49 +2917,53 @@ static void mmc_test_free_file_test(struct mmc_card *card)
29172917
mutex_unlock(&mmc_test_lock);
29182918
}
29192919

2920-
static int mmc_test_register_file_test(struct mmc_card *card)
2920+
static int __mmc_test_register_dbgfs_file(struct mmc_card *card,
2921+
const char *name, mode_t mode, const struct file_operations *fops)
29212922
{
29222923
struct dentry *file = NULL;
29232924
struct mmc_test_dbgfs_file *df;
2924-
int ret = 0;
2925-
2926-
mutex_lock(&mmc_test_lock);
2927-
2928-
if (card->debugfs_root)
2929-
file = debugfs_create_file("test", S_IWUSR | S_IRUGO,
2930-
card->debugfs_root, card, &mmc_test_fops_test);
2931-
2932-
if (IS_ERR_OR_NULL(file)) {
2933-
dev_err(&card->dev,
2934-
"Can't create test. Perhaps debugfs is disabled.\n");
2935-
ret = -ENODEV;
2936-
goto err;
2937-
}
29382925

29392926
if (card->debugfs_root)
2940-
file = debugfs_create_file("testlist", S_IRUGO,
2941-
card->debugfs_root, card, &mmc_test_fops_testlist);
2927+
file = debugfs_create_file(name, mode, card->debugfs_root,
2928+
card, fops);
29422929

29432930
if (IS_ERR_OR_NULL(file)) {
29442931
dev_err(&card->dev,
2945-
"Can't create testlist. Perhaps debugfs is disabled.\n");
2946-
ret = -ENODEV;
2947-
goto err;
2932+
"Can't create %s. Perhaps debugfs is disabled.\n",
2933+
name);
2934+
return -ENODEV;
29482935
}
29492936

29502937
df = kmalloc(sizeof(struct mmc_test_dbgfs_file), GFP_KERNEL);
29512938
if (!df) {
29522939
debugfs_remove(file);
29532940
dev_err(&card->dev,
29542941
"Can't allocate memory for internal usage.\n");
2955-
ret = -ENOMEM;
2956-
goto err;
2942+
return -ENOMEM;
29572943
}
29582944

29592945
df->card = card;
29602946
df->file = file;
29612947

29622948
list_add(&df->link, &mmc_test_file_test);
2949+
return 0;
2950+
}
2951+
2952+
static int mmc_test_register_dbgfs_file(struct mmc_card *card)
2953+
{
2954+
int ret;
2955+
2956+
mutex_lock(&mmc_test_lock);
2957+
2958+
ret = __mmc_test_register_dbgfs_file(card, "test", S_IWUSR | S_IRUGO,
2959+
&mmc_test_fops_test);
2960+
if (ret)
2961+
goto err;
2962+
2963+
ret = __mmc_test_register_dbgfs_file(card, "testlist", S_IRUGO,
2964+
&mmc_test_fops_testlist);
2965+
if (ret)
2966+
goto err;
29632967

29642968
err:
29652969
mutex_unlock(&mmc_test_lock);
@@ -2974,7 +2978,7 @@ static int mmc_test_probe(struct mmc_card *card)
29742978
if (!mmc_card_mmc(card) && !mmc_card_sd(card))
29752979
return -ENODEV;
29762980

2977-
ret = mmc_test_register_file_test(card);
2981+
ret = mmc_test_register_dbgfs_file(card);
29782982
if (ret)
29792983
return ret;
29802984

@@ -2986,7 +2990,7 @@ static int mmc_test_probe(struct mmc_card *card)
29862990
static void mmc_test_remove(struct mmc_card *card)
29872991
{
29882992
mmc_test_free_result(card);
2989-
mmc_test_free_file_test(card);
2993+
mmc_test_free_dbgfs_file(card);
29902994
}
29912995

29922996
static struct mmc_driver mmc_driver = {
@@ -3006,7 +3010,7 @@ static void __exit mmc_test_exit(void)
30063010
{
30073011
/* Clear stalled data if card is still plugged */
30083012
mmc_test_free_result(NULL);
3009-
mmc_test_free_file_test(NULL);
3013+
mmc_test_free_dbgfs_file(NULL);
30103014

30113015
mmc_unregister_driver(&mmc_driver);
30123016
}

0 commit comments

Comments
 (0)