From patchwork Mon Feb 26 08:33:57 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: 129610 Delivered-To: patch@linaro.org Received: by 10.46.66.2 with SMTP id p2csp3364952lja; Mon, 26 Feb 2018 00:34:57 -0800 (PST) X-Google-Smtp-Source: AH8x227/FNZG7KUFB+GCydiRxtUJa6e3SHYIcyd5ML3xCWqiMlXZ8nkFD0VL9NumDc8rgHPUOE6o X-Received: by 2002:a17:902:50e:: with SMTP id 14-v6mr9838427plf.360.1519634097348; Mon, 26 Feb 2018 00:34:57 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1519634097; cv=none; d=google.com; s=arc-20160816; b=YJNzIBmwGOz9CcPqSzqDNXbup8l3wgshlulg/tTU1mYqjDruDUuIz/pDLnM4ejrHT+ P8WeFG0JZhRVGKdyEuIChqUc8vKI336LVF2yPmlyRx6/JiGb0xWkqpLiFKTeDJqexFF8 PW234YvKJy+CuyVMMCyo+s/bo3TN+cAXf9RrSMz4RtBfe3YfVTz4j2mJMM2JAwHWK4Ad ZPctnHHXl8Tl6NEsRTXIuCwk1eSc/lIAV7ckPgw74F4E91ajUPg9Tn+yCCxGhIJeUG5X 5HRFbGBvkzZWpg1j36fRt9a1s2yLncLNfs6w/s/e1u3MrslrzklQLbq8pdXmDkIf9I4f 27xA== 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=IzVnQsiaJpsvgArC4tqNOrZgNLdSwmSWbuPGX6C6DK8=; b=mq0a6iAFMZKU4nLKS789BoYoZ6PCnlpJBZyZ+hroEeUQX2JivHg7UodicQdH850BlL OohuA9R7VZ+AsOqmMWoARorE5/rtH3+ipeSMkmWjd/uAt096G5EXmEejd3xq06f1pji1 UpOMYRwTol6Satx5ajj5+fjCzJcpYXIumJR1LRWhPx1d7/uKWReSLrZU4XerhwSzQf0K MVW71v5nPcEzhONXbsXJnmxkw2GyYhn3JyVbMxq0nfXgaCso6mLmgM37NQsx/s4rfRg7 BIEgX2s4dA6XN4wpsRnVDhE7GHK1GPD9F9qm+cVkj2LnLbfM7uI0h47CuM9SxMeqbaey 1Ybg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=PXU2r1K3; 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 c14si983370pgu.341.2018.02.26.00.34.57; Mon, 26 Feb 2018 00:34:57 -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=PXU2r1K3; 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 S1752662AbeBZIet (ORCPT + 28 others); Mon, 26 Feb 2018 03:34:49 -0500 Received: from mail-pf0-f193.google.com ([209.85.192.193]:39182 "EHLO mail-pf0-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752607AbeBZIeg (ORCPT ); Mon, 26 Feb 2018 03:34:36 -0500 Received: by mail-pf0-f193.google.com with SMTP id c143so6232220pfb.6 for ; Mon, 26 Feb 2018 00:34:36 -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=IzVnQsiaJpsvgArC4tqNOrZgNLdSwmSWbuPGX6C6DK8=; b=PXU2r1K3x38Rryp2XwZQ+M2RkvUE1+irtsoINeT++qsoPuLAy4EaqcvRS31Bp8exBd VWakgwhd4PXvBH5CQSS0Lp95EaDdUs9RjCoeo3hQrZ73snAY5Iq+UmGJasLZ6nt4BNE9 2CHJXokhO9aAHYY1oVrrNeltalnwKx2PVfzts= 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=IzVnQsiaJpsvgArC4tqNOrZgNLdSwmSWbuPGX6C6DK8=; b=fPjcycirddcuuW2pDkWF9DSDldY7XxmmlgT4f2UP018eBGIMOIfTQFnIYfp0AO5jL+ c0DBvKLus3A8k7ZAe5V4P3Sjbf3j2XURWmWzHyyeuWJrrSgby+sZk+WSu0zcU7AWzMgz gUgJ+G9LVT8fBTHvsx2g8PZ1D+vXJLj5W8uzmeXDN2WQxIqJqt7eCPikD1Dog4Fb+Xmy ZPfcdstHVOcKe0opYUvySKg20KVwv2B9/ESrVFMxdXYEI1al1WFKHaqaXJu7WTvAYKwy Z05EcrCUzJnL2byT8Trt59kboCeeH/wwUE8XsJgAeiUlQO497ehi32unAtIOD+pBzElI wsng== X-Gm-Message-State: APf1xPABr0YUE4QpnRnAA9YvMM51UMc3hdwDqQG3MFMH+kA+Rnpp5ZxP i8cRdW1EUDdp4AvwGGbbp1kjgg== X-Received: by 10.101.69.134 with SMTP id o6mr8014642pgq.340.1519634075650; Mon, 26 Feb 2018 00:34:35 -0800 (PST) Received: from baolinwangubtpc.spreadtrum.com ([117.18.48.82]) by smtp.gmail.com with ESMTPSA id e83sm17734791pfk.148.2018.02.26.00.34.33 (version=TLS1 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 26 Feb 2018 00:34:35 -0800 (PST) From: Baolin Wang To: a.zummo@towertech.it, alexandre.belloni@bootlin.com Cc: arnd@arndb.de, broonie@kernel.org, linux-rtc@vger.kernel.org, linux-kernel@vger.kernel.org, baolin.wang@linaro.org, alexandre.belloni@free-electrons.com Subject: [RESEND PATCH 2/3] rtc: Factor out the RTC range validation into rtc_valid_range() Date: Mon, 26 Feb 2018 16:33:57 +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 c068dae..25aebc5 100644 --- a/drivers/rtc/interface.c +++ b/drivers/rtc/interface.c @@ -23,6 +23,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; @@ -70,12 +82,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) @@ -381,12 +390,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)