From patchwork Mon Jan 8 06:04:49 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "\(Exiting\) Baolin Wang" X-Patchwork-Id: 123684 Delivered-To: patch@linaro.org Received: by 10.140.22.227 with SMTP id 90csp2333809qgn; Sun, 7 Jan 2018 22:05:32 -0800 (PST) X-Google-Smtp-Source: ACJfBosCDL8w1wnOlBBME4E+SLjhRZtqN2m2b53vSyBGoC/lr82E0JmS4AhZ42692Mumgo2JpUX/ X-Received: by 10.98.13.212 with SMTP id 81mr9649129pfn.154.1515391532142; Sun, 07 Jan 2018 22:05:32 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1515391532; cv=none; d=google.com; s=arc-20160816; b=y2EDs/mm1qnuBYEWyxfmW72MATtTAbwgOcOvsjDNn9t59Slv7iriq/qhRwFsvmk9hS Iz2xl7tKsX73kb13KAnksfJWn71f/oJWtIXt61aDogD7hHE5eO1YSuXz3uAnRiWum79W v1EZzgumn7Psw+FfwstpRh8A8hrkjlK1zR6kfwY09Fkrsf6RHeXDyCsHFQ0F/rsZ6+O1 cl/etPJtNHxnD5YHDZS3uPFj/OgpIg3LrtPEnBV8vD9KRJmw/J4z34VI/KUK2NDj/fNU w7HzZ/ldADPv4A48XsVscEISLymkXrlqHgObCSpvVptB+EDTAjL6rnbT19NmAyCXVdWD 6Z/A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:references :in-reply-to:message-id:date:subject:cc:to:from:dkim-signature :arc-authentication-results; bh=40Q7z+wbRCumzjIRGSVgQWM8GMNbSVOltSvFSFVOaCE=; b=fP8oMdf+NBF51z0JFZYdaX4v/3BjABfycf7qw6PM61h1jGAmaimDX/btKDB1NrKNch 6gFs4FjU4QiatQ9Duia68jSmYIFmgPW/6O9wP59PM82x7xR/DjdsLE7rdPcyyGtJTxk2 puFQQ+8pb9cKX5HQYM34kDlhzZNJxs7rdif7kbHDxXQFiQ/I9b2yPMtFS6aV15Hou7vt yJofDhHwzlPOKk5li9GXbva8I/aDQrWrgP6KRQhJ5Efx918bhL0/uJhmvcm0HqECaf4S m7q+AJLgOZx2RS5uB2v43jlzI7rSnWfuj+FqAyG9npNL1Eow8vDfGEqMSXsUOoK70WM4 LYww== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Nwfl4sfA; 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 l7si7052521pgf.346.2018.01.07.22.05.31; Sun, 07 Jan 2018 22:05:32 -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=Nwfl4sfA; 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 S1755577AbeAHGF0 (ORCPT + 28 others); Mon, 8 Jan 2018 01:05:26 -0500 Received: from mail-pg0-f67.google.com ([74.125.83.67]:45437 "EHLO mail-pg0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755407AbeAHGFX (ORCPT ); Mon, 8 Jan 2018 01:05:23 -0500 Received: by mail-pg0-f67.google.com with SMTP id c194so3934326pga.12 for ; Sun, 07 Jan 2018 22:05:23 -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:in-reply-to:references :in-reply-to:references; bh=40Q7z+wbRCumzjIRGSVgQWM8GMNbSVOltSvFSFVOaCE=; b=Nwfl4sfA99FEzCpYbUreVbpGLQkfZqt17QhSfkv86MFKxqdYE0jqBWDNW16/ykqLg0 lKo8Dc8YcEqeeMjjiQii28SquOxms4Abjzt/PlXn3VUUhDgPfguJ1DV9iBGn1SgO5IhL FbXVbnGLN2YCmkCiyg3LSCtGbKvPPa0uTsVtg= 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:in-reply-to :references:in-reply-to:references; bh=40Q7z+wbRCumzjIRGSVgQWM8GMNbSVOltSvFSFVOaCE=; b=oqy3+n2yHQSjPyFSG00ubHm5H3zveY78pCFiLKTL1ZYcPPvpb+syJ0Z16Le9XesIHE Mf1ZjivnApzQMFYoUAM+d79AGcyUpSA03MmQsHzIkBn1vVJVgtrGeHQAD1KosCMGFaN3 OwDZWIl1aOdkLbjGnxMVZOdNDzcIYwBijZrPClrl6mfLBk9yp5KPosW1y/+upnDpGyTT xyfLDsWWMgoppwFukkkkyQlx3ae4n8R2qvqJ6HROpS0zOpYOo1OIgNK3rfdz6FCkNkVl 5fZG3m89P+IWnUwCd/iOExPO4fcsG5HGOUBMRa9aXfFqu1L8rio9pBrBT9Jl0T+GnE/m LRdA== X-Gm-Message-State: AKGB3mLqIJRPJB+QW5Ri0Mff2Bw5G2N/yo766NyjbOXtTqhRK1We8DUG REVhKcKko3GKVklynCH/H4DBAA== X-Received: by 10.101.88.206 with SMTP id e14mr35296pgu.441.1515391522854; Sun, 07 Jan 2018 22:05:22 -0800 (PST) Received: from baolinwangubtpc.spreadtrum.com ([117.18.48.82]) by smtp.gmail.com with ESMTPSA id q5sm20468615pgn.39.2018.01.07.22.05.20 (version=TLS1 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sun, 07 Jan 2018 22:05:22 -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 2/3] rtc: Factor out the RTC range validation into rtc_valid_range() Date: Mon, 8 Jan 2018 14:04:49 +0800 Message-Id: X-Mailer: git-send-email 1.7.9.5 In-Reply-To: References: In-Reply-To: References: Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The RTC range validation code can be factored into rtc_valid_range() function to avoid duplicate code. Signed-off-by: Baolin Wang --- drivers/rtc/interface.c | 30 ++++++++++++++++++------------ 1 file changed, 18 insertions(+), 12 deletions(-) -- 1.7.9.5 diff --git a/drivers/rtc/interface.c b/drivers/rtc/interface.c index 028dc16..55ada51 100644 --- a/drivers/rtc/interface.c +++ b/drivers/rtc/interface.c @@ -20,6 +20,18 @@ static int rtc_timer_enqueue(struct rtc_device *rtc, struct rtc_timer *timer); static void rtc_timer_remove(struct rtc_device *rtc, struct rtc_timer *timer); +static int rtc_valid_range(struct rtc_device *rtc, struct rtc_time *tm) +{ + if (rtc->range_min != rtc->range_max) { + time64_t time = rtc_tm_to_time64(tm); + + if (time < rtc->range_min || time > rtc->range_max) + return -ERANGE; + } + + return 0; +} + static int __rtc_read_time(struct rtc_device *rtc, struct rtc_time *tm) { int err; @@ -65,12 +77,9 @@ int rtc_set_time(struct rtc_device *rtc, struct rtc_time *tm) if (err != 0) return err; - if (rtc->range_min != rtc->range_max) { - time64_t time = rtc_tm_to_time64(tm); - - if (time < rtc->range_min || time > rtc->range_max) - return -ERANGE; - } + err = rtc_valid_range(rtc, tm); + if (err) + return err; err = mutex_lock_interruptible(&rtc->ops_lock); if (err) @@ -370,12 +379,9 @@ int rtc_set_alarm(struct rtc_device *rtc, struct rtc_wkalrm *alarm) if (err != 0) return err; - if (rtc->range_min != rtc->range_max) { - time64_t time = rtc_tm_to_time64(&alarm->time); - - if (time < rtc->range_min || time > rtc->range_max) - return -ERANGE; - } + err = rtc_valid_range(rtc, &alarm->time); + if (err) + return err; err = mutex_lock_interruptible(&rtc->ops_lock); if (err)