From patchwork Fri Mar 22 16:17:20 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnd Bergmann X-Patchwork-Id: 160944 Delivered-To: patch@linaro.org Received: by 2002:a02:c6d8:0:0:0:0:0 with SMTP id r24csp993949jan; Fri, 22 Mar 2019 09:18:19 -0700 (PDT) X-Google-Smtp-Source: APXvYqwm/p2BOR1l9GI9k0WnUtcGwtBlFFWZCkasCRd7dzDQY5HEKqju7VFj1xbJ1Zhn8fcxE6dE X-Received: by 2002:a62:55c7:: with SMTP id j190mr9778521pfb.226.1553271499168; Fri, 22 Mar 2019 09:18:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1553271499; cv=none; d=google.com; s=arc-20160816; b=Yd3SyOBrYVSOk2TqfQ6SGg6GiGtwy9YmJvo35DwZOo832fbqQp43TSH8myDZhPDVYI 4wAjKzDStGTXHtmDAbSBWvqngvTpwx610fUBnTT9zLWCFJQo1yBPH0RI0p4X446uPBBV J2GGwLA32WWahp9acGalajrZUQrYgIxcUH9lduGGXZtPNN8SjiDTIaFIko0V5+IFZzK7 fBqsHWQhLe55XOKGrqh97xOd3T8ZUxJ04YYVY8lNzS3gBc1faxgd1hV9KNrct3dFg8GF tM6j70yz/b3cZcYEdMn/odDkWw+iZV7JyMLlw9nlWwcDje1ANnYYgkww6dlEYJfbR3TL tB2A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=DEmRVnD3YOzp5zWba5JmRm1MgJevUJpAo+nvDahANC0=; b=pgid21V8QxHbpXWRQ138qyt4KBddCEDYH9PvE9y56afqrWCQg9TMJjKBQekldAZPgB RC1lwJ2ufDifQIRLFyVb1cdc9oz28Wyvp/guijkxdOItRVrshhbUQzNqSxqfyrxsQkFf IhxhlxlrBiyRWEWBaaOolg1VP/7tQ0xQ5MhHVy64h7501xzYQW1BfTvl3jz07iI/4kcY 4WGUhi8x2GH7wdR8VbI2yPxPc1D6/zk5BwqELnZC9NxCwwjeiWyms1Dt/qSpglWbcKpr LBC2e3sWGeZSwdKEVvPC75qnJYybWOGZJVGRuG9aXNbt0Cadar3MiZLbIKqHApt+e5Sf rEuQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id h21si6992593pgl.346.2019.03.22.09.18.18; Fri, 22 Mar 2019 09:18:19 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729576AbfCVQSR (ORCPT + 31 others); Fri, 22 Mar 2019 12:18:17 -0400 Received: from mout.kundenserver.de ([212.227.17.10]:52975 "EHLO mout.kundenserver.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728506AbfCVQSM (ORCPT ); Fri, 22 Mar 2019 12:18:12 -0400 Received: from wuerfel.lan ([149.172.19.189]) by mrelayeu.kundenserver.de (mreue108 [212.227.15.145]) with ESMTPA (Nemesis) id 1MV6Bs-1hXK040iVq-00SBOO; Fri, 22 Mar 2019 17:18:02 +0100 From: Arnd Bergmann To: stable@vger.kernel.org, Alessandro Zummo , Alexandre Belloni Cc: Baolin Wang , Arnd Bergmann , Alexandre Belloni , linux-rtc@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [BACKPORT 4.14.y 5/8] rtc: Fix overflow when converting time64_t to rtc_time Date: Fri, 22 Mar 2019 17:17:20 +0100 Message-Id: <20190322161727.1153278-6-arnd@arndb.de> X-Mailer: git-send-email 2.20.0 In-Reply-To: <20190322161727.1153278-1-arnd@arndb.de> References: <20190322161727.1153278-1-arnd@arndb.de> MIME-Version: 1.0 X-Provags-ID: V03:K1:r0URZeN4gl7747nPXhOIAmjtBlm93At/wCEX35OJL/3fdk1//D1 feA/Fk2kPW6TKH/ldm6agj9lgaUknzZrsXCYPUuJiw4KxzSxdu+2KaKXiktyqmlcukX10Pq +QBEDSo+WLP9BxfDB0b3BldcwiI+rHtMakaIkvtb3NkDEwjC4RfqCQZcAaEy27j+RVfz7o/ pv0OauMAob0C7nkOJlrBQ== X-Spam-Flag: NO X-UI-Out-Filterresults: notjunk:1; V03:K0:F4pSOYgaiOY=:PNleV7UoPK6PrajcUklQi3 Tn4AHogzTixryXzYMkLtR5rpIHwhOPG05W22vny5Stg/9DQbKVlEgWQ/IpCE9ugBanXqk69Lm Wu9/vlbODPiIzxjv5Eer+aLoqDFJTXQpTgbd3dQK3N8VExArKncAGsrKTGiNR5zxyPpf0wjqB 0UHVaAmSvBUfb+sNxn1R8QRx3dl7Q3UVPTRmt+btDU+N5O4iIwJrAti//wZ/PjRiu3NpDKKqs NpfPFxJ7YH3TG2aHJY+/MImdk0cOeVLDbEftrWd9Z9t15FPNIGqq2tQzF9c1+j4d2Q4pP/zRw cGLnFxZtEEp1MUcw4RH+gmfnEgM9Vn0d9ZPWEv/9IzbXjo3qOQmn4znm04cSOklCNVJ+Y1hCr vI8poW694uAEHAPv3jqLlMJ1u4TfwzfskKz5b8rctNwXhOh3+QlbrvKCFq7cLbH6YHMs8qAYP dJq/jVWTzu9I8JjSw3w1Dkhv8ksdFGPs6Oqk7AfI+qfGRN3yM9gX6QRJupGMEV9KVc0FgSwiA uZGIoZUTYnFtQjzKovR4Z8hU6pHEApNrz6AHOVXo5jzti4ffCvodN2OoPkex6Rr3hc9OAgsQk q+F+sVFUqeqdDBDHC5/QdOueHY5eL/00fbqUfFrwkQRrudMVWodeSnUXKEDD0VkbV+lMNtVGZ dF9l33uCCPv26R4lwHgdgtGp3BDoctkOKjw0AU8a4EENsBpwQXDam6s5TCYyeJT3zvzcMmzdR mcoxmo/LRDhjGtPjOuVmzAdp3SlyTJIFZVvD3Q== Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Baolin Wang If we convert one large time values to rtc_time, in the original formula 'days * 86400' can be overflowed in 'unsigned int' type to make the formula get one incorrect remain seconds value. Thus we can use div_s64_rem() function to avoid this situation. Signed-off-by: Baolin Wang Acked-by: Arnd Bergmann Signed-off-by: Alexandre Belloni (cherry picked from commit 36d46cdb43efea74043e29e2a62b13e9aca31452) Signed-off-by: Arnd Bergmann --- drivers/rtc/rtc-lib.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) -- 2.20.0 diff --git a/drivers/rtc/rtc-lib.c b/drivers/rtc/rtc-lib.c index 1ae7da5cfc60..ad5bb21908e5 100644 --- a/drivers/rtc/rtc-lib.c +++ b/drivers/rtc/rtc-lib.c @@ -52,13 +52,11 @@ EXPORT_SYMBOL(rtc_year_days); */ void rtc_time64_to_tm(time64_t time, struct rtc_time *tm) { - unsigned int month, year; - unsigned long secs; + unsigned int month, year, secs; int days; /* time must be positive */ - days = div_s64(time, 86400); - secs = time - (unsigned int) days * 86400; + days = div_s64_rem(time, 86400, &secs); /* day of the week, 1970-01-01 was a Thursday */ tm->tm_wday = (days + 4) % 7;