From patchwork Mon Aug 22 22:15:01 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ben Dooks X-Patchwork-Id: 9295669 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 4EA25607F0 for ; Tue, 23 Aug 2016 13:48:50 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3F2A128790 for ; Tue, 23 Aug 2016 13:48:50 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 33EFA2884D; Tue, 23 Aug 2016 13:48:50 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.2 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id B0E0228790 for ; Tue, 23 Aug 2016 13:48:49 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.85_2 #1 (Red Hat Linux)) id 1bcC4J-0003eT-PW; Tue, 23 Aug 2016 13:48:43 +0000 Received: from merlin.infradead.org ([2001:4978:20e::2]) by bombadil.infradead.org with esmtps (Exim 4.85_2 #1 (Red Hat Linux)) id 1bcC4H-0003dr-N7 for linux-amlogic@bombadil.infradead.org; Tue, 23 Aug 2016 13:48:41 +0000 Received: from [75.98.193.200] (helo=freya) by merlin.infradead.org with esmtps (Exim 4.85_2 #1 (Red Hat Linux)) id 1bcC4G-0000ON-LG for linux-amlogic@lists.infradead.org; Tue, 23 Aug 2016 13:48:40 +0000 Received: from ben by freya with local (Exim 4.87) (envelope-from ) id 1bbxUk-0005jN-JI; Mon, 22 Aug 2016 23:15:02 +0100 From: Ben Dooks To: linux-amlogic@lists.infradead.org Subject: [PATCH 5/5] rtc: warn if rtc_tm_to_time64 overflows in rtc_tm_to_time Date: Mon, 22 Aug 2016 23:15:01 +0100 Message-Id: <20160822221501.21945-6-ben-linux@fluff.org> X-Mailer: git-send-email 2.9.3 In-Reply-To: <20160822221501.21945-1-ben-linux@fluff.org> References: <20160822221501.21945-1-ben-linux@fluff.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20160823_094840_725491_276D953B X-CRM114-Status: UNSURE ( 9.93 ) X-CRM114-Notice: Please train this message. X-BeenThere: linux-amlogic@lists.infradead.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Ben Dooks MIME-Version: 1.0 Sender: "linux-amlogic" Errors-To: linux-amlogic-bounces+patchwork-linux-amlogic=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP The addition of the compatibility layer for rtc_tm_to_time() to bridge the move to rtc_tm_to_time64() does not check if the value will overflow the old call's use of unsigned long to restore the result. This means that if the result is bigger than the arch's use of unsigned long then the result will be silently truncated to whatever the maximum value of the unsigned long. Since the call does not have an option of returning an error, at least have an WARN_ON() to show if the value is out of range. Signed-off-by: Ben Dooks --- include/linux/rtc.h | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/include/linux/rtc.h b/include/linux/rtc.h index b693ada..ef7bb2c 100644 --- a/include/linux/rtc.h +++ b/include/linux/rtc.h @@ -45,7 +45,10 @@ static inline void rtc_time_to_tm(unsigned long time, struct rtc_time *tm) */ static inline int rtc_tm_to_time(struct rtc_time *tm, unsigned long *time) { - *time = rtc_tm_to_time64(tm); + time64_t tt = rtc_tm_to_time64(tm); + + WARN_ON(tt > ~(0UL)); + *time = tt; return 0; }