From: Miquel Raynal <miquel.raynal@bootlin.com>
To: Dan Carpenter <dan.carpenter@oracle.com>
Cc: linux-rtc@vger.kernel.org, linux-renesas-soc@vger.kernel.org
Subject: Re: [bug report] rtc: rzn1: Add oscillator offset support
Date: Thu, 19 May 2022 16:11:16 +0200 [thread overview]
Message-ID: <20220519161116.6f378382@xps-13> (raw)
In-Reply-To: <YoZMjwjcDlVCG+TR@kili>
Hi Dan,
dan.carpenter@oracle.com wrote on Thu, 19 May 2022 16:56:31 +0300:
> Hello Miquel Raynal,
>
> The patch be4a11cf98af: "rtc: rzn1: Add oscillator offset support"
> from May 16, 2022, leads to the following Smatch static checker
> warning:
>
> drivers/rtc/rtc-rzn1.c:302 rzn1_rtc_set_offset()
> warn: 'steps' 'true' implies 'steps > 0' is 'true'
>
> drivers/rtc/rtc-rzn1.c
> 270 static int rzn1_rtc_set_offset(struct device *dev, long offset)
> 271 {
> 272 struct rzn1_rtc *rtc = dev_get_drvdata(dev);
> 273 unsigned int steps;
> ^^^^^^^^^^^^^^^^^^
> steps is unsigned
>
> 274 int stepsh, stepsl;
> 275 u32 val = 0;
> 276 int ret;
> 277
> 278 /*
> 279 * Check which resolution mode (every 20 or 60s) can be used.
> 280 * Between 2 and 124 clock pulses can be added or substracted.
> 281 *
> 282 * In 20s mode, the minimum resolution is 2 / (32768 * 20) which is
> 283 * close to 3051 ppb. In 60s mode, the resolution is closer to 1017.
> 284 */
> 285 stepsh = DIV_ROUND_CLOSEST(offset, 1017);
> 286 stepsl = DIV_ROUND_CLOSEST(offset, 3051);
> 287
> 288 if (stepsh >= -0x3E && stepsh <= 0x3E) {
> 289 /* 1017 ppb per step */
> 290 steps = stepsh;
> 291 val |= RZN1_RTC_SUBU_DEV;
> 292 } else if (stepsl >= -0x3E && stepsl <= 0x3E) {
> 293 /* 3051 ppb per step */
> 294 steps = stepsl;
> 295 } else {
> 296 return -ERANGE;
> 297 }
> 298
> 299 if (!steps)
>
> if steps is zero return
>
> 300 return 0;
> 301
> --> 302 if (steps > 0) {
>
> This is true. No need to check.
'steps' should not be unsigned in order to properly carry the offset.
Do you plan to send a patch?
>
> 303 val |= steps + 1;
> 304 } else {
> 305 val |= RZN1_RTC_SUBU_DECR;
> 306 val |= (~(-steps - 1)) & 0x3F;
> 307 }
> 308
> 309 ret = readl_poll_timeout(rtc->base + RZN1_RTC_CTL2, val,
> 310 !(val & RZN1_RTC_CTL2_WUST), 100, 2000000);
> 311 if (ret)
> 312 return ret;
> 313
> 314 writel(val, rtc->base + RZN1_RTC_SUBU);
> 315
> 316 return 0;
> 317 }
>
> regards,
> dan carpenter
Thanks,
Miquèl
prev parent reply other threads:[~2022-05-19 14:11 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-05-19 13:56 [bug report] rtc: rzn1: Add oscillator offset support Dan Carpenter
2022-05-19 14:11 ` Miquel Raynal [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20220519161116.6f378382@xps-13 \
--to=miquel.raynal@bootlin.com \
--cc=dan.carpenter@oracle.com \
--cc=linux-renesas-soc@vger.kernel.org \
--cc=linux-rtc@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).