Skip to contentSkip to conversation

drivers: char: Replace "foo * bar" with "foo *bar".

PATCH New Varsha Rao 1 participant 5 messages Apr 3, 2017 1 message not in the archive Char and misc drivers

lore
Share & tools
lore

Varsha Rao

author
#1 lore raw

PATCH 1/5 drivers: char: Replace "foo * bar" with "foo *bar".

In reply to a message not in the archive

Remove space after * in pointer type, to follow Linux coding style. This patch fixes the following checkpatch issue:

ERROR: "foo * bar" should be "foo *bar"

---
 drivers/char/misc.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/char/misc.c +2 -2
index 8069b36..ed8f79c 100644
@@ -109,7 +109,7 @@ static const struct file_operations misc_proc_fops = {
 };
 #endif
 
-static int misc_open(struct inode * inode, struct file * file)
+static int misc_open(struct inode *inode, struct file *file)
 {
 	int minor = iminor(inode);
 	struct miscdevice *c;
@@ -182,7 +182,7 @@ static const struct file_operations misc_fops = {
  *	failure.
  */
 
-int misc_register(struct miscdevice * misc)
+int misc_register(struct miscdevice *misc)
 {
 	dev_t dev;
 	int err = 0;
Signature · 1 line
2.9.3
author
#2 lore raw

PATCH 2/5 drivers: char: Add space after ','.

In reply to a message not in the archive

Add space which is required after ',' to follow Linux coding style. This patch fixes the checkpatch issue.

---
 drivers/char/misc.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/char/misc.c +2 -2
index ed8f79c..3a19fa3 100644
@@ -150,7 +150,7 @@ static int misc_open(struct inode *inode, struct file *file)
 	err = 0;
 	replace_fops(file, new_fops);
 	if (file->f_op->open)
-		err = file->f_op->open(inode,file);
+		err = file->f_op->open(inode, file);
 fail:
 	mutex_unlock(&misc_mtx);
 	return err;
@@ -287,7 +287,7 @@ static int __init misc_init(void)
 		goto fail_remove;
 
 	err = -EIO;
-	if (register_chrdev(MISC_MAJOR,"misc",&misc_fops))
+	if (register_chrdev(MISC_MAJOR, "misc", &misc_fops))
 		goto fail_printk;
 	misc_class->devnode = misc_devnode;
 	return 0;
Signature · 1 line
2.9.3
author
#3 lore raw

PATCH 3/5 drivers: char: Add blank line after declarations.

In reply to a message not in the archive

Add a blank line after declarations, to fix the checkpatch issue.

---
 drivers/char/misc.c | 1 +
 1 file changed, 1 insertion(+)
drivers/char/misc.c +1 -0
index 3a19fa3..1312e29 100644
@@ -194,6 +194,7 @@ int misc_register(struct miscdevice *misc)
 
 	if (is_dynamic) {
 		int i = find_first_zero_bit(misc_minors, DYNAMIC_MINORS);
+
 		if (i >= DYNAMIC_MINORS) {
 			err = -EBUSY;
 			goto out;
Signature · 1 line
2.9.3
author
#4 lore raw

PATCH 4/5 drivers: char: Replace printk with pr_err.

In reply to a message not in the archive

Replace printk with pr_err to fix the checkpatch issue.

---
 drivers/char/misc.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/char/misc.c +1 -1
index 1312e29..c9cd1ea 100644
@@ -294,7 +294,7 @@ static int __init misc_init(void)
 	return 0;
 
 fail_printk:
-	printk("unable to get major %d for misc devices\n", MISC_MAJOR);
+	pr_err("unable to get major %d for misc devices\n", MISC_MAJOR);
 	class_destroy(misc_class);
 fail_remove:
 	if (ret)
Signature · 1 line
2.9.3
author
#5 lore raw

PATCH 5/5 drivers: char: Replace bit operation functions with IDA allocator.

In reply to a message not in the archive

Replace bit operation functions with IDA allocator functions. As IDA allocation is simpler.

---
 drivers/char/misc.c | 16 ++++++++++------
 1 file changed, 10 insertions(+), 6 deletions(-)
drivers/char/misc.c +10 -6
index c9cd1ea..5786281 100644
@@ -60,7 +60,7 @@ static DEFINE_MUTEX(misc_mtx);
  * Assigned numbers, used for dynamic minors
  */
 #define DYNAMIC_MINORS 64 /* like dynamic majors */
-static DECLARE_BITMAP(misc_minors, DYNAMIC_MINORS);
+static DEFINE_IDA(misc_minors_ida);
 
 #ifdef CONFIG_PROC_FS
 static void *misc_seq_start(struct seq_file *seq, loff_t *pos)
@@ -193,14 +193,18 @@ int misc_register(struct miscdevice *misc)
 	mutex_lock(&misc_mtx);
 
 	if (is_dynamic) {
-		int i = find_first_zero_bit(misc_minors, DYNAMIC_MINORS);
+		int i = ida_simple_get(&misc_minors_ida, 0,
+				       DYNAMIC_MINORS, GFP_KERNEL);
 
 		if (i >= DYNAMIC_MINORS) {
 			err = -EBUSY;
 			goto out;
-		}
+		} else if (i < 0) {
+			err = i;
+			goto out;
+		} else {
 		misc->minor = DYNAMIC_MINORS - i - 1;
-		set_bit(i, misc_minors);
+		}
 	} else {
 		struct miscdevice *c;
 
@@ -222,7 +226,7 @@ int misc_register(struct miscdevice *misc)
 			int i = DYNAMIC_MINORS - misc->minor - 1;
 
 			if (i < DYNAMIC_MINORS && i >= 0)
-				clear_bit(i, misc_minors);
+				ida_simple_remove(&misc_minors_ida, i);
 			misc->minor = MISC_DYNAMIC_MINOR;
 		}
 		err = PTR_ERR(misc->this_device);
@@ -258,7 +262,7 @@ void misc_deregister(struct miscdevice *misc)
 	list_del(&misc->list);
 	device_destroy(misc_class, MKDEV(MISC_MAJOR, misc->minor));
 	if (i < DYNAMIC_MINORS && i >= 0)
-		clear_bit(i, misc_minors);
+		ida_simple_remove(&misc_minors_ida, i);
 	mutex_unlock(&misc_mtx);
 }
 
Signature · 1 line
2.9.3