From: ebiederm@xmission.com (Eric W. Biederman)
To: "Hans J. Koch" <hjk@linutronix.de>
Cc: Greg Kroah-Hartman <gregkh@suse.de>,
linux-kernel@vger.kernel.org,
Thomas Gleixner <tglx@linutronix.de>
Subject: [PATCH 1/5] uio: Simplify the lifetime logic of struct uio_device.
Date: Mon, 20 Sep 2010 00:21:07 -0700 [thread overview]
Message-ID: <m1wrqg3mos.fsf_-_@fess.ebiederm.org> (raw)
In-Reply-To: <m139t451b4.fsf_-_@fess.ebiederm.org> (Eric W. Biederman's message of "Mon, 20 Sep 2010 00:19:59 -0700")
Embed struct device into struct uio_device, and use
the refcounting and the release method of struct device
to control struct uio_device.
This allows device_create and device_destroy to be replaced
with the more standard device_register and device_unregister,
and allows the struct device reference count to act as a
reference count on struct idev as well.
Signed-off-by: Eric W. Biederman <ebiederm@aristanetworks.com>
---
drivers/uio/uio.c | 42 ++++++++++++++++++++++++++++--------------
1 files changed, 28 insertions(+), 14 deletions(-)
diff --git a/drivers/uio/uio.c b/drivers/uio/uio.c
index 6285afb..565559c 100644
--- a/drivers/uio/uio.c
+++ b/drivers/uio/uio.c
@@ -30,7 +30,7 @@
struct uio_device {
struct module *owner;
- struct device *dev;
+ struct device device;
int minor;
atomic_t event;
struct fasync_struct *async_queue;
@@ -279,7 +279,7 @@ static int uio_dev_add_attributes(struct uio_device *idev)
if (!map_found) {
map_found = 1;
idev->map_dir = kobject_create_and_add("maps",
- &idev->dev->kobj);
+ &idev->device.kobj);
if (!idev->map_dir)
goto err_map;
}
@@ -304,7 +304,7 @@ static int uio_dev_add_attributes(struct uio_device *idev)
if (!portio_found) {
portio_found = 1;
idev->portio_dir = kobject_create_and_add("portio",
- &idev->dev->kobj);
+ &idev->device.kobj);
if (!idev->portio_dir)
goto err_portio;
}
@@ -339,7 +339,7 @@ err_map:
kobject_put(&map->kobj);
}
kobject_put(idev->map_dir);
- dev_err(idev->dev, "error creating sysfs files (%d)\n", ret);
+ dev_err(&idev->device, "error creating sysfs files (%d)\n", ret);
return ret;
}
@@ -789,6 +789,13 @@ static void release_uio_class(void)
uio_major_cleanup();
}
+static void uio_device_release(struct device *dev)
+{
+ struct uio_device *idev = dev_get_drvdata(dev);
+
+ kfree(idev);
+}
+
/**
* uio_register_device - register a new userspace IO device
* @owner: module that creates the new device
@@ -824,14 +831,19 @@ int __uio_register_device(struct module *owner,
if (ret)
goto err_get_minor;
- idev->dev = device_create(&uio_class, parent,
- MKDEV(uio_major, idev->minor), idev,
- "uio%d", idev->minor);
- if (IS_ERR(idev->dev)) {
- printk(KERN_ERR "UIO: device register failed\n");
- ret = PTR_ERR(idev->dev);
+ idev->device.devt = MKDEV(uio_major, idev->minor);
+ idev->device.class = &uio_class;
+ idev->device.parent = parent;
+ idev->device.release = uio_device_release;
+ dev_set_drvdata(&idev->device, idev);
+
+ ret = kobject_set_name(&idev->device.kobj, "uio%d", idev->minor);
+ if (ret)
+ goto err_device_create;
+
+ ret = device_register(&idev->device);
+ if (ret)
goto err_device_create;
- }
ret = uio_dev_add_attributes(idev);
if (ret)
@@ -851,7 +863,10 @@ int __uio_register_device(struct module *owner,
err_request_irq:
uio_dev_del_attributes(idev);
err_uio_dev_add_attributes:
- device_destroy(&uio_class, MKDEV(uio_major, idev->minor));
+ uio_free_minor(idev);
+ device_unregister(&idev->device);
+ return ret;
+
err_device_create:
uio_free_minor(idev);
err_get_minor:
@@ -882,8 +897,7 @@ void uio_unregister_device(struct uio_info *info)
uio_dev_del_attributes(idev);
- device_destroy(&uio_class, MKDEV(uio_major, idev->minor));
- kfree(idev);
+ device_unregister(&idev->device);
return;
}
--
1.7.2.2
next prev parent reply other threads:[~2010-09-20 7:21 UTC|newest]
Thread overview: 53+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-09-14 18:35 [PATCH 0/5] Uio enhancements Eric W. Biederman
2010-09-14 18:36 ` [PATCH 1/5] uio: Fix lack of locking in init_uio_class Eric W. Biederman
2010-09-17 20:32 ` Thomas Gleixner
2010-09-17 20:49 ` Hans J. Koch
2010-09-14 18:36 ` [PATCH 2/5] uio: Don't clear driver data Eric W. Biederman
2010-09-17 20:33 ` Thomas Gleixner
2010-09-17 20:50 ` Hans J. Koch
2010-09-14 18:37 ` [PATCH 3/5] uio: Cleanup irq handling Eric W. Biederman
2010-09-17 20:34 ` Thomas Gleixner
2010-09-17 20:51 ` Hans J. Koch
2010-09-14 18:38 ` [PATCH 4/5] uio: Support 2^MINOR_BITS minors Eric W. Biederman
2010-09-17 20:36 ` Thomas Gleixner
2010-09-17 20:57 ` Hans J. Koch
2010-09-17 21:09 ` Greg KH
2010-09-21 21:08 ` Greg KH
2010-09-21 21:38 ` Thomas Gleixner
2010-09-21 21:56 ` Greg KH
2010-09-21 22:21 ` Eric W. Biederman
2010-09-21 22:26 ` Thomas Gleixner
2010-09-14 18:38 ` [PATCH 5/5] uio: Statically allocate uio_class and use class .dev_attrs Eric W. Biederman
2010-09-17 20:37 ` Thomas Gleixner
2010-09-17 20:57 ` Hans J. Koch
2010-09-17 20:59 ` [PATCH 0/5] Uio enhancements Hans J. Koch
2010-09-20 7:19 ` [PATCH 0/5] uio hotplug support Eric W. Biederman
2010-09-20 7:21 ` Eric W. Biederman [this message]
2010-09-20 7:21 ` [PATCH 2/5] uio: Kill unused vma_count Eric W. Biederman
2010-09-20 7:23 ` [PATCH 3/5] uio: Remove unused uio_info mmap method Eric W. Biederman
2010-09-20 7:23 ` [PATCH 4/5] libunload: A library to help remove open files Eric W. Biederman
2010-09-20 7:24 ` [PATCH 5/5] uio: Implement hotunplug support, using libunload Eric W. Biederman
2010-09-24 10:55 ` Hans J. Koch
2010-09-24 17:11 ` Eric W. Biederman
2010-09-25 2:06 ` [PATCH] uio: Fix accidentally changed return value in uio_read Eric W. Biederman
2010-09-24 10:45 ` [PATCH 0/5] uio hotplug support Hans J. Koch
2010-09-24 17:14 ` Eric W. Biederman
2010-09-24 17:31 ` Hans J. Koch
2010-09-24 18:38 ` Eric W. Biederman
2010-09-25 0:05 ` Eric W. Biederman
2010-09-25 0:33 ` Greg KH
2010-09-25 1:54 ` Eric W. Biederman
2010-09-26 19:21 ` Greg KH
2010-09-26 22:46 ` [PATCH 1/5] uio: Simplify the lifetime logic of struct uio_device Eric W. Biederman
2010-09-30 22:00 ` Hans J. Koch
2010-09-26 22:47 ` [PATCH 2/5] uio: Kill unused vma_count Eric W. Biederman
2010-09-26 22:48 ` [PATCH 3/5] uio: Remove unused uio_info mmap method Eric W. Biederman
2010-10-04 9:26 ` Hans J. Koch
2010-09-26 22:48 ` [PATCH 4/5] libunload: A library to help remove open files Eric W. Biederman
2010-10-04 9:56 ` Hans J. Koch
2010-09-26 22:49 ` [PATCH 5/5] uio: Implement hotunplug support, using libunload Eric W. Biederman
2010-10-04 10:47 ` Hans J. Koch
2010-10-04 12:34 ` Hans J. Koch
2010-10-04 18:19 ` Eric W. Biederman
2010-10-04 18:52 ` Hans J. Koch
2010-09-26 22:49 ` [PATCH 6/5] uio: Fix accidentally changed return value in uio_read Eric W. Biederman
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=m1wrqg3mos.fsf_-_@fess.ebiederm.org \
--to=ebiederm@xmission.com \
--cc=gregkh@suse.de \
--cc=hjk@linutronix.de \
--cc=linux-kernel@vger.kernel.org \
--cc=tglx@linutronix.de \
/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;
as well as URLs for NNTP newsgroup(s).