From: linux@arm.linux.org.uk (Russell King - ARM Linux)
To: linux-arm-kernel@lists.infradead.org
Subject: [PATCH 18/20] ARM: sa1111: cleanup sub-device registration and unregistration
Date: Fri, 03 Feb 2012 20:00:37 +0000 [thread overview]
Message-ID: <E1RtPJF-00044q-Py@rmk-PC.arm.linux.org.uk> (raw)
In-Reply-To: <20120203195419.GH14129@n2100.arm.linux.org.uk>
Move the releasing of resources out of the release function - this
allows a cleaner and more conventional arrangement of the registration
failure paths and a saner unregistration process for these devices.
Signed-off-by: Russell King <rmk+kernel@arm.linux.org.uk>
---
arch/arm/common/sa1111.c | 27 ++++++++++++++++-----------
1 files changed, 16 insertions(+), 11 deletions(-)
diff --git a/arch/arm/common/sa1111.c b/arch/arm/common/sa1111.c
index d78499f..8d86338 100644
--- a/arch/arm/common/sa1111.c
+++ b/arch/arm/common/sa1111.c
@@ -610,7 +610,6 @@ static void sa1111_dev_release(struct device *_dev)
{
struct sa1111_dev *dev = SA1111_DEV(_dev);
- release_resource(&dev->res);
kfree(dev);
}
@@ -625,9 +624,10 @@ sa1111_init_one_child(struct sa1111 *sachip, struct resource *parent,
dev = kzalloc(sizeof(struct sa1111_dev), GFP_KERNEL);
if (!dev) {
ret = -ENOMEM;
- goto out;
+ goto err_alloc;
}
+ device_initialize(&dev->dev);
dev_set_name(&dev->dev, "%4.4lx", info->offset);
dev->devid = info->devid;
dev->dev.parent = sachip->dev;
@@ -657,17 +657,19 @@ sa1111_init_one_child(struct sa1111 *sachip, struct resource *parent,
if (ret) {
printk("SA1111: failed to allocate resource for %s\n",
dev->res.name);
- dev_set_name(&dev->dev, NULL);
- kfree(dev);
- goto out;
+ goto err_resource;
}
- ret = device_register(&dev->dev);
- if (ret) {
- release_resource(&dev->res);
- kfree(dev);
- }
+ ret = device_add(&dev->dev);
+ if (ret)
+ goto err_add;
+ return 0;
+ err_add:
+ release_resource(&dev->res);
+ err_resource:
+ put_device(&dev->dev);
+ err_alloc:
return ret;
}
@@ -813,7 +815,10 @@ __sa1111_probe(struct device *me, struct resource *mem, int irq)
static int sa1111_remove_one(struct device *dev, void *data)
{
- device_unregister(dev);
+ struct sa1111_dev *sadev = SA1111_DEV(dev);
+ device_del(&sadev->dev);
+ release_resource(&sadev->res);
+ put_device(&sadev->dev);
return 0;
}
--
1.7.4.4
next prev parent reply other threads:[~2012-02-03 20:00 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-02-03 19:54 [PATCH 00/20] SA1111 cleanups Russell King - ARM Linux
2012-02-03 19:54 ` [PATCH 01/20] ARM: sa1111: fix memory request/grant setup on PM events Russell King - ARM Linux
2012-02-03 19:55 ` [PATCH 02/20] ARM: sa1111: fix PWM state on suspend Russell King - ARM Linux
2012-02-03 19:55 ` [PATCH 03/20] ARM: sa1111: add sa1111 core driver .owner initializer Russell King - ARM Linux
2012-02-03 19:55 ` [PATCH 04/20] ARM: sa1111: add .owner initializer to sa1111 driver structures Russell King - ARM Linux
2012-02-03 19:56 ` [PATCH 05/20] ARM: sa1111: finish "allow cascaded IRQs to be used by platforms" Russell King - ARM Linux
2012-02-03 19:56 ` [PATCH 06/20] ARM: sa1111: implement support for sparse IRQs Russell King - ARM Linux
2012-02-03 19:56 ` [PATCH 07/20] ARM: sa1111: add shutdown hook to sa1111_driver structure Russell King - ARM Linux
2012-02-03 19:57 ` [PATCH 08/20] ARM: sa1111: add platform enable/disable functions Russell King - ARM Linux
2012-02-03 19:57 ` [PATCH 09/20] ARM: sa11x0: badge4: move board specific ohci initialization to badge4.c Russell King - ARM Linux
2012-02-03 19:57 ` [PATCH 10/20] ARM: sa1111: change devid to be a bitmask Russell King - ARM Linux
2012-02-03 19:58 ` [PATCH 11/20] ARM: sa1111: provide a generic way to prevent devices from registering Russell King - ARM Linux
2012-02-03 19:58 ` [PATCH 12/20] ARM: sa1111: delete unused physical GPIO register definitions Russell King - ARM Linux
2012-02-03 19:58 ` [PATCH 13/20] ARM: sa1111: move PS/2 interface register definitions to sa1111p2.c Russell King - ARM Linux
2012-02-03 19:59 ` [PATCH 14/20] ARM: sa1111: move PCMCIA interface register definitions to sa1111_generic.c Russell King - ARM Linux
2012-02-03 19:59 ` [PATCH 15/20] ARM: sa1111: move USB interface register definitions to ohci-sa1111.c Russell King - ARM Linux
2012-02-03 19:59 ` [PATCH 16/20] ARM: sa1111: register sa1111 devices with dmabounce in bus notifier Russell King - ARM Linux
2012-02-03 20:00 ` [PATCH 17/20] ARM: sa1111: only setup DMA for DMA capable devices Russell King - ARM Linux
2012-02-03 20:00 ` Russell King - ARM Linux [this message]
2012-02-03 20:00 ` [PATCH 19/20] ARM: sa1111: use dev_err() rather than printk() Russell King - ARM Linux
2012-02-03 20:01 ` [PATCH 20/20] ARM: sa11x0: don't static map sa1111 Russell King - ARM Linux
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=E1RtPJF-00044q-Py@rmk-PC.arm.linux.org.uk \
--to=linux@arm.linux.org.uk \
--cc=linux-arm-kernel@lists.infradead.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;
as well as URLs for NNTP newsgroup(s).