Skip to contentSkip to conversation

The function register_chrdev_region() for count=0 returns a false success.This patch pre

PATCH New Matthew Wilcox 3 participants 5 messages Apr 25, 2008

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

Review

Quoted 1 line · anubhav rakshit
(quoted diff) +1 -0
+	if(unlikely(count = 0))

A space between 'if' and '(', please. scripts/checkpatch.pl can warn you about this kind of thing.

Signature · 4 lines
Intel are signing my paycheques ... these opinions are still mine
"Bill, look, we understand that you're interested in selling us this
operating system, but compare it to ours.  We can't possibly take such
a retrograde step."
#1 lore raw

Re: [PATCH] The function register_chrdev_region() for count=0

Quoted 21 lines · anubhav rakshit
---
 fs/char_dev.c |    5 ++++-
 1 files changed, 4 insertions(+), 1 deletions(-)
fs/char_dev.c +4 -1
index 038674a..f4c371a 100644
@@ -199,7 +199,10 @@ int register_chrdev_region(dev_t from, unsigned
 count, const char *name)
 	struct char_device_struct *cd;
 	dev_t to = from + count;
 	dev_t n, next;
-
+	
+	if(unlikely(count = 0))
+		return -EINVAL;
+	
 	for (n = from; n < to; n = next) {
 		next = MKDEV(MAJOR(n)+1, 0);
Quoted 1 line

if (next > to)

I'd say
a) unlikely in such rarely used function is useless
b)

	register_chrdev_region(from, 0, name);
	unregister_chrdev_region(from, 0);

will unregister region sucessfully ;-)

c) this is problem of a caller -- don't!

#2 lore raw

PATCH 1/1 The function register_chrdev_region() for count=0 returns a false success.This patch prevent

In reply to Matthew Wilcox
---
 fs/char_dev.c |    5 ++++-
 1 files changed, 4 insertions(+), 1 deletions(-)
fs/char_dev.c +0 -0
index 038674a..f4c371a 100644
@@ -199,7 +199,10 @@ int register_chrdev_region(dev_t from, unsigned

count, const char *name)
struct char_device_struct *cd;
dev_t to = from + count;
dev_t n, next;
-
+
+ if(unlikely(count = 0))
+ return -EINVAL;
+
for (n = from; n < to; n = next) {
next = MKDEV(MAJOR(n)+1, 0);
if (next > to)

Signature · 2 lines
-- 
Anubhav Rakshit
#3 lore raw
In reply to Matthew Wilcox
Quoted 29 lines · Alexey Dobriyan
Quoted 21 lines · anubhav rakshit
---
 fs/char_dev.c |    5 ++++-
 1 files changed, 4 insertions(+), 1 deletions(-)
fs/char_dev.c +4 -1
index 038674a..f4c371a 100644
@@ -199,7 +199,10 @@ int register_chrdev_region(dev_t from, unsigned
 count, const char *name)
      struct char_device_struct *cd;
      dev_t to = from + count;
      dev_t n, next;
-
+
+     if(unlikely(count = 0))
+             return -EINVAL;
+
      for (n = from; n < to; n = next) {
              next = MKDEV(MAJOR(n)+1, 0);
Quoted 1 line

if (next > to)

I'd say
a) unlikely in such rarely used function is useless
b)

Quoted 4 lines
        register_chrdev_region(from, 0, name);
        unregister_chrdev_region(from, 0);

will unregister region sucessfully ;-)

register_chrdev_region() doesnot actually succeed with count=0.The
caller should be notified about this.

Quoted 2 lines

c) this is problem of a caller -- don't!

Exactly and he/she should be notified.

Quoted 2 lines
Signature · 1 line
Anubhav Rakshit
#4 lore raw
In reply to Matthew Wilcox

<--snip-->

Quoted 2 lines

A space between 'if' and '(', please. scripts/checkpatch.pl can warn you about this kind of thing.

<--snip-->
Resending with corrections

---
 fs/char_dev.c |    3 +++
 1 files changed, 3 insertions(+), 0 deletions(-)
fs/char_dev.c +0 -0
index 038674a..e042aa7 100644
@@ -200,6 +200,9 @@ int register_chrdev_region(dev_t from, unsigned

count, const char *name)
dev_t to = from + count;
dev_t n, next;

+ if (unlikely(count = 0))
+ return -EINVAL;
+
for (n = from; n < to; n = next) {
next = MKDEV(MAJOR(n)+1, 0);
if (next > to)
--