Skip to contentSkip to conversation

staging: unisys: remove redundant variable

PATCH In review Sudip Mukherjee 4 participants 9 messages Mar 24, 2015 – Mar 26, 2015 Staging

lore
Share & tools
lore
#0 lore raw

PATCH v5 1/5 staging: unisys: remove redundant variable

remove the variable "registered", which was used in the cleanup() to detect if the driver has successfully initialized. the cleanup() is called from module_exit, so its obvious that the module has successfully initialized. if the initialization had failed, then we will never be in the cleanup().

---

v5: reordered the patch series
v4: messed up the subject in v3
v3: broke the previous patch in series

 drivers/staging/unisys/visorchipset/file.c | 12 +++---------
 1 file changed, 3 insertions(+), 9 deletions(-)
drivers/staging/unisys/visorchipset/file.c +3 -9
index 9ca7f1e..b426762 100644
@@ -31,7 +31,6 @@
 static struct cdev file_cdev;
 static struct visorchannel **file_controlvm_channel;
 static dev_t majordev = -1; /**< indicates major num for device */
-static BOOL registered = FALSE;
 
 static int visorchipset_open(struct inode *inode, struct file *file);
 static int visorchipset_release(struct inode *inode, struct file *file);
@@ -62,12 +61,10 @@ visorchipset_file_init(dev_t major_dev, struct visorchannel **controlvm_channel)
 		/* dynamic major device number registration required */
 		if (alloc_chrdev_region(&majordev, 0, 1, MYDRVNAME) < 0)
 			return -1;
-		registered = TRUE;
 	} else {
 		/* static major device number registration required */
 		if (register_chrdev_region(majordev, 1, MYDRVNAME) < 0)
 			return -1;
-		registered = TRUE;
 	}
 	rc = cdev_add(&file_cdev, MKDEV(MAJOR(majordev), 0), 1);
 	if (rc  < 0)
@@ -81,12 +78,9 @@ visorchipset_file_cleanup(void)
 	if (file_cdev.ops != NULL)
 		cdev_del(&file_cdev);
 	file_cdev.ops = NULL;
-	if (registered) {
-		if (MAJOR(majordev) >= 0) {
-			unregister_chrdev_region(majordev, 1);
-			majordev = MKDEV(0, 0);
-		}
-		registered = FALSE;
+	if (MAJOR(majordev) >= 0) {
+		unregister_chrdev_region(majordev, 1);
+		majordev = MKDEV(0, 0);
 	}
 }
 
Signature · 1 line
1.8.1.2
#1 lore raw

PATCH v5 2/5 staging: unisys: use local variable

we are getting dev_t as an argument in the function, so use the local variable instead of the global variable "majordev".
this global variable will be removed in one of the next patch of the series.

---

v5: reordered the patch series
v4: messed up the subject in v3
v3: broke the previous patch in series

 drivers/staging/unisys/visorchipset/file.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/staging/unisys/visorchipset/file.c +4 -4
index b426762..6ebe7f7 100644
@@ -57,16 +57,16 @@ visorchipset_file_init(dev_t major_dev, struct visorchannel **controlvm_channel)
 	majordev = major_dev;
 	cdev_init(&file_cdev, &visorchipset_fops);
 	file_cdev.owner = THIS_MODULE;
-	if (MAJOR(majordev) == 0) {
+	if (MAJOR(major_dev) == 0) {
 		/* dynamic major device number registration required */
-		if (alloc_chrdev_region(&majordev, 0, 1, MYDRVNAME) < 0)
+		if (alloc_chrdev_region(&major_dev, 0, 1, MYDRVNAME) < 0)
 			return -1;
 	} else {
 		/* static major device number registration required */
-		if (register_chrdev_region(majordev, 1, MYDRVNAME) < 0)
+		if (register_chrdev_region(major_dev, 1, MYDRVNAME) < 0)
 			return -1;
 	}
-	rc = cdev_add(&file_cdev, MKDEV(MAJOR(majordev), 0), 1);
+	rc = cdev_add(&file_cdev, MKDEV(MAJOR(major_dev), 0), 1);
 	if (rc  < 0)
 		return -1;
 	return 0;
Signature · 1 line
1.8.1.2
#2 lore raw

PATCH v5 3/5 staging: unisys: use local variable in cleanup

In reply to Sudip Mukherjee

the dev_t was being stored in visorchipset_platform_device.dev.devt while initializing the module. so pass that value as an argument to cleanup() so that it can use this local variable instead of the global variable.

---

v5: reordered the patch series
v4: messed up the subject in v3
v3: broke the previous patch in series

 drivers/staging/unisys/visorchipset/file.c              | 6 +++---
 drivers/staging/unisys/visorchipset/file.h              | 2 +-
 drivers/staging/unisys/visorchipset/visorchipset_main.c | 2 +-
 3 files changed, 5 insertions(+), 5 deletions(-)
drivers/staging/unisys/visorchipset/file.c +3 -3
index 6ebe7f7..257cfdd 100644
@@ -73,13 +73,13 @@ visorchipset_file_init(dev_t major_dev, struct visorchannel **controlvm_channel)
 }
 
 void
