From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1CE29522F03; Wed, 30 Sep 2026 17:38:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1790789895; cv=none; b=MDPiktYM3qLUP0phvdqx85Gu1IrfnVU70UP8tb3xF2jRmA/Tt7BJY54PizazmFk3f5iKr48hokbUZCjk5m3A5zJF0zlsjzsZgzWM8NQ7E02U75e9hnXv36AxSVyKsImj8R9Ml6AT0555V+xEnolCyoePuk4EysXfI+1unbjlhxo= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1790789895; c=relaxed/simple; bh=NyjA9oCxd1BIummopQG32qUcP6bIammuiwpURcebsBU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=KMu/2LmyW9zPb2hPovjvoItv6d8i44g1IplSxFAJa/PFBFWgj0k8d9ei15mYfTyUjWEe98Dswhxy/ogKdQYNZqRHVSK+z+1mJT8iPmxgQNOoV9I/KUq4wnsyT85ycihCe/ynY09iBA32LiNSRYHI7ftNPasyN6zcu1y9NycbcdY= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=My7V1NVc; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="My7V1NVc" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6D7561F00898; Wed, 30 Sep 2026 17:38:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1790789894; bh=d6TXd2MEOyUQMBPG4WWlBEbtenCeObI0UF1R7cKJLEo=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=My7V1NVcaBhC9ruOxYKlq1/yd6+3RBe6zXGDPMMl5V3LgqsUJe6vgySsxYQrVsJBd jGEPam+gxKphQv9ztKRvpkHVr3xepM1yROJjDB0KpHmfvQm8AvEZFWgQnEB5csVbKP PbJcXR+qopgawYoNesxO/N9A57fFhhREqf3vBFk0= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Lad Prabhakar , Wolfram Sang , Alexandre Belloni , Sasha Levin Subject: [PATCH 6.12 636/877] rtc: rzn1: Handle unset alarm weekday in rzn1_rtc_read_alarm Date: Wed, 30 Sep 2026 17:25:47 +0200 Message-ID: <20260930152428.377927556@linuxfoundation.org> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260930152414.738996857@linuxfoundation.org> References: <20260930152414.738996857@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: patches@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.12-stable review patch. If anyone has any objections, please let me know. ------------------ From: Lad Prabhakar [ Upstream commit 457b5dbce31209e65e1184716ed3af59cb1c0372 ] RZN1_RTC_ALW is a weekday bitmask where bit N represents weekday N. When no alarm has been configured, the register has its power-on-reset value of zero. rzn1_rtc_read_alarm() uses fls() to convert the weekday bitmask into a weekday number. When RZN1_RTC_ALW is zero, fls(0) returns zero and fls(wday) - 1 evaluates to -1. This invalid weekday is then used to calculate the alarm date and can either leave tm_wday set to -1 or produce a fabricated alarm date. Treat a zero RZN1_RTC_ALW value as an unset alarm weekday and return without calculating the alarm date. Move reading RZN1_RTC_CTL1 before this check so that alrm->enabled is updated for both configured and unconfigured alarms. Fixes: b5ad1bf00d2c4 ("rtc: rzn1: Add alarm support") Cc: stable@vger.kernel.org Signed-off-by: Lad Prabhakar Reviewed-by: Wolfram Sang Tested-by: Wolfram Sang Link: https://patch.msgid.link/20260821211032.13554-5-prabhakar.mahadev-lad.rj@bp.renesas.com Signed-off-by: Alexandre Belloni [ retained the ALME-only enable check because RZN1_RTC_CTL1_1SE is absent. ] Signed-off-by: Sasha Levin Signed-off-by: Greg Kroah-Hartman --- drivers/rtc/rtc-rzn1.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) --- a/drivers/rtc/rtc-rzn1.c +++ b/drivers/rtc/rtc-rzn1.c @@ -193,13 +193,24 @@ static int rzn1_rtc_read_alarm(struct de if (ret) return ret; + ctl1 = readl(rtc->base + RZN1_RTC_CTL1); + alrm->enabled = !!(ctl1 & RZN1_RTC_CTL1_ALME); + min = readl(rtc->base + RZN1_RTC_ALM); hour = readl(rtc->base + RZN1_RTC_ALH); - wday = readl(rtc->base + RZN1_RTC_ALW); tm->tm_sec = 0; tm->tm_min = bcd2bin(min); tm->tm_hour = bcd2bin(hour); + + /* + * If wday is zero, no bit is set in RZN1_RTC_ALW. This is the + * register's power-on reset value. + */ + wday = readl(rtc->base + RZN1_RTC_ALW); + if (!wday) + return 0; + delta_days = ((fls(wday) - 1) - tm->tm_wday + 7) % 7; tm->tm_wday = fls(wday) - 1; @@ -208,9 +219,6 @@ static int rzn1_rtc_read_alarm(struct de rtc_time64_to_tm(alarm, tm); } - ctl1 = readl(rtc->base + RZN1_RTC_CTL1); - alrm->enabled = !!(ctl1 & RZN1_RTC_CTL1_ALME); - return 0; }