From patchwork Mon Dec 25 11:10:37 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "\(Exiting\) Baolin Wang" X-Patchwork-Id: 122694 Delivered-To: patch@linaro.org Received: by 10.140.22.227 with SMTP id 90csp5371159qgn; Mon, 25 Dec 2017 03:11:55 -0800 (PST) X-Google-Smtp-Source: ACJfBoues2KEquYQWOZtmU0E0cb+eFTsF5PkO8tJTb5BG7h1foYnAW61/ICcLmP7FF1K5gKiX4vW X-Received: by 10.84.141.164 with SMTP id 33mr22375365plv.375.1514200315427; Mon, 25 Dec 2017 03:11:55 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1514200315; cv=none; d=google.com; s=arc-20160816; b=Wc92oPgtFsjd+1vuKEHOV/OR7Ajzs3GsvU2xI4Gkzv00kuoX98zXFFp+Hqu1JGlalI bdc3wD62F0KIUeVCvKx0LfU9eaPgBHGMTP4NZvJ2MnWXCJBlUXgTPWx0jcBetDVjPHJj 46jvP9I8M/+Joca9CTH7bfwcgVtYG3xBBiJRm8yUsKajX6P17xToDCamZEAxHHFdvBRp qHlDm3VD3eXLrD9wgUuDU1zhBka6gNadHwEdJ0p3PxGNrOquGUx481gJDJDE8cGoQ3fu MYXUk5qyK/kNhlN2wFoIPy6RxEgjh5uj1WcMvP7groqK9GkVQmUgkAlFOOSVfxpQLmVM JffA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :dkim-signature:arc-authentication-results; bh=ivxjW2s1i0Wwh/h/DDdI1mVVFQRGU/mqEFiftwg6Vdw=; b=Si/33IkotDFND1TI21tStADQsayIDA6KJGvqoEeEe9JOhRlsNn5YLpqH4nwnmYXx3k VcY79BNjgZM5iopc2wXdUE6B53xmwtwYziD1esmlYPCj6OxrgdbKKYEQ5OTHvhuSEB0Z HYJ4M8yHsAZFVM4px5VyjqGuRMINm3xp7OMKMCwN49xArJisBOOSxnHjtGWIyewHMo9n sFQHxMzsvKUAtpdlEC8r9K6TAwJkCoB28rHMnAcGl9O4imIvZOg3feXez9nNxhSRqSin EM1AvF82rBq+rzIZeXj2j9n1azuk7XGQngiS/DN5sYgKbIVrWFbfY/51t5QknoPK8tBn XrqQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=BC1foCvB; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id k6si7701910pgp.281.2017.12.25.03.11.54; Mon, 25 Dec 2017 03:11:55 -0800 (PST) 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; dkim=pass header.i=@linaro.org header.s=google header.b=BC1foCvB; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751958AbdLYLLl (ORCPT + 28 others); Mon, 25 Dec 2017 06:11:41 -0500 Received: from mail-pg0-f66.google.com ([74.125.83.66]:45805 "EHLO mail-pg0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750811AbdLYLLi (ORCPT ); Mon, 25 Dec 2017 06:11:38 -0500 Received: by mail-pg0-f66.google.com with SMTP id m127so2487351pga.12 for ; Mon, 25 Dec 2017 03:11:38 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id; bh=ivxjW2s1i0Wwh/h/DDdI1mVVFQRGU/mqEFiftwg6Vdw=; b=BC1foCvBimatktY/1wLoLXIUDl63Txapi0CJlJygz9jU5cAFjfharJ976QZigbHGL4 oeSLCmKeoa3AVukxD+bwu4IobAlQ0+zUKdaiYkAoJKXVROrajFDQtMdguOgm56f7VRLn Ctp1+jDKXrpTj2/fYOYj/v3UPKNGEe6JVj5V8= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=ivxjW2s1i0Wwh/h/DDdI1mVVFQRGU/mqEFiftwg6Vdw=; b=NqeUNoZuk6yzGj5o2t0GPa4cMhRv/vpf2oSlDrylS35f52tvZtjaAKQztBWdSfPEDt 4VBu72kqffFL375PVG9YQzPoE0ibt2POp0/+WR5wHk4VFXmot8g+SwOZu+UHuJgfaLfO ZuxymURKwmh/Zg1cKibUL5gwdkRZhDYyEi7M4zZ3sA2kmQRmTEiI+LtZJ7MC6JVjKYPP y2ssG6RKq9P7XdrjfHLhcwZIUGhHUVmu01+rjnnbA6foCQorasAmfamf5V3HgrRD1Vjk vNtOqP8uZVV1Ld4/0anIr4Pzu0uVlxbbXBmSrsZGe4CzBv5TZkM+X653CaYySXr+Tmph K77Q== X-Gm-Message-State: AKGB3mKUiLcbmMkWVtVMMNVq/NppD6saDO42hLCyCuJ3DyLsmfAuVLxU C3Kj8fe5Jcz0UL3812fMzwnkAA== X-Received: by 10.98.214.145 with SMTP id a17mr22016766pfl.167.1514200298176; Mon, 25 Dec 2017 03:11:38 -0800 (PST) Received: from baolinwangubtpc.spreadtrum.com ([117.18.48.82]) by smtp.gmail.com with ESMTPSA id a67sm5124840pgc.60.2017.12.25.03.11.34 (version=TLS1 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 25 Dec 2017 03:11:37 -0800 (PST) From: Baolin Wang To: a.zummo@towertech.it, alexandre.belloni@free-electrons.com Cc: arnd@arndb.de, broonie@kernel.org, linux-rtc@vger.kernel.org, linux-kernel@vger.kernel.org, baolin.wang@linaro.org Subject: [PATCH] rtc: Fix overflow when converting time64_t to rtc_time Date: Mon, 25 Dec 2017 19:10:37 +0800 Message-Id: X-Mailer: git-send-email 1.7.9.5 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 --- drivers/rtc/rtc-lib.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) -- 1.7.9.5 Acked-by: Arnd Bergmann diff --git a/drivers/rtc/rtc-lib.c b/drivers/rtc/rtc-lib.c index 1ae7da5..ad5bb21 100644 --- a/drivers/rtc/rtc-lib.c +++ b/drivers/rtc/rtc-lib.c @@ -52,13 +52,11 @@ int rtc_year_days(unsigned int day, unsigned int month, unsigned int year) */ 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;