[PATCH 03/23] use register_chrdev_ids to replace (register|alloc)_chrdev_region

From: Jim Cromie
Date: Thu May 19 2011 - 17:35:23 EST


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@xxxxxxxxx>
---
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

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