Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1206294

[PATCH] staging: wilc1000: Process WARN, INFO options of debug levels from user

From Chandra S Gorentla <csgorentla@gmail.com>
Newsgroups linux.kernel
Subject [PATCH] staging: wilc1000: Process WARN, INFO options of debug levels from user
Date 2015-08-12 19:40 +0200
Message-ID <pWIan-2Ol-43@gated-at.bofh.it> (permalink)
Organization linux.* mail to news gateway

Show all headers | View raw


This patch enables setting the module's debug options WARN and INFO in the
debugfs file 'wilc_debug_level'.  This enables the user to enable logging
of warning and other information.  Before this change writes to this debugfs
file sets only one option DGB.  This is additional to the default option
ERR.

As a side effect, this patch removes the 'sparse' warning -
'warning: incorrect type in argument 2 (different address spaces)'.

Signed-off-by: Chandra S Gorentla <csgorentla@gmail.com>
---
 drivers/staging/wilc1000/wilc_debugfs.c | 26 ++++++++++++--------------
 1 file changed, 12 insertions(+), 14 deletions(-)

diff --git a/drivers/staging/wilc1000/wilc_debugfs.c b/drivers/staging/wilc1000/wilc_debugfs.c
index be2e901..3934e8b 100644
--- a/drivers/staging/wilc1000/wilc_debugfs.c
+++ b/drivers/staging/wilc1000/wilc_debugfs.c
@@ -48,29 +48,26 @@ static ssize_t wilc_debug_level_read(struct file *file, char __user *userbuf, si
 	return simple_read_from_buffer(userbuf, count, ppos, buf, res);
 }
 
-static ssize_t wilc_debug_level_write(struct file *filp, const char *buf, size_t count, loff_t *ppos)
+static ssize_t wilc_debug_level_write(struct file *filp, const char __user *buf,
+					size_t count, loff_t *ppos)
 {
-	char buffer[128] = {};
+	char buffer[2] = {};  /* One character for 'level' + one for null */
 	int flag = 0;
+	int ret;
 
 	if (count > sizeof(buffer))
 		return -EINVAL;
 
-	if (copy_from_user(buffer, buf, count)) {
+	ret = simple_write_to_buffer(buffer, sizeof(buffer), ppos, buf, count);
+	if (ret != count)
 		return -EFAULT;
-	}
-
-	flag = buffer[0] - '0';
 
-	if (flag > 0)
-		flag = DEBUG | ERR;
-	else if (flag < 0)
-		flag = 100;
+	ret = kstrtoint(buffer, 16, &flag);
+	if (ret)
+		return -EINVAL;
 
-	if (flag > DBG_LEVEL_ALL) {
-		printk("%s, value (0x%08x) is out of range, stay previous flag (0x%08x)\n", __func__, flag, atomic_read(&DEBUG_LEVEL));
-		return -EFAULT;
-	}
+	if (flag > DBG_LEVEL_ALL)
+		return -EINVAL;
 
 	atomic_set(&DEBUG_LEVEL, (int)flag);
 
@@ -78,6 +75,7 @@ static ssize_t wilc_debug_level_write(struct file *filp, const char *buf, size_t
 		printk("Debug-level disabled\n");
 	else
 		printk("Debug-level enabled\n");
+
 	return count;
 }
 
-- 
2.5.0

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Back to linux.kernel | Previous | NextNext in thread | Find similar | Unroll thread


Thread

[PATCH] staging: wilc1000: Process WARN, INFO options of debug levels from user Chandra S Gorentla <csgorentla@gmail.com> - 2015-08-12 19:40 +0200
  Re: [PATCH] staging: wilc1000: Process WARN, INFO options of debug  levels from user Dan Carpenter <dan.carpenter@oracle.com> - 2015-08-13 21:10 +0200

csiph-web