lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-Id: <1426604484-7770-1-git-send-email-sudipm.mukherjee@gmail.com>
Date:	Tue, 17 Mar 2015 20:31:24 +0530
From:	Sudip Mukherjee <sudipm.mukherjee@...il.com>
To:	Benjamin Romer <benjamin.romer@...sys.com>,
	David Kershner <david.kershner@...sys.com>,
	Greg Kroah-Hartman <gregkh@...uxfoundation.org>
Cc:	Sudip Mukherjee <sudipm.mukherjee@...il.com>,
	sparmaintainer@...sys.com, devel@...verdev.osuosl.org,
	linux-kernel@...r.kernel.org
Subject: [PATCH] staging: unisys: handle major number properly

fixed the handling of dev_t and the major number.
now the major and minor number is passed to the init function.
similarly in the cleanup function dev_t is passed to unregister it.

Signed-off-by: Sudip Mukherjee <sudip@...torindia.org>
---
 drivers/staging/unisys/visorchipset/file.c             | 18 ++++++++----------
 drivers/staging/unisys/visorchipset/file.h             |  4 ++--
 .../staging/unisys/visorchipset/visorchipset_main.c    | 10 +++-------
 3 files changed, 13 insertions(+), 19 deletions(-)

diff --git a/drivers/staging/unisys/visorchipset/file.c b/drivers/staging/unisys/visorchipset/file.c
index 9ca7f1e..224e214 100644
--- a/drivers/staging/unisys/visorchipset/file.c
+++ b/drivers/staging/unisys/visorchipset/file.c
@@ -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);
@@ -50,15 +49,17 @@ static const struct file_operations visorchipset_fops = {
 };
 
 int
-visorchipset_file_init(dev_t major_dev, struct visorchannel **controlvm_channel)
+visorchipset_file_init(int major, int minor,
+		       struct visorchannel **controlvm_channel)
 {
 	int rc = 0;
+	dev_t majordev;
 
 	file_controlvm_channel = controlvm_channel;
-	majordev = major_dev;
 	cdev_init(&file_cdev, &visorchipset_fops);
 	file_cdev.owner = THIS_MODULE;
-	if (MAJOR(majordev) == 0) {
+	majordev = MKDEV(major, minor);
+	if (major == 0) {
 		/* dynamic major device number registration required */
 		if (alloc_chrdev_region(&majordev, 0, 1, MYDRVNAME) < 0)
 			return -1;
@@ -69,23 +70,20 @@ visorchipset_file_init(dev_t major_dev, struct visorchannel **controlvm_channel)
 			return -1;
 		registered = TRUE;
 	}
-	rc = cdev_add(&file_cdev, MKDEV(MAJOR(majordev), 0), 1);
+	rc = cdev_add(&file_cdev, MKDEV(major, 0), 1);
 	if (rc  < 0)
 		return -1;
 	return 0;
 }
 
 void
-visorchipset_file_cleanup(void)
+visorchipset_file_cleanup(dev_t majordev)
 {
 	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);
-		}
+		unregister_chrdev_region(majordev, 1);
 		registered = FALSE;
 	}
 }
diff --git a/drivers/staging/unisys/visorchipset/file.h b/drivers/staging/unisys/visorchipset/file.h
index dc7a195..213b3a3 100644
--- a/drivers/staging/unisys/visorchipset/file.h
+++ b/drivers/staging/unisys/visorchipset/file.h
@@ -20,8 +20,8 @@
 
 #include "globals.h"
 
-int visorchipset_file_init(dev_t majorDev,
+int visorchipset_file_init(int major, int minor,
 			   struct visorchannel **pControlVm_channel);
-void visorchipset_file_cleanup(void);
+void visorchipset_file_cleanup(dev_t majordev);
 
 #endif
diff --git a/drivers/staging/unisys/visorchipset/visorchipset_main.c b/drivers/staging/unisys/visorchipset/visorchipset_main.c
index ec258ae..17d3b3f 100644
--- a/drivers/staging/unisys/visorchipset/visorchipset_main.c
+++ b/drivers/staging/unisys/visorchipset/visorchipset_main.c
@@ -241,9 +241,6 @@ static struct visorchipset_busdev_responders BusDev_Responders = {
 	.device_resume = device_resume_response,
 };
 
-/* info for /dev/visorchipset */
-static dev_t MajorDev = -1; /**< indicates major num for device */
-
 /* prototypes for attributes */
 static ssize_t toolaction_show(struct device *dev,
 	struct device_attribute *attr, char *buf);
@@ -2225,8 +2222,7 @@ visorchipset_init(void)
 		return -ENODEV;
 	}
 
-	MajorDev = MKDEV(visorchipset_major, 0);
-	rc = visorchipset_file_init(MajorDev, &ControlVm_channel);
+	rc = visorchipset_file_init(visorchipset_major, 0, &ControlVm_channel);
 	if (rc < 0) {
 		POSTCODE_LINUX_2(CHIPSET_INIT_FAILURE_PC, DIAG_SEVERITY_ERR);
 		goto Away;
@@ -2276,7 +2272,7 @@ visorchipset_init(void)
 
 	}
 
-	Visorchipset_platform_device.dev.devt = MajorDev;
+	Visorchipset_platform_device.dev.devt = MKDEV(visorchipset_major, 0);
 	if (platform_device_register(&Visorchipset_platform_device) < 0) {
 		POSTCODE_LINUX_2(DEVICE_REGISTER_FAILURE_PC, DIAG_SEVERITY_ERR);
 		rc = -1;
@@ -2322,7 +2318,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);
 }
 
-- 
1.8.1.2

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