From: Tomi Valkeinen <tomi.valkeinen@ti.com>
To: Kevin Hilman <khilman@ti.com>
Cc: linux-omap@vger.kernel.org
Subject: Re: context_loss_count error value
Date: Wed, 25 May 2011 21:45:59 +0300 [thread overview]
Message-ID: <1306349159.2062.32.camel@deskari> (raw)
In-Reply-To: <87ipsyvdc6.fsf@ti.com>
On Wed, 2011-05-25 at 11:34 -0700, Kevin Hilman wrote:
> Tomi Valkeinen <tomi.valkeinen@ti.com> writes:
>
> [...]
>
> >>
> >> You're right, the code is just wrong here and would lead to strange
> >> return value checking in the callers to be correct.
> >>
> >> I think the best fix for this problem is to use a signed return value
> >> which can wrap as expected, and then use return negative error codes
> >> (e.g. -ENODEV).
> >>
> >> Care to send a patch? or do you have any other suggestions for a fix?
> >
> > Here's a patch.
>
> Thanks!
<snip>
> > @@ -311,22 +311,26 @@ void omap_pm_disable_off_mode(void)
> >
> > #ifdef CONFIG_ARCH_OMAP2PLUS
> >
> > -u32 omap_pm_get_dev_context_loss_count(struct device *dev)
> > +int omap_pm_get_dev_context_loss_count(struct device *dev)
> > {
> > struct platform_device *pdev = to_platform_device(dev);
> > - u32 count;
> > + int count;
> >
> > if (WARN_ON(!dev))
> > - return 0;
> > + return -ENODEV;
> >
> > if (dev->parent == &omap_device_parent) {
> > count = omap_device_get_context_loss_count(pdev);
> > } else {
> > WARN_ONCE(off_mode_enabled, "omap_pm: using dummy context loss counter; device %s should be converted to omap_device",
> > dev_name(dev));
> > - if (off_mode_enabled)
> > - dummy_context_loss_counter++;
> > +
> > count = dummy_context_loss_counter;
> > +
> > + if (off_mode_enabled) {
> > + count = (count + 1) & 0x7fffffff;
> > + dummy_context_loss_counter = count;
> > + }
>
> Again, I don't think this masking is needed. count is already an
> 'int', so when it gets bigger than INT_MAX, it will wrap.
When count is INT_MAX and one is added to it, it'll wrap to INT_MIN,
i.e. maximum negative value, which would be an error value. So by
masking out the highest bit we'll get nonnegative count range from 0 to
INT_MAX.
Perhaps a comment would be justified here =).
Tomi
next prev parent reply other threads:[~2011-05-25 18:46 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-05-18 7:40 context_loss_count error value Tomi Valkeinen
2011-05-18 10:50 ` Kevin Hilman
2011-05-18 11:33 ` Tomi Valkeinen
2011-05-18 14:24 ` Kevin Hilman
2011-05-18 14:41 ` Tomi Valkeinen
2011-05-24 15:47 ` Tomi Valkeinen
2011-05-24 23:45 ` Kevin Hilman
2011-05-25 6:05 ` Tomi Valkeinen
2011-05-25 8:31 ` Tomi Valkeinen
2011-05-25 18:34 ` Kevin Hilman
2011-05-25 18:45 ` Tomi Valkeinen [this message]
2011-05-25 20:30 ` Kevin Hilman
2011-05-26 5:55 ` Tomi Valkeinen
2011-05-26 15:56 ` Kevin Hilman
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=1306349159.2062.32.camel@deskari \
--to=tomi.valkeinen@ti.com \
--cc=khilman@ti.com \
--cc=linux-omap@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