Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

rtc: pl031: fix rtc features null pointer dereference

When there is no interrupt line, rtc alarm feature is disabled.

The clearing of the alarm feature bit was being done prior to allocations
of ldata->rtc device, resulting in a null pointer dereference.

Clear RTC_FEATURE_ALARM after the rtc device is allocated.

Fixes: d9b0dd54a194 ("rtc: pl031: use RTC_FEATURE_ALARM")
Cc: stable@vger.kernel.org
Signed-off-by: Ali Pouladi <quic_apouladi@quicinc.com>
Signed-off-by: Elliot Berman <quic_eberman@quicinc.com>
Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
Link: https://lore.kernel.org/r/20220225161924.274141-1-quic_eberman@quicinc.com

authored by

Ali Pouladi and committed by
Alexandre Belloni
ea6af39f 811f5559

+3 -3
+3 -3
drivers/rtc/rtc-pl031.c
··· 350 350 } 351 351 } 352 352 353 - if (!adev->irq[0]) 354 - clear_bit(RTC_FEATURE_ALARM, ldata->rtc->features); 355 - 356 353 device_init_wakeup(&adev->dev, true); 357 354 ldata->rtc = devm_rtc_allocate_device(&adev->dev); 358 355 if (IS_ERR(ldata->rtc)) { 359 356 ret = PTR_ERR(ldata->rtc); 360 357 goto out; 361 358 } 359 + 360 + if (!adev->irq[0]) 361 + clear_bit(RTC_FEATURE_ALARM, ldata->rtc->features); 362 362 363 363 ldata->rtc->ops = ops; 364 364 ldata->rtc->range_min = vendor->range_min;