提交 128b1b38 编写于 作者: A Alexandre Belloni 提交者: Greg Kroah-Hartman

mfd: menelaus: Fix possible race condition and leak

[ Upstream commit 9612f8f5 ]

The IRQ work is added before the struct rtc is allocated and registered,
but this struct is used in the IRQ handler. This may lead to a NULL pointer
dereference.

Switch to devm_rtc_allocate_device/rtc_register_device to allocate the rtc
before calling menelaus_add_irq_work.

Also, this solves a possible leak as the RTC is never released.
Signed-off-by: NAlexandre Belloni <alexandre.belloni@bootlin.com>
Signed-off-by: NLee Jones <lee.jones@linaro.org>
Signed-off-by: NSasha Levin <sashal@kernel.org>
Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
上级 cd295fdd
...@@ -1094,6 +1094,7 @@ static void menelaus_rtc_alarm_work(struct menelaus_chip *m) ...@@ -1094,6 +1094,7 @@ static void menelaus_rtc_alarm_work(struct menelaus_chip *m)
static inline void menelaus_rtc_init(struct menelaus_chip *m) static inline void menelaus_rtc_init(struct menelaus_chip *m)
{ {
int alarm = (m->client->irq > 0); int alarm = (m->client->irq > 0);
int err;
/* assume 32KDETEN pin is pulled high */ /* assume 32KDETEN pin is pulled high */
if (!(menelaus_read_reg(MENELAUS_OSC_CTRL) & 0x80)) { if (!(menelaus_read_reg(MENELAUS_OSC_CTRL) & 0x80)) {
...@@ -1101,6 +1102,12 @@ static inline void menelaus_rtc_init(struct menelaus_chip *m) ...@@ -1101,6 +1102,12 @@ static inline void menelaus_rtc_init(struct menelaus_chip *m)
return; return;
} }
m->rtc = devm_rtc_allocate_device(&m->client->dev);
if (IS_ERR(m->rtc))
return;
m->rtc->ops = &menelaus_rtc_ops;
/* support RTC alarm; it can issue wakeups */ /* support RTC alarm; it can issue wakeups */
if (alarm) { if (alarm) {
if (menelaus_add_irq_work(MENELAUS_RTCALM_IRQ, if (menelaus_add_irq_work(MENELAUS_RTCALM_IRQ,
...@@ -1125,10 +1132,8 @@ static inline void menelaus_rtc_init(struct menelaus_chip *m) ...@@ -1125,10 +1132,8 @@ static inline void menelaus_rtc_init(struct menelaus_chip *m)
menelaus_write_reg(MENELAUS_RTC_CTRL, m->rtc_control); menelaus_write_reg(MENELAUS_RTC_CTRL, m->rtc_control);
} }
m->rtc = rtc_device_register(DRIVER_NAME, err = rtc_register_device(m->rtc);
&m->client->dev, if (err) {
&menelaus_rtc_ops, THIS_MODULE);
if (IS_ERR(m->rtc)) {
if (alarm) { if (alarm) {
menelaus_remove_irq_work(MENELAUS_RTCALM_IRQ); menelaus_remove_irq_work(MENELAUS_RTCALM_IRQ);
device_init_wakeup(&m->client->dev, 0); device_init_wakeup(&m->client->dev, 0);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册