From patchwork Mon Jan 16 10:08:53 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amelie Delaunay X-Patchwork-Id: 9518425 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 F163F6020B for ; Mon, 16 Jan 2017 10:11:19 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id BF18E2835B for ; Mon, 16 Jan 2017 10:11:19 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B274928438; Mon, 16 Jan 2017 10:11:19 +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=unavailable version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 4B9792835B for ; Mon, 16 Jan 2017 10:11:19 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.87 #1 (Red Hat Linux)) id 1cT4Fw-00053C-Rj; Mon, 16 Jan 2017 10:11:16 +0000 Received: from mx07-00178001.pphosted.com ([62.209.51.94]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1cT4EV-0000gf-Qu for linux-arm-kernel@lists.infradead.org; Mon, 16 Jan 2017 10:09:55 +0000 Received: from pps.filterd (m0046037.ppops.net [127.0.0.1]) by m0046037.ppops.net (8.16.0.11/8.16.0.11) with SMTP id v0GA4RUp007019; Mon, 16 Jan 2017 11:08:56 +0100 Received: from beta.dmz-eu.st.com (beta.dmz-eu.st.com [164.129.1.35]) by mx07-.pphosted.com with ESMTP id 27yamvsc8n-1 (version=TLSv1 cipher=ECDHE-RSA-AES256-SHA bits=256 verify=NOT); Mon, 16 Jan 2017 11:08:56 +0100 Received: from zeta.dmz-eu.st.com (zeta.dmz-eu.st.com [164.129.230.9]) by beta.dmz-eu.st.com (STMicroelectronics) with ESMTP id 1529234; Mon, 16 Jan 2017 10:08:55 +0000 (GMT) Received: from Webmail-eu.st.com (Safex1hubcas21.st.com [10.75.90.44]) by zeta.dmz-eu.st.com (STMicroelectronics) with ESMTP id 7698126E2; Mon, 16 Jan 2017 10:08:54 +0000 (GMT) Received: from localhost (10.201.23.160) by Webmail-ga.st.com (10.75.90.48) with Microsoft SMTP Server (TLS) id 14.3.294.0; Mon, 16 Jan 2017 11:08:54 +0100 From: Amelie Delaunay To: Alessandro Zummo , Alexandre Belloni , Rob Herring , Mark Rutland , Maxime Coquelin , Alexandre Torgue , Russell King Subject: [PATCH] rtc: stm32: fix comparison warnings Date: Mon, 16 Jan 2017 11:08:53 +0100 Message-ID: <1484561333-12087-1-git-send-email-amelie.delaunay@st.com> X-Mailer: git-send-email 1.9.1 MIME-Version: 1.0 X-Originating-IP: [10.201.23.160] X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:, , definitions=2017-01-16_08:, , signatures=0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20170116_020948_379416_C6AA4F1C X-CRM114-Status: GOOD ( 11.83 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: devicetree@vger.kernel.org, Amelie Delaunay , rtc-linux@googlegroups.com, linux-kernel@vger.kernel.org, Gabriel Fernandez , linux-arm-kernel@lists.infradead.org Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP This patches fixes comparison between signed and unsigned values as it could produce an incorrect result when the signed value is converted to unsigned: drivers/rtc/rtc-stm32.c: In function 'stm32_rtc_valid_alrm': drivers/rtc/rtc-stm32.c:404:21: warning: comparison between signed and unsigned integer expressions [-Wsign-compare] if ((((tm->tm_year > cur_year) && ... It also fixes comparison always true or false due to the fact that unsigned value is compared against zero with >= or <: drivers/rtc/rtc-stm32.c: In function 'stm32_rtc_init': drivers/rtc/rtc-stm32.c:514:35: warning: comparison of unsigned expression >= 0 is always true [-Wtype-limits] for (pred_a = pred_a_max; pred_a >= 0; pred_a-- ) { drivers/rtc/rtc-stm32.c:530:44: warning: comparison of unsigned expression < 0 is always false [-Wtype-limits] (rate - ((pred_a + 1) * (pred_s + 1)) < 0) ? Fixes: 4e64350f42e2 ("rtc: add STM32 RTC driver") Signed-off-by: Amelie Delaunay --- drivers/rtc/rtc-stm32.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/drivers/rtc/rtc-stm32.c b/drivers/rtc/rtc-stm32.c index 03c97c1..bd57eb1 100644 --- a/drivers/rtc/rtc-stm32.c +++ b/drivers/rtc/rtc-stm32.c @@ -383,7 +383,7 @@ static int stm32_rtc_alarm_irq_enable(struct device *dev, unsigned int enabled) static int stm32_rtc_valid_alrm(struct stm32_rtc *rtc, struct rtc_time *tm) { - unsigned int cur_day, cur_mon, cur_year, cur_hour, cur_min, cur_sec; + int cur_day, cur_mon, cur_year, cur_hour, cur_min, cur_sec; unsigned int dr = readl_relaxed(rtc->base + STM32_RTC_DR); unsigned int tr = readl_relaxed(rtc->base + STM32_RTC_TR); @@ -509,7 +509,7 @@ static int stm32_rtc_init(struct platform_device *pdev, pred_a_max = STM32_RTC_PRER_PRED_A >> STM32_RTC_PRER_PRED_A_SHIFT; pred_s_max = STM32_RTC_PRER_PRED_S >> STM32_RTC_PRER_PRED_S_SHIFT; - for (pred_a = pred_a_max; pred_a >= 0; pred_a--) { + for (pred_a = pred_a_max; pred_a + 1 > 0; pred_a--) { pred_s = (rate / (pred_a + 1)) - 1; if (((pred_s + 1) * (pred_a + 1)) == rate) @@ -525,7 +525,7 @@ static int stm32_rtc_init(struct platform_device *pdev, pred_s = (rate / (pred_a + 1)) - 1; dev_warn(&pdev->dev, "ck_rtc is %s\n", - (rate - ((pred_a + 1) * (pred_s + 1)) < 0) ? + (rate < ((pred_a + 1) * (pred_s + 1))) ? "fast" : "slow"); }