mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Jim Cromie <jim.cromie@gmail.com>
To: linux-kernel@vger.kernel.org
Cc: gregkh@suse.de, Jim Cromie <jim.cromie@gmail.com>
Subject: [PATCH 03/23] use register_chrdev_ids to replace (register|alloc)_chrdev_region
Date: Thu, 19 May 2011 15:33:06 -0600	[thread overview]
Message-ID: <1305840792-25877-4-git-send-email-jim.cromie@gmail.com> (raw)
In-Reply-To: <1305840792-25877-1-git-send-email-jim.cromie@gmail.com>

replace __deprecated (register|alloc)_chrdev_region api calls with
register_chrdev_ids.

This patch brought to you by coccinelle-spatch with the following
cocci-file.  It transforms ~40 callsites, which are broken out on
MAINTAINER boundaries, but misses those with MKDEV(X,Y) in the
param-list.

@ combo @	// if-major-alloc-else-register
dev_t devid;
identifier rc;
expression major, minor;
expression CT, DEVNAME;
@@

-	if (major) {
-		devid = MKDEV(major, 0);
-		rc = register_chrdev_region(devid, CT, DEVNAME);
-	} else {
-		rc = alloc_chrdev_region(&devid, minor, CT, DEVNAME);
-		major = MAJOR(devid);
-	}

+	devid = MKDEV(major, minor);
+	rc = register_chrdev_ids(&devid, CT, DEVNAME);

// general rules, implicitly depend on !combo

@ register_chrdev_region @
dev_t devid;			// typed simple var, not MKDEV(x,y)
expression ct, name;
@@

- register_chrdev_region(devid, ct, name)
+ register_chrdev_ids(&devid, ct, name)

@ alloc_chrdev_region @
dev_t devid;			// typed simple var, not MKDEV(x,y)
expression minor, ct, name;
@@

- alloc_chrdev_region(&devid, minor, ct, name)
+ register_chrdev_ids(&devid, ct, name)

Signed-off-by: Jim Cromie <jim.cromie@gmail.com>
---
 drivers/char/pc8736x_gpio.c |   20 ++++++--------------
 drivers/char/scx200_gpio.c  |   12 ++++--------
 2 files changed, 10 insertions(+), 22 deletions(-)

diff --git a/drivers/char/pc8736x_gpio.c b/drivers/char/pc8736x_gpio.c
index b304ec0..cf01c99 100644
--- a/drivers/char/pc8736x_gpio.c
+++ b/drivers/char/pc8736x_gpio.c
@@ -254,7 +254,7 @@ static struct cdev pc8736x_gpio_cdev;
 static int __init pc8736x_gpio_init(void)
 {
 	int rc;
-	dev_t devid;
+	dev_t devid = MKDEV(major, 0);
 
 	pdev = platform_device_alloc(DEVNAME, 0);
 	if (!pdev)
@@ -300,24 +300,16 @@ static int __init pc8736x_gpio_init(void)
 			pc8736x_gpio_base);
 		goto undo_platform_dev_add;
 	}
-	dev_info(&pdev->dev, "GPIO ioport %x reserved\n", pc8736x_gpio_base);
-
-	if (major) {
-		devid = MKDEV(major, 0);
-		rc = register_chrdev_region(devid, PC8736X_GPIO_CT, DEVNAME);
-	} else {
-		rc = alloc_chrdev_region(&devid, 0, PC8736X_GPIO_CT, DEVNAME);
-		major = MAJOR(devid);
-	}
 
+	rc = register_chrdev_ids(&devid, PC8736X_GPIO_CT, DEVNAME);
 	if (rc < 0) {
 		dev_err(&pdev->dev, "register-chrdev failed: %d\n", rc);
 		goto undo_request_region;
 	}
-	if (!major) {
-		major = rc;
-		dev_dbg(&pdev->dev, "got dynamic major %d\n", major);
-	}
+	major = MAJOR(devid);
+
+	dev_info(&pdev->dev, "GPIO ioport=%x, device-major=%d\n",
+		 pc8736x_gpio_base, major);
 
 	pc8736x_init_shadow();
 
diff --git a/drivers/char/scx200_gpio.c b/drivers/char/scx200_gpio.c
index 0bc135b..9b53a01 100644
--- a/drivers/char/scx200_gpio.c
+++ b/drivers/char/scx200_gpio.c
@@ -75,7 +75,7 @@ static struct cdev scx200_gpio_cdev;  /* use 1 cdev for all pins */
 static int __init scx200_gpio_init(void)
 {
 	int rc;
-	dev_t devid;
+	dev_t devid = MKDEV(major, 0);
 
 	if (!scx200_gpio_present()) {
 		printk(KERN_ERR DRVNAME ": no SCx200 gpio present\n");
@@ -94,17 +94,13 @@ static int __init scx200_gpio_init(void)
 	/* nsc_gpio uses dev_dbg(), so needs this */
 	scx200_gpio_ops.dev = &pdev->dev;
 
-	if (major) {
-		devid = MKDEV(major, 0);
-		rc = register_chrdev_region(devid, MAX_PINS, "scx200_gpio");
-	} else {
-		rc = alloc_chrdev_region(&devid, 0, MAX_PINS, "scx200_gpio");
-		major = MAJOR(devid);
-	}
+	rc = register_chrdev_ids(&devid, MAX_PINS, "scx200_gpio");
 	if (rc < 0) {
 		dev_err(&pdev->dev, "SCx200 chrdev_region err: %d\n", rc);
 		goto undo_platform_device_add;
 	}
+	major = MAJOR(devid);
+	dev_info(&pdev->dev, "GPIO device-major=%d\n", major);
 
 	cdev_init(&scx200_gpio_cdev, &scx200_gpio_fileops);
 	cdev_add(&scx200_gpio_cdev, devid, MAX_PINS);
-- 
1.7.4.4


  parent reply	other threads:[~2011-05-19 21:34 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-05-19 21:33 [PATCH 00/23] add register_chrdev_ids() to char_dev.c, API Jim Cromie
2011-05-19 21:33 ` [PATCH 02/23] reimplement alloc_chrdev_region with register_chrdev_ids Jim Cromie
2011-05-19 21:33 ` Jim Cromie [this message]
2011-05-19 21:33 ` [PATCH 04/23] use register_chrdev_ids in drivers/tty/ Jim Cromie
2011-05-19 21:33 ` [PATCH 05/23] use register_chrdev_ids in drivers/infiniband/ Jim Cromie
2011-05-19 21:33 ` [PATCH 06/23] use register_chrdev_ids in drivers/media/ Jim Cromie
2011-05-21 12:48   ` Mauro Carvalho Chehab
2011-05-19 21:33 ` [PATCH 07/23] use register_chrdev_ids in drivers/s390/ Jim Cromie
2011-05-19 21:33 ` [PATCH 08/23] use register_chrdev_ids in drivers/scsi/ Jim Cromie
2011-05-20 15:42   ` Boaz Harrosh
2011-05-21  4:21     ` Jim Cromie
2011-05-21  7:59       ` Boaz Harrosh
2011-05-19 21:33 ` [PATCH 09/23] use register_chrdev_ids in drivers/staging/ Jim Cromie
2011-05-19 22:44 ` [PATCH 00/23] add register_chrdev_ids() to char_dev.c, API Greg KH
2011-05-21  5:15   ` Jim Cromie
2011-05-21 21:14     ` Greg KH
2011-05-22 14:55       ` Greg KH

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1305840792-25877-4-git-send-email-jim.cromie@gmail.com \
    --to=jim.cromie@gmail.com \
    --cc=gregkh@suse.de \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

Powered by JetHome