Skip to contentSkip to conversation

mmc: mmc_test: replace strict_strtol() with kstrtol_from_user()

PATCH In review Jingoo Han 2 participants 2 messages Jul 19, 2013 – Aug 25, 2013 MMC, SD and SDIO

lore
Share & tools
lore

Jingoo Han

author
#0 lore raw

PATCH 1/1 mmc: mmc_test: replace strict_strtol() with kstrtol_from_user()

The usage of strict_strtol() is not preferred, because strict_strtol() is obsolete. Thus, kstrtol() should be used.

Also, both kstrtol() and copy_from_user() can be replaced with kstrtol_from_user() to make the code simpler.

---
 drivers/mmc/card/mmc_test.c |   14 ++++----------
 1 file changed, 4 insertions(+), 10 deletions(-)
drivers/mmc/card/mmc_test.c +4 -10
index a69df52..0c0fc52 100644
@@ -2849,18 +2849,12 @@ static ssize_t mtf_test_write(struct file *file, const char __user *buf,
 	struct seq_file *sf = (struct seq_file *)file->private_data;
 	struct mmc_card *card = (struct mmc_card *)sf->private;
 	struct mmc_test_card *test;
-	char lbuf[12];
 	long testcase;
+	int ret;
 
-	if (count >= sizeof(lbuf))
-		return -EINVAL;
-
-	if (copy_from_user(lbuf, buf, count))
-		return -EFAULT;
-	lbuf[count] = '\0';
-
-	if (strict_strtol(lbuf, 10, &testcase))
-		return -EINVAL;
+	ret = kstrtol_from_user(buf, count, 10, &testcase);
+	if (ret)
+		return ret;
 
 	test = kzalloc(sizeof(struct mmc_test_card), GFP_KERNEL);
 	if (!test)
Signature · 1 line
1.7.10.4
#1 lore raw

Hi Jingoo,

Quoted 29 lines · Jingoo Han

The usage of strict_strtol() is not preferred, because strict_strtol() is obsolete. Thus, kstrtol() should be used.

Also, both kstrtol() and copy_from_user() can be replaced with kstrtol_from_user() to make the code simpler.

---
 drivers/mmc/card/mmc_test.c |   14 ++++----------
 1 file changed, 4 insertions(+), 10 deletions(-)
drivers/mmc/card/mmc_test.c +1 -6
index a69df52..0c0fc52 100644
@@ -2849,18 +2849,12 @@ static ssize_t mtf_test_write(struct file *file, const char __user *buf,
 	struct seq_file *sf = (struct seq_file *)file->private_data;
 	struct mmc_card *card = (struct mmc_card *)sf->private;
 	struct mmc_test_card *test;
-	char lbuf[12];
 	long testcase;
+	int ret;
 
-	if (count >= sizeof(lbuf))
-		return -EINVAL;
-
-	if (copy_from_user(lbuf, buf, count))
-		return -EFAULT;

drivers/mmc/card/mmc_test.c static ssize_t mtf_test_write(struct file *file, const char __user *buf, · line 2860

Quoted 10 lines
drivers/mmc/card/mmc_test.c +3 -4
-	lbuf[count] = '\0';
-
-	if (strict_strtol(lbuf, 10, &testcase))
-		return -EINVAL;
+	ret = kstrtol_from_user(buf, count, 10, &testcase);
+	if (ret)
+		return ret;
 
 	test = kzalloc(sizeof(struct mmc_test_card), GFP_KERNEL);
 	if (!test)

Thanks, pushed to mmc-next for 3.12.

- Chris.

Signature · 1 line
Chris Ball   <[email protected]>   <http://printf.net/>