* [PATCH 1/3] staging: unisys: unregister chardev on error
@ 2015-03-27 8:30 Sudip Mukherjee
2015-03-27 8:30 ` [PATCH 2/3] staging: unisys: use error codes Sudip Mukherjee
` (2 more replies)
0 siblings, 3 replies; 6+ messages in thread
From: Sudip Mukherjee @ 2015-03-27 8:30 UTC (permalink / raw)
To: Benjamin Romer, David Kershner, Greg Kroah-Hartman
Cc: sparmaintainer, devel, linux-kernel, Sudip Mukherjee
after registering the major numbers if the cdev_add fails then we were
not releasing the major numbers. now we are doing that.
Signed-off-by: Sudip Mukherjee <sudip@vectorindia.org>
---
drivers/staging/unisys/visorchipset/file.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/drivers/staging/unisys/visorchipset/file.c b/drivers/staging/unisys/visorchipset/file.c
index 39b19af..074c285 100644
--- a/drivers/staging/unisys/visorchipset/file.c
+++ b/drivers/staging/unisys/visorchipset/file.c
@@ -65,8 +65,10 @@ visorchipset_file_init(dev_t major_dev, struct visorchannel **controlvm_channel)
return -1;
}
rc = cdev_add(&file_cdev, MKDEV(MAJOR(major_dev), 0), 1);
- if (rc < 0)
+ if (rc < 0) {
+ unregister_chrdev_region(major_dev, 1);
return -1;
+ }
return 0;
}
--
1.8.1.2
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH 2/3] staging: unisys: use error codes
2015-03-27 8:30 [PATCH 1/3] staging: unisys: unregister chardev on error Sudip Mukherjee
@ 2015-03-27 8:30 ` Sudip Mukherjee
2015-03-27 8:47 ` Greg Kroah-Hartman
2015-03-27 8:30 ` [PATCH 3/3] staging: unisys: remove forward declaration Sudip Mukherjee
2015-03-27 8:46 ` [PATCH 1/3] staging: unisys: unregister chardev on error Greg Kroah-Hartman
2 siblings, 1 reply; 6+ messages in thread
From: Sudip Mukherjee @ 2015-03-27 8:30 UTC (permalink / raw)
To: Benjamin Romer, David Kershner, Greg Kroah-Hartman
Cc: sparmaintainer, devel, linux-kernel, Sudip Mukherjee
we were just returning -1 to the calling function which was again
returning that if the module failed to load. Now we are returning the
actual error codes.
Signed-off-by: Sudip Mukherjee <sudip@vectorindia.org>
---
drivers/staging/unisys/visorchipset/file.c | 12 +++++++-----
1 file changed, 7 insertions(+), 5 deletions(-)
diff --git a/drivers/staging/unisys/visorchipset/file.c b/drivers/staging/unisys/visorchipset/file.c
index 074c285..552febc 100644
--- a/drivers/staging/unisys/visorchipset/file.c
+++ b/drivers/staging/unisys/visorchipset/file.c
@@ -56,18 +56,20 @@ visorchipset_file_init(dev_t major_dev, struct visorchannel **controlvm_channel)
cdev_init(&file_cdev, &visorchipset_fops);
file_cdev.owner = THIS_MODULE;
if (MAJOR(major_dev) == 0) {
+ rc = alloc_chrdev_region(&major_dev, 0, 1, MYDRVNAME);
/* dynamic major device number registration required */
- if (alloc_chrdev_region(&major_dev, 0, 1, MYDRVNAME) < 0)
- return -1;
+ if (rc < 0)
+ return rc;
} else {
/* static major device number registration required */
- if (register_chrdev_region(major_dev, 1, MYDRVNAME) < 0)
- return -1;
+ rc = register_chrdev_region(major_dev, 1, MYDRVNAME);
+ if (rc < 0)
+ return rc;
}
rc = cdev_add(&file_cdev, MKDEV(MAJOR(major_dev), 0), 1);
if (rc < 0) {
unregister_chrdev_region(major_dev, 1);
- return -1;
+ return rc;
}
return 0;
}
--
1.8.1.2
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH 3/3] staging: unisys: remove forward declaration
2015-03-27 8:30 [PATCH 1/3] staging: unisys: unregister chardev on error Sudip Mukherjee
2015-03-27 8:30 ` [PATCH 2/3] staging: unisys: use error codes Sudip Mukherjee
@ 2015-03-27 8:30 ` Sudip Mukherjee
2015-03-27 8:46 ` [PATCH 1/3] staging: unisys: unregister chardev on error Greg Kroah-Hartman
2 siblings, 0 replies; 6+ messages in thread
From: Sudip Mukherjee @ 2015-03-27 8:30 UTC (permalink / raw)
To: Benjamin Romer, David Kershner, Greg Kroah-Hartman
Cc: sparmaintainer, devel, linux-kernel, Sudip Mukherjee
rearranged the functions to get rid of the forward declarations.
Signed-off-by: Sudip Mukherjee <sudip@vectorindia.org>
---
drivers/staging/unisys/visorchipset/file.c | 80 ++++++++++++++----------------
1 file changed, 37 insertions(+), 43 deletions(-)
diff --git a/drivers/staging/unisys/visorchipset/file.c b/drivers/staging/unisys/visorchipset/file.c
index 552febc..479447a 100644
--- a/drivers/staging/unisys/visorchipset/file.c
+++ b/drivers/staging/unisys/visorchipset/file.c
@@ -31,49 +31,6 @@
static struct cdev file_cdev;
static struct visorchannel **file_controlvm_channel;
-static int visorchipset_open(struct inode *inode, struct file *file);
-static int visorchipset_release(struct inode *inode, struct file *file);
-static int visorchipset_mmap(struct file *file, struct vm_area_struct *vma);
-static long visorchipset_ioctl(struct file *file, unsigned int cmd,
- unsigned long arg);
-
-static const struct file_operations visorchipset_fops = {
- .owner = THIS_MODULE,
- .open = visorchipset_open,
- .read = NULL,
- .write = NULL,
- .unlocked_ioctl = visorchipset_ioctl,
- .release = visorchipset_release,
- .mmap = visorchipset_mmap,
-};
-
-int
-visorchipset_file_init(dev_t major_dev, struct visorchannel **controlvm_channel)
-{
- int rc = 0;
-
- file_controlvm_channel = controlvm_channel;
- cdev_init(&file_cdev, &visorchipset_fops);
- file_cdev.owner = THIS_MODULE;
- if (MAJOR(major_dev) == 0) {
- rc = alloc_chrdev_region(&major_dev, 0, 1, MYDRVNAME);
- /* dynamic major device number registration required */
- if (rc < 0)
- return rc;
- } else {
- /* static major device number registration required */
- rc = register_chrdev_region(major_dev, 1, MYDRVNAME);
- if (rc < 0)
- return rc;
- }
- rc = cdev_add(&file_cdev, MKDEV(MAJOR(major_dev), 0), 1);
- if (rc < 0) {
- unregister_chrdev_region(major_dev, 1);
- return rc;
- }
- return 0;
-}
-
void
visorchipset_file_cleanup(dev_t major_dev)
{
@@ -164,3 +121,40 @@ static long visorchipset_ioctl(struct file *file, unsigned int cmd,
return -EFAULT;
}
}
+
+static const struct file_operations visorchipset_fops = {
+ .owner = THIS_MODULE,
+ .open = visorchipset_open,
+ .read = NULL,
+ .write = NULL,
+ .unlocked_ioctl = visorchipset_ioctl,
+ .release = visorchipset_release,
+ .mmap = visorchipset_mmap,
+};
+
+int
+visorchipset_file_init(dev_t major_dev, struct visorchannel **controlvm_channel)
+{
+ int rc = 0;
+
+ file_controlvm_channel = controlvm_channel;
+ cdev_init(&file_cdev, &visorchipset_fops);
+ file_cdev.owner = THIS_MODULE;
+ if (MAJOR(major_dev) == 0) {
+ rc = alloc_chrdev_region(&major_dev, 0, 1, MYDRVNAME);
+ /* dynamic major device number registration required */
+ if (rc < 0)
+ return rc;
+ } else {
+ /* static major device number registration required */
+ rc = register_chrdev_region(major_dev, 1, MYDRVNAME);
+ if (rc < 0)
+ return rc;
+ }
+ rc = cdev_add(&file_cdev, MKDEV(MAJOR(major_dev), 0), 1);
+ if (rc < 0) {
+ unregister_chrdev_region(major_dev, 1);
+ return rc;
+ }
+ return 0;
+}
--
1.8.1.2
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH 1/3] staging: unisys: unregister chardev on error
2015-03-27 8:30 [PATCH 1/3] staging: unisys: unregister chardev on error Sudip Mukherjee
2015-03-27 8:30 ` [PATCH 2/3] staging: unisys: use error codes Sudip Mukherjee
2015-03-27 8:30 ` [PATCH 3/3] staging: unisys: remove forward declaration Sudip Mukherjee
@ 2015-03-27 8:46 ` Greg Kroah-Hartman
2 siblings, 0 replies; 6+ messages in thread
From: Greg Kroah-Hartman @ 2015-03-27 8:46 UTC (permalink / raw)
To: Sudip Mukherjee
Cc: Benjamin Romer, David Kershner, sparmaintainer, devel, linux-kernel
On Fri, Mar 27, 2015 at 02:00:57PM +0530, Sudip Mukherjee wrote:
> after registering the major numbers if the cdev_add fails then we were
> not releasing the major numbers. now we are doing that.
>
> Signed-off-by: Sudip Mukherjee <sudip@vectorindia.org>
> ---
> drivers/staging/unisys/visorchipset/file.c | 4 +++-
> 1 file changed, 3 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/staging/unisys/visorchipset/file.c b/drivers/staging/unisys/visorchipset/file.c
> index 39b19af..074c285 100644
> --- a/drivers/staging/unisys/visorchipset/file.c
> +++ b/drivers/staging/unisys/visorchipset/file.c
> @@ -65,8 +65,10 @@ visorchipset_file_init(dev_t major_dev, struct visorchannel **controlvm_channel)
> return -1;
> }
> rc = cdev_add(&file_cdev, MKDEV(MAJOR(major_dev), 0), 1);
> - if (rc < 0)
> + if (rc < 0) {
Care to delete the extra space while you are modifying this line?
> + unregister_chrdev_region(major_dev, 1);
> return -1;
It's not your fault, and don't change this, but something that needs to
be fixed up in the future are these "random" negative numbers being
returned. Use proper -ERROR #defines instead.
thanks,
greg k-h
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH 2/3] staging: unisys: use error codes
2015-03-27 8:30 ` [PATCH 2/3] staging: unisys: use error codes Sudip Mukherjee
@ 2015-03-27 8:47 ` Greg Kroah-Hartman
2015-03-27 9:45 ` Sudip Mukherjee
0 siblings, 1 reply; 6+ messages in thread
From: Greg Kroah-Hartman @ 2015-03-27 8:47 UTC (permalink / raw)
To: Sudip Mukherjee
Cc: Benjamin Romer, David Kershner, sparmaintainer, devel, linux-kernel
On Fri, Mar 27, 2015 at 02:00:58PM +0530, Sudip Mukherjee wrote:
> we were just returning -1 to the calling function which was again
> returning that if the module failed to load. Now we are returning the
> actual error codes.
>
> Signed-off-by: Sudip Mukherjee <sudip@vectorindia.org>
> ---
> drivers/staging/unisys/visorchipset/file.c | 12 +++++++-----
> 1 file changed, 7 insertions(+), 5 deletions(-)
>
> diff --git a/drivers/staging/unisys/visorchipset/file.c b/drivers/staging/unisys/visorchipset/file.c
> index 074c285..552febc 100644
> --- a/drivers/staging/unisys/visorchipset/file.c
> +++ b/drivers/staging/unisys/visorchipset/file.c
> @@ -56,18 +56,20 @@ visorchipset_file_init(dev_t major_dev, struct visorchannel **controlvm_channel)
> cdev_init(&file_cdev, &visorchipset_fops);
> file_cdev.owner = THIS_MODULE;
> if (MAJOR(major_dev) == 0) {
> + rc = alloc_chrdev_region(&major_dev, 0, 1, MYDRVNAME);
> /* dynamic major device number registration required */
> - if (alloc_chrdev_region(&major_dev, 0, 1, MYDRVNAME) < 0)
> - return -1;
> + if (rc < 0)
> + return rc;
> } else {
> /* static major device number registration required */
> - if (register_chrdev_region(major_dev, 1, MYDRVNAME) < 0)
> - return -1;
> + rc = register_chrdev_region(major_dev, 1, MYDRVNAME);
> + if (rc < 0)
> + return rc;
> }
> rc = cdev_add(&file_cdev, MKDEV(MAJOR(major_dev), 0), 1);
> if (rc < 0) {
> unregister_chrdev_region(major_dev, 1);
> - return -1;
> + return rc;
I should have kept reading in the patch series, nice fix up :)
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH 2/3] staging: unisys: use error codes
2015-03-27 8:47 ` Greg Kroah-Hartman
@ 2015-03-27 9:45 ` Sudip Mukherjee
0 siblings, 0 replies; 6+ messages in thread
From: Sudip Mukherjee @ 2015-03-27 9:45 UTC (permalink / raw)
To: Greg Kroah-Hartman
Cc: Benjamin Romer, David Kershner, sparmaintainer, devel, linux-kernel
On Fri, Mar 27, 2015 at 09:47:16AM +0100, Greg Kroah-Hartman wrote:
> On Fri, Mar 27, 2015 at 02:00:58PM +0530, Sudip Mukherjee wrote:
> > }
> > rc = cdev_add(&file_cdev, MKDEV(MAJOR(major_dev), 0), 1);
> > if (rc < 0) {
> > unregister_chrdev_region(major_dev, 1);
> > - return -1;
> > + return rc;
>
> I should have kept reading in the patch series, nice fix up :)
some effect of learning from you and Dan :)
thanks
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2015-03-27 9:45 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-03-27 8:30 [PATCH 1/3] staging: unisys: unregister chardev on error Sudip Mukherjee
2015-03-27 8:30 ` [PATCH 2/3] staging: unisys: use error codes Sudip Mukherjee
2015-03-27 8:47 ` Greg Kroah-Hartman
2015-03-27 9:45 ` Sudip Mukherjee
2015-03-27 8:30 ` [PATCH 3/3] staging: unisys: remove forward declaration Sudip Mukherjee
2015-03-27 8:46 ` [PATCH 1/3] staging: unisys: unregister chardev on error Greg Kroah-Hartman
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.