From: Alexandre Belloni <alexandre.belloni@free-electrons.com>
To: linux-rtc@vger.kernel.org
Cc: linux-kernel@vger.kernel.org,
Alexandre Belloni <alexandre.belloni@free-electrons.com>
Subject: [PATCH 01/11] rtc: class separate device allocation from registration
Date: Thu, 6 Jul 2017 11:41:58 +0200 [thread overview]
Message-ID: <20170706094208.16240-2-alexandre.belloni@free-electrons.com> (raw)
In-Reply-To: <20170706094208.16240-1-alexandre.belloni@free-electrons.com>
Create rtc_allocate_device to allocate memory for a struct rtc_device and
initialize it.
Signed-off-by: Alexandre Belloni <alexandre.belloni@free-electrons.com>
---
drivers/rtc/class.c | 63 +++++++++++++++++++++++++++++++----------------------
1 file changed, 37 insertions(+), 26 deletions(-)
diff --git a/drivers/rtc/class.c b/drivers/rtc/class.c
index 543c64cd3df0..fb39c1334d7b 100644
--- a/drivers/rtc/class.c
+++ b/drivers/rtc/class.c
@@ -150,6 +150,41 @@ static SIMPLE_DEV_PM_OPS(rtc_class_dev_pm_ops, rtc_suspend, rtc_resume);
#define RTC_CLASS_DEV_PM_OPS NULL
#endif
+static struct rtc_device *rtc_allocate_device(void)
+{
+ struct rtc_device *rtc;
+
+ rtc = kzalloc(sizeof(*rtc), GFP_KERNEL);
+ if (!rtc)
+ return NULL;
+
+ device_initialize(&rtc->dev);
+
+ rtc->irq_freq = 1;
+ rtc->max_user_freq = 64;
+ rtc->dev.class = rtc_class;
+ rtc->dev.groups = rtc_get_dev_attribute_groups();
+ rtc->dev.release = rtc_device_release;
+
+ mutex_init(&rtc->ops_lock);
+ spin_lock_init(&rtc->irq_lock);
+ spin_lock_init(&rtc->irq_task_lock);
+ init_waitqueue_head(&rtc->irq_queue);
+
+ /* Init timerqueue */
+ timerqueue_init_head(&rtc->timerqueue);
+ INIT_WORK(&rtc->irqwork, rtc_timer_do_work);
+ /* Init aie timer */
+ rtc_timer_init(&rtc->aie_timer, rtc_aie_update_irq, (void *)rtc);
+ /* Init uie timer */
+ rtc_timer_init(&rtc->uie_rtctimer, rtc_uie_update_irq, (void *)rtc);
+ /* Init pie timer */
+ hrtimer_init(&rtc->pie_timer, CLOCK_MONOTONIC, HRTIMER_MODE_REL);
+ rtc->pie_timer.function = rtc_pie_update_irq;
+ rtc->pie_enabled = 0;
+
+ return rtc;
+}
/**
* rtc_device_register - register w/ RTC class
@@ -189,40 +224,16 @@ struct rtc_device *rtc_device_register(const char *name, struct device *dev,
}
}
- rtc = kzalloc(sizeof(struct rtc_device), GFP_KERNEL);
- if (rtc == NULL) {
+ rtc = rtc_allocate_device();
+ if (!rtc) {
err = -ENOMEM;
goto exit_ida;
}
- device_initialize(&rtc->dev);
-
rtc->id = id;
rtc->ops = ops;
rtc->owner = owner;
- rtc->irq_freq = 1;
- rtc->max_user_freq = 64;
rtc->dev.parent = dev;
- rtc->dev.class = rtc_class;
- rtc->dev.groups = rtc_get_dev_attribute_groups();
- rtc->dev.release = rtc_device_release;
-
- mutex_init(&rtc->ops_lock);
- spin_lock_init(&rtc->irq_lock);
- spin_lock_init(&rtc->irq_task_lock);
- init_waitqueue_head(&rtc->irq_queue);
-
- /* Init timerqueue */
- timerqueue_init_head(&rtc->timerqueue);
- INIT_WORK(&rtc->irqwork, rtc_timer_do_work);
- /* Init aie timer */
- rtc_timer_init(&rtc->aie_timer, rtc_aie_update_irq, (void *)rtc);
- /* Init uie timer */
- rtc_timer_init(&rtc->uie_rtctimer, rtc_uie_update_irq, (void *)rtc);
- /* Init pie timer */
- hrtimer_init(&rtc->pie_timer, CLOCK_MONOTONIC, HRTIMER_MODE_REL);
- rtc->pie_timer.function = rtc_pie_update_irq;
- rtc->pie_enabled = 0;
dev_set_name(&rtc->dev, "rtc%d", id);
--
2.11.0
next prev parent reply other threads:[~2017-07-06 9:42 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-07-06 9:41 [PATCH 00/11] RTC: rework registration Alexandre Belloni
2017-07-06 9:41 ` Alexandre Belloni [this message]
2017-07-06 9:41 ` [PATCH 02/11] rtc: class separate id allocation from registration Alexandre Belloni
2017-07-06 9:42 ` [PATCH 03/11] rtc: introduce new registration method Alexandre Belloni
2017-07-06 9:42 ` [PATCH 04/11] rtc: at91rm9200: remove race condition Alexandre Belloni
2017-07-06 9:42 ` [PATCH 05/11] rtc: add generic nvmem support Alexandre Belloni
2017-07-06 9:42 ` [PATCH 06/11] rtc: rv8803: switch to rtc_register_device Alexandre Belloni
2017-07-06 9:42 ` [PATCH 07/11] rtc: rv8803: use generic nvmem support Alexandre Belloni
2017-07-06 9:42 ` [PATCH 08/11] rtc: rv8803: remove rv8803_remove Alexandre Belloni
2017-07-06 9:42 ` [PATCH 09/11] rtc: ds1307: switch to rtc_register_device Alexandre Belloni
2017-07-06 9:42 ` [PATCH 10/11] rtc: ds1307: use generic nvmem Alexandre Belloni
2017-07-06 9:42 ` [PATCH 11/11] rtc: ds1307: remove ds1307_remove Alexandre Belloni
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=20170706094208.16240-2-alexandre.belloni@free-electrons.com \
--to=alexandre.belloni@free-electrons.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-rtc@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;
as well as URLs for NNTP newsgroup(s).