Commit 142513a2 authored by Alexandre Belloni's avatar Alexandre Belloni Committed by Greg Kroah-Hartman

rtc: ds1374: fix possible race condition

[ Upstream commit c11af813 ]

The RTC IRQ is requested before the struct rtc_device is allocated,
this may lead to a NULL pointer dereference in the IRQ handler.

To fix this issue, allocating the rtc_device struct before requesting
the RTC IRQ using devm_rtc_allocate_device, and use rtc_register_device
to register the RTC device.

Link: https://lore.kernel.org/r/20200306073404.56921-1-alexandre.belloni@bootlin.comSigned-off-by: default avatarAlexandre Belloni <alexandre.belloni@bootlin.com>
Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
parent e934a66d
...@@ -620,6 +620,10 @@ static int ds1374_probe(struct i2c_client *client, ...@@ -620,6 +620,10 @@ static int ds1374_probe(struct i2c_client *client,
if (!ds1374) if (!ds1374)
return -ENOMEM; return -ENOMEM;
ds1374->rtc = devm_rtc_allocate_device(&client->dev);
if (IS_ERR(ds1374->rtc))
return PTR_ERR(ds1374->rtc);
ds1374->client = client; ds1374->client = client;
i2c_set_clientdata(client, ds1374); i2c_set_clientdata(client, ds1374);
...@@ -641,12 +645,11 @@ static int ds1374_probe(struct i2c_client *client, ...@@ -641,12 +645,11 @@ static int ds1374_probe(struct i2c_client *client,
device_set_wakeup_capable(&client->dev, 1); device_set_wakeup_capable(&client->dev, 1);
} }
ds1374->rtc = devm_rtc_device_register(&client->dev, client->name, ds1374->rtc->ops = &ds1374_rtc_ops;
&ds1374_rtc_ops, THIS_MODULE);
if (IS_ERR(ds1374->rtc)) { ret = rtc_register_device(ds1374->rtc);
dev_err(&client->dev, "unable to register the class device\n"); if (ret)
return PTR_ERR(ds1374->rtc); return ret;
}
#ifdef CONFIG_RTC_DRV_DS1374_WDT #ifdef CONFIG_RTC_DRV_DS1374_WDT
save_client = client; save_client = client;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment