Skip to contentSkip to conversation

remove unneeded comparison

PATCH Superseded Sudip Mukherjee 1 participant 5 messages Mar 24, 2015 Staging

v3 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

PATCH v3 1/4 remove unneeded comparison

visorchipset_file_cleanup() is called from visorchipset_exit() which is the module_exit function and this function is executing means module_init succeeded, so registered will always be true at this time. and majordev has also been initialized in the init function. hence these comparisons will always be true.

---

v3: broke the previous patch in this series

 drivers/staging/unisys/visorchipset/file.c | 10 +++-------
 1 file changed, 3 insertions(+), 7 deletions(-)
drivers/staging/unisys/visorchipset/file.c +3 -7
index 9ca7f1e..cbed1ba2 100644
@@ -81,13 +81,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;
-	}
+	unregister_chrdev_region(majordev, 1);
+	majordev = MKDEV(0, 0);
+	registered = FALSE;
 }
 
 static int
Signature · 1 line
1.8.1.2
#1 lore raw

PATCH v3 2/4 use local dev_t instead of global

the dev_t is stored in visorchipset_platform_device.dev.devt, so we can pass that value as an argument to visorchipset_file_cleanup() instead of using the global variable in file.c

---

v3: broke the previous patch in this series

 drivers/staging/unisys/visorchipset/file.c              | 3 +--
 drivers/staging/unisys/visorchipset/file.h              | 2 +-
 drivers/staging/unisys/visorchipset/visorchipset_main.c | 2 +-
 3 files changed, 3 insertions(+), 4 deletions(-)
drivers/staging/unisys/visorchipset/file.c +1 -2
index cbed1ba2..d62908d 100644
@@ -76,13 +76,12 @@ visorchipset_file_init(dev_t major_dev, struct visorchannel **controlvm_channel)
 }
 
 void
-visorchipset_file_cleanup(void)
+visorchipset_file_cleanup(dev_t majordev)
 {
 	if (file_cdev.ops != NULL)
 		cdev_del(&file_cdev);
 	file_cdev.ops = NULL;
 	unregister_chrdev_region(majordev, 1);
-	majordev = MKDEV(0, 0);
 	registered = FALSE;
 }
 
drivers/staging/unisys/visorchipset/file.h +1 -1
index dc7a195..b32a472 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 majordev);
 
 #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
#2 lore raw

PATCH v3 3/4 use local variable instead of global

In reply to Sudip Mukherjee

dev_t was passed as an argument to visorchipset_file_init() which was storing that value in a global variable so that it can be used while cleanup. now we are no longer using the global variable in the cleanup so we donot need to keep the global variable anymore.

---

v3: broke the previous patch in this series

 drivers/staging/unisys/visorchipset/file.c | 10 ++++------
 1 file changed, 4 insertions(+), 6 deletions(-)
drivers/staging/unisys/visorchipset/file.c +4 -6
index d62908d..a52939a4 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 BOOL registered = FALSE;
 
 static int visorchipset_open(struct inode *inode, struct file *file);
@@ -55,21 +54,20 @@ 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(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;
 		registered = TRUE;
 	} 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;
 		registered = TRUE;
 	}
-	rc = cdev_add(&file_cdev, MKDEV(MAJOR(majordev), 0), 1);
+	rc = cdev_add(&file_cdev, major_dev, 1);
 	if (rc  < 0)
 		return -1;
 	return 0;
Signature · 1 line
1.8.1.2
#3 lore raw

PATCH v3 4/4 remove unused variable

In reply to Sudip Mukherjee

after the first patch of this series the registered variable was no longer required.

---

v3: broke the previous patch in this series

 drivers/staging/unisys/visorchipset/file.c | 4 ----
 1 file changed, 4 deletions(-)
drivers/staging/unisys/visorchipset/file.c +0 -4
index a52939a4..24cac93 100644
@@ -30,7 +30,6 @@
 
 static struct cdev file_cdev;
 static struct visorchannel **file_controlvm_channel;
-static BOOL registered = FALSE;
 
 static int visorchipset_open(struct inode *inode, struct file *file);
 static int visorchipset_release(struct inode *inode, struct file *file);
@@ -60,12 +59,10 @@ visorchipset_file_init(dev_t major_dev, struct visorchannel **controlvm_channel)
 		/* dynamic major device number registration required */
 		if (alloc_chrdev_region(&major_dev, 0, 1, MYDRVNAME) < 0)
 			return -1;
-		registered = TRUE;
 	} else {
 		/* static major device number registration required */
 		if (register_chrdev_region(major_dev, 1, MYDRVNAME) < 0)
 			return -1;
-		registered = TRUE;
 	}
 	rc = cdev_add(&file_cdev, major_dev, 1);
 	if (rc  < 0)
@@ -80,7 +77,6 @@ visorchipset_file_cleanup(dev_t majordev)
 		cdev_del(&file_cdev);
 	file_cdev.ops = NULL;
 	unregister_chrdev_region(majordev, 1);
-	registered = FALSE;
 }
 
 static int
Signature · 1 line
1.8.1.2
#4 lore raw
In reply to Sudip Mukherjee

On Tue, Mar 24, 2015 at 05:36:09PM +0530, Sudip Mukherjee wrote:

please scrap this series, I messed up the subject line and missed mentioning "staging: unisys"

i am sending a corrected copies as v4.
sorry for the noise.

regards
sudip