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

rtc: zynqmp: use dynamic max and min offset ranges

Maximum and minimum offsets in ppb that can be handled are dependent on
the rtc clock frequency and what can fit in the 16-bit register field.

Reviewed-by: Harini T <harini.t@amd.com>
Tested-by: Harini T <harini.t@amd.com>
Signed-off-by: Tomas Melin <tomas.melin@vaisala.com>
Acked-by: Michal Simek <michal.simek@amd.com>
Link: https://patch.msgid.link/20260122-zynqmp-rtc-updates-v4-5-d4edb966b499@vaisala.com
Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>

authored by

Tomas Melin and committed by
Alexandre Belloni
22543831 9f5af702

+3 -4
+3 -4
drivers/rtc/rtc-zynqmp.c
··· 44 44 #define RTC_FR_MASK 0xF0000 45 45 #define RTC_FR_MAX_TICKS 16 46 46 #define RTC_PPB 1000000000 47 - #define RTC_MIN_OFFSET -32768000 48 - #define RTC_MAX_OFFSET 32767000 49 47 50 48 struct xlnx_rtc_dev { 51 49 struct rtc_device *rtc; ··· 213 215 214 216 /* Tick to offset multiplier */ 215 217 tick_mult = DIV_ROUND_CLOSEST(RTC_PPB, freq); 216 - if (offset < RTC_MIN_OFFSET || offset > RTC_MAX_OFFSET) 217 - return -ERANGE; 218 218 219 219 /* Number ticks for given offset */ 220 220 max_tick = div_s64_rem(offset, tick_mult, &fract_offset); 221 + 222 + if (freq + max_tick > RTC_TICK_MASK || (freq + max_tick < 1)) 223 + return -ERANGE; 221 224 222 225 /* Number fractional ticks for given offset */ 223 226 if (fract_offset) {