mfd: menelaus: Fix possible race condition and leak
authorAlexandre Belloni <alexandre.belloni@bootlin.com>
Sun, 9 Sep 2018 20:48:58 +0000 (22:48 +0200)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Tue, 13 Nov 2018 19:08:38 +0000 (11:08 -0800)
commit128b1b38a6bf30e8444f8af76729502528e00895
tree2c13a3cf5cee63be451a2f3fb941a65de1d6a0b2
parentcd295fddbe5168a9fd0ebfbbc2e02f7e2f6c81f1
mfd: menelaus: Fix possible race condition and leak

[ Upstream commit 9612f8f503804d2fd2f63aa6ba1e58bba4612d96 ]

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: Alexandre Belloni <alexandre.belloni@bootlin.com>
Signed-off-by: Lee Jones <lee.jones@linaro.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/mfd/menelaus.c