-visorchipset_file_cleanup(void)
+visorchipset_file_cleanup(dev_t major_dev)
 {
 	if (file_cdev.ops != NULL)
 		cdev_del(&file_cdev);
 	file_cdev.ops = NULL;
-	if (MAJOR(majordev) >= 0) {
-		unregister_chrdev_region(majordev, 1);
+	if (MAJOR(major_dev) >= 0) {
+		unregister_chrdev_region(major_dev, 1);
 		majordev = MKDEV(0, 0);
 	}
 }
drivers/staging/unisys/visorchipset/file.h +1 -1
index dc7a195..51f7699 100644
@@ -22,6 +22,6 @@
 
 int visorchipset_file_init(dev_t majorDev,
 			   struct visorchannel **pControlVm_channel);
-void visorchipset_file_cleanup(void);
+void visorchipset_file_cleanup(dev_t major_dev);
 
 #endif
drivers/staging/unisys/visorchipset/visorchipset_main.c +1 -1
index 9c8605d..f2663d2c 100644
@@ -2278,7 +2278,7 @@ visorchipset_exit(void)
 
 	visorchannel_destroy(controlvm_channel);
 
-	visorchipset_file_cleanup();
+	visorchipset_file_cleanup(visorchipset_platform_device.dev.devt);
 	POSTCODE_LINUX_2(DRIVER_EXIT_PC, POSTCODE_SEVERITY_INFO);
 }
 
Signature · 1 line
1.8.1.2
#3 lore raw

PATCH v5 4/5 staging: unisys: remove global dev_t

In reply to Sudip Mukherjee

the global variable majordev is no longer required, as it is not being used anywhere.

---

v5: reordered the patch series
v4: messed up the subject in v3
v3: broke the previous patch in series

 drivers/staging/unisys/visorchipset/file.c | 3 ---
 1 file changed, 3 deletions(-)
drivers/staging/unisys/visorchipset/file.c +0 -3
index 257cfdd..890869a 100644
@@ -30,7 +30,6 @@
 
 static struct cdev file_cdev;
 static struct visorchannel **file_controlvm_channel;
-static dev_t majordev = -1; /**< indicates major num for device */
 
 static int visorchipset_open(struct inode *inode, struct file *file);
 static int visorchipset_release(struct inode *inode, struct file *file);
@@ -54,7 +53,6 @@ visorchipset_file_init(dev_t major_dev, struct visorchannel **controlvm_channel)
 	int rc = 0;
 
 	file_controlvm_channel = controlvm_channel;
-	majordev = major_dev;
 	cdev_init(&file_cdev, &visorchipset_fops);
 	file_cdev.owner = THIS_MODULE;
 	if (MAJOR(major_dev) == 0) {
@@ -80,7 +78,6 @@ visorchipset_file_cleanup(dev_t major_dev)
 	file_cdev.ops = NULL;
 	if (MAJOR(major_dev) >= 0) {
 		unregister_chrdev_region(major_dev, 1);
-		majordev = MKDEV(0, 0);
 	}
 }
 
Signature · 1 line
1.8.1.2
#4 lore raw

PATCH v5 5/5 staging: unisys: remove comparison

In reply to Sudip Mukherjee

the comparison is always true as the dev_t has been initialized in the init function and we are sending that initialized dev_t to the cleanup().

---

v5: reordered the patch series
v4: messed up the subject in v3
v3: broke the previous patch in series

 drivers/staging/unisys/visorchipset/file.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)
drivers/staging/unisys/visorchipset/file.c +1 -3
index 890869a..39b19af 100644
@@ -76,9 +76,7 @@ visorchipset_file_cleanup(dev_t major_dev)
 	if (file_cdev.ops != NULL)
 		cdev_del(&file_cdev);
 	file_cdev.ops = NULL;
-	if (MAJOR(major_dev) >= 0) {
-		unregister_chrdev_region(major_dev, 1);
-	}
+	unregister_chrdev_region(major_dev, 1);
 }
 
 static int
Signature · 1 line
1.8.1.2
#6 lore raw
In reply to Sudip Mukherjee
Quoted 6 lines · Sudip Mukherjee

remove the variable "registered", which was used in the cleanup() to detect if the driver has successfully initialized. the cleanup() is called from module_exit, so its obvious that the module has successfully initialized. if the initialization had failed, then we will never be in the cleanup().

Quoted 6 lines

---

v5: reordered the patch series
v4: messed up the subject in v3
v3: broke the previous patch in series

I need an ack from Benjamin and/or David before I can take these, as they are the maintainers of the driver, and have the ability to test these patches.

I'll just wait to apply them until that happens.

Ben/David?

thanks,

greg k-h

#7 lore raw
Quoted 7 lines · Greg Kroah-Hartman

I need an ack from Benjamin and/or David before I can take these, as they are the maintainers of the driver, and have the ability to test these patches.

I'll just wait to apply them until that happens.

Ben/David?

I'll test them today. :)

-- Ben

#8 lore raw
Quoted 5 lines · Ben Romer
Quoted 4 lines · Greg Kroah-Hartman

I need an ack from Benjamin and/or David before I can take these, as they are the maintainers of the driver, and have the ability to test these patches.

Quoted 8 lines
Quoted 3 lines

I'll just wait to apply them until that happens.

Ben/David?

I'll test them today. :)

-- Ben

I've tested them and everything appears to function correctly, so please accept this patch series.

Thanks!

-- Ben