All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] kernel/power/hibernate.c: be sure of 'start' is not bigger than 'stop'
@ 2014-04-21 13:40 Chen Gang
  2014-04-21 20:09 ` Pavel Machek
  0 siblings, 1 reply; 4+ messages in thread
From: Chen Gang @ 2014-04-21 13:40 UTC (permalink / raw)
  To: Guan Xuetao, Rafael J. Wysocki, len.brown, pavel; +Cc: linux-pm, linux-kernel

For do_div(), it need 'u64' type, which means the outside must be sure
of 'start' is not bigger than 'stop', or it will report warning.

The related warning (with allmodconfig for unicore32):

    CC      kernel/power/hibernate.o
  kernel/power/hibernate.c: In function ‘swsusp_show_speed’:
  kernel/power/hibernate.c:237: warning: comparison of distinct pointer types lacks a cast

Signed-off-by: Chen Gang <gang.chen.5i5j@gmail.com>
---
 kernel/power/hibernate.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/kernel/power/hibernate.c b/kernel/power/hibernate.c
index f4f2073..0dec9b7 100644
--- a/kernel/power/hibernate.c
+++ b/kernel/power/hibernate.c
@@ -228,12 +228,17 @@ static void platform_recover(int platform_mode)
 void swsusp_show_speed(struct timeval *start, struct timeval *stop,
 			unsigned nr_pages, char *msg)
 {
-	s64 elapsed_centisecs64;
+	u64 elapsed_centisecs64;
 	int centisecs;
 	int k;
 	int kps;
 
 	elapsed_centisecs64 = timeval_to_ns(stop) - timeval_to_ns(start);
+	if ((s64)elapsed_centisecs64 < 0) {
+		printk(KERN_ERR "PM: stop: %llu < start %llu\n",
+			timeval_to_ns(stop), timeval_to_ns(start));
+		return;
+	}
 	do_div(elapsed_centisecs64, NSEC_PER_SEC / 100);
 	centisecs = elapsed_centisecs64;
 	if (centisecs == 0)
-- 
1.9.2.459.g68773ac

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] kernel/power/hibernate.c: be sure of 'start' is not bigger than 'stop'
  2014-04-21 13:40 [PATCH] kernel/power/hibernate.c: be sure of 'start' is not bigger than 'stop' Chen Gang
@ 2014-04-21 20:09 ` Pavel Machek
  2014-04-21 20:43   ` Rafael J. Wysocki
  0 siblings, 1 reply; 4+ messages in thread
From: Pavel Machek @ 2014-04-21 20:09 UTC (permalink / raw)
  To: Chen Gang
  Cc: Guan Xuetao, Rafael J. Wysocki, len.brown, linux-pm, linux-kernel

On Mon 2014-04-21 21:40:27, Chen Gang wrote:
> For do_div(), it need 'u64' type, which means the outside must be sure
> of 'start' is not bigger than 'stop', or it will report warning.
> 
> The related warning (with allmodconfig for unicore32):
> 
>     CC      kernel/power/hibernate.o
>   kernel/power/hibernate.c: In function ‘swsusp_show_speed’:
>   kernel/power/hibernate.c:237: warning: comparison of distinct pointer types lacks a cast
> 
> Signed-off-by: Chen Gang <gang.chen.5i5j@gmail.com>

>  {
> -	s64 elapsed_centisecs64;
> +	u64 elapsed_centisecs64;
>  	int centisecs;
>  	int k;
>  	int kps;
>  
>  	elapsed_centisecs64 = timeval_to_ns(stop) - timeval_to_ns(start);
> +	if ((s64)elapsed_centisecs64 < 0) {
> +		printk(KERN_ERR "PM: stop: %llu < start %llu\n",
> +			timeval_to_ns(stop), timeval_to_ns(start));
> +		return;
> +	}
>  	do_div(elapsed_centisecs64, NSEC_PER_SEC / 100);
>  	centisecs = elapsed_centisecs64;
>  	if (centisecs == 0)

Quite a lot of code to shut up warning in mostly debugging
function... is there alternative method of shutting it up? Have you
seen < 0 values in wild? Is it worth handing that situation?
									Pavel
-- 
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] kernel/power/hibernate.c: be sure of 'start' is not bigger than 'stop'
  2014-04-21 20:09 ` Pavel Machek
@ 2014-04-21 20:43   ` Rafael J. Wysocki
  2014-04-22  0:58     ` Chen Gang
  0 siblings, 1 reply; 4+ messages in thread
From: Rafael J. Wysocki @ 2014-04-21 20:43 UTC (permalink / raw)
  To: Pavel Machek; +Cc: Chen Gang, Guan Xuetao, len.brown, linux-pm, linux-kernel

