public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Jim Cromie <jim.cromie@gmail.com>
To: Linux kernel <linux-kernel@vger.kernel.org>
Cc: Andrew Morton <akpm@osdl.org>
Subject: [ patch -mm1 02/02 ] scx200_gpio: use 1 cdev for N minors, not N for N
Date: Tue, 11 Jul 2006 09:27:50 -0600	[thread overview]
Message-ID: <44B3C376.4060307@gmail.com> (raw)


this patch removes the scx200_gpio's  cdev-array & ksalloc,
replacing it with a single static struct cdev, which is sufficient
for all the pins.

cdev_put is commented out since kernel wont link properly with it,
and its apparently not needed.

With these patches, this driver continues to work with Chris Boot's
leds_48xx driver, which is also new in -mm1.

Signed-off-by  Jim Cromie <jim.cromie@gmail.com>

---

$ diffstat diff.scx-1-cdev
 scx200_gpio.c |   28 ++++++++--------------------
 1 files changed, 8 insertions(+), 20 deletions(-)



diff -ruNp -X dontdiff -X exclude-diffs x-1/drivers/char/scx200_gpio.c x-2/drivers/char/scx200_gpio.c
--- x-1/drivers/char/scx200_gpio.c	2006-07-10 20:19:17.000000000 -0600
+++ x-2/drivers/char/scx200_gpio.c	2006-07-10 20:45:05.000000000 -0600
@@ -63,7 +63,6 @@ static int scx200_gpio_release(struct in
 	return 0;
 }
 
-
 static const struct file_operations scx200_gpio_fops = {
 	.owner   = THIS_MODULE,
 	.write   = nsc_gpio_write,
@@ -72,11 +71,11 @@ static const struct file_operations scx2
 	.release = scx200_gpio_release,
 };
 
-struct cdev *scx200_devices;
+struct cdev scx200_gpio_cdev;  /* use 1 cdev for all pins */
 
 static int __init scx200_gpio_init(void)
 {
-	int rc, i;
+	int rc;
 	dev_t devid;
 
 	if (!scx200_gpio_present()) {
@@ -107,25 +106,12 @@ static int __init scx200_gpio_init(void)
 		dev_err(&pdev->dev, "SCx200 chrdev_region err: %d\n", rc);
 		goto undo_platform_device_add;
 	}
-	scx200_devices = kzalloc(MAX_PINS * sizeof(struct cdev), GFP_KERNEL);
-	if (!scx200_devices) {
-		rc = -ENOMEM;
-		goto undo_chrdev_region;
-	}
-	for (i = 0; i < MAX_PINS; i++) {
-		struct cdev *cdev = &scx200_devices[i];
-		cdev_init(cdev, &scx200_gpio_fops);
-		cdev->owner = THIS_MODULE;
-		rc = cdev_add(cdev, MKDEV(major, i), 1);
-		/* tolerate 'minor' errors */
-		if (rc)
-			dev_err(&pdev->dev, "Error %d on minor %d", rc, i);
-	}
+
+	cdev_init(&scx200_gpio_cdev, &scx200_gpio_fops);
+	cdev_add(&scx200_gpio_cdev, devid, MAX_PINS);
 
 	return 0; /* succeed */
 
-undo_chrdev_region:
-	unregister_chrdev_region(devid, MAX_PINS);
 undo_platform_device_add:
 	platform_device_del(pdev);
 undo_malloc:
@@ -136,7 +122,9 @@ undo_malloc:
 
 static void __exit scx200_gpio_cleanup(void)
 {
-	kfree(scx200_devices);
+	cdev_del(&scx200_gpio_cdev);
+	/* cdev_put(&scx200_gpio_cdev); */
+
 	unregister_chrdev_region(MKDEV(major, 0), MAX_PINS);
 	platform_device_unregister(pdev);
 }



                 reply	other threads:[~2006-07-11 15:27 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=44B3C376.4060307@gmail.com \
    --to=jim.cromie@gmail.com \
    --cc=akpm@osdl.org \
    --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