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:15:00 +0000 (11:15 -0800)
commit64b48a5cbea969bb7bd2f779dab52c2753c44e46
tree157e7eba55b4dc303060bfc9f09f6235fa83ccc8
parent06bd97b79584764d3ff4dbd42d4ca87d2cbe5a46
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