On Monday, April 21, 2014 10:09:30 PM Pavel Machek wrote:
> On Mon 2014-04-21 21:40:27, Chen Gang wrote:
> > For do_div(), it need 'u64' type, which means the outside must be sure
> > of 'start' is not bigger than 'stop', or it will report warning.
> > 
> > The related warning (with allmodconfig for unicore32):
> > 
> >     CC      kernel/power/hibernate.o
> >   kernel/power/hibernate.c: In function ‘swsusp_show_speed’:
> >   kernel/power/hibernate.c:237: warning: comparison of distinct pointer types lacks a cast
> > 
> > Signed-off-by: Chen Gang <gang.chen.5i5j@gmail.com>
> 
> >  {
> > -	s64 elapsed_centisecs64;
> > +	u64 elapsed_centisecs64;
> >  	int centisecs;
> >  	int k;
> >  	int kps;
> >  
> >  	elapsed_centisecs64 = timeval_to_ns(stop) - timeval_to_ns(start);
> > +	if ((s64)elapsed_centisecs64 < 0) {
> > +		printk(KERN_ERR "PM: stop: %llu < start %llu\n",
> > +			timeval_to_ns(stop), timeval_to_ns(start));
> > +		return;
> > +	}
> >  	do_div(elapsed_centisecs64, NSEC_PER_SEC / 100);
> >  	centisecs = elapsed_centisecs64;
> >  	if (centisecs == 0)
> 
> Quite a lot of code to shut up warning in mostly debugging
> function... is there alternative method of shutting it up? Have you
> seen < 0 values in wild?

No, I don't think so.  This is a purely theoretical problem that never
happens in practice, because all of the callers do the right thing.

Rafael 


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] kernel/power/hibernate.c: be sure of 'start' is not bigger than 'stop'
  2014-04-21 20:43   ` Rafael J. Wysocki
@ 2014-04-22  0:58     ` Chen Gang
  0 siblings, 0 replies; 4+ messages in thread
From: Chen Gang @ 2014-04-22  0:58 UTC (permalink / raw)
  To: Rafael J. Wysocki, Pavel Machek
  Cc: Guan Xuetao, len.brown, linux-pm, linux-kernel

On 04/22/2014 04:43 AM, Rafael J. Wysocki wrote:
> On Monday, April 21, 2014 10:09:30 PM Pavel Machek wrote:
>> On Mon 2014-04-21 21:40:27, Chen Gang wrote:
>>> For do_div(), it need 'u64' type, which means the outside must be sure
>>> of 'start' is not bigger than 'stop', or it will report warning.
>>>
>>> The related warning (with allmodconfig for unicore32):
>>>
>>>     CC      kernel/power/hibernate.o
>>>   kernel/power/hibernate.c: In function ‘swsusp_show_speed’:
>>>   kernel/power/hibernate.c:237: warning: comparison of distinct pointer types lacks a cast
>>>
>>> Signed-off-by: Chen Gang <gang.chen.5i5j@gmail.com>
>>
>>>  {
>>> -	s64 elapsed_centisecs64;
>>> +	u64 elapsed_centisecs64;
>>>  	int centisecs;
>>>  	int k;
>>>  	int kps;
>>>  
>>>  	elapsed_centisecs64 = timeval_to_ns(stop) - timeval_to_ns(start);
>>> +	if ((s64)elapsed_centisecs64 < 0) {
>>> +		printk(KERN_ERR "PM: stop: %llu < start %llu\n",
>>> +			timeval_to_ns(stop), timeval_to_ns(start));
>>> +		return;
>>> +	}
>>>  	do_div(elapsed_centisecs64, NSEC_PER_SEC / 100);
>>>  	centisecs = elapsed_centisecs64;
>>>  	if (centisecs == 0)
>>
>> Quite a lot of code to shut up warning in mostly debugging
>> function... is there alternative method of shutting it up? Have you
>> seen < 0 values in wild?
> 
> No, I don't think so.  This is a purely theoretical problem that never
> happens in practice, because all of the callers do the right thing.
> 
> Rafael 
> 

OK, it sounds fine to me, I shall send patch v2 for it.

Thanks.
-- 
Chen Gang

Open, share, and attitude like air, water, and life which God blessed

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2014-04-22  0:58 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-04-21 13:40 [PATCH] kernel/power/hibernate.c: be sure of 'start' is not bigger than 'stop' Chen Gang
2014-04-21 20:09 ` Pavel Machek
2014-04-21 20:43   ` Rafael J. Wysocki
2014-04-22  0:58     ` Chen Gang

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.