LKML Archive on lore.kernel.org
help / color / mirror / Atom feed
* [PATCH 12/14] fs/binfmt_aout.c: Use time_* macros
@ 2008-02-14 15:36 S.Çağlar Onur
  2008-02-14 19:46 ` Geert Uytterhoeven
  0 siblings, 1 reply; 3+ messages in thread
From: S.Çağlar Onur @ 2008-02-14 15:36 UTC (permalink / raw)
  To: linux-kernel; +Cc: linux-arch, S.Çağlar Onur

The functions time_before, time_before_eq, time_after, and time_after_eq are more robust for comparing jiffies against other values.

So following patch implements usage of the time_after() macro, defined at linux/jiffies.h, which deals with wrapping correctly

Cc: linux-arch@vger.kernel.org
Signed-off-by: S.Çağlar Onur <caglar@pardus.org.tr>
---
 fs/binfmt_aout.c |    7 ++++---
 1 files changed, 4 insertions(+), 3 deletions(-)

diff --git a/fs/binfmt_aout.c b/fs/binfmt_aout.c
index a1bb224..72757fe 100644
--- a/fs/binfmt_aout.c
+++ b/fs/binfmt_aout.c
@@ -6,6 +6,7 @@
 
 #include <linux/module.h>
 
+#include <linux/jiffies.h>
 #include <linux/time.h>
 #include <linux/kernel.h>
 #include <linux/mm.h>
@@ -374,14 +375,14 @@ static int load_aout_binary(struct linux_binprm * bprm, struct pt_regs * regs)
 	} else {
 		static unsigned long error_time, error_time2;
 		if ((ex.a_text & 0xfff || ex.a_data & 0xfff) &&
-		    (N_MAGIC(ex) != NMAGIC) && (jiffies-error_time2) > 5*HZ)
+		    (N_MAGIC(ex) != NMAGIC) && time_after(jiffies, error_time2 + 5 * HZ))
 		{
 			printk(KERN_NOTICE "executable not page aligned\n");
 			error_time2 = jiffies;
 		}
 
 		if ((fd_offset & ~PAGE_MASK) != 0 &&
-		    (jiffies-error_time) > 5*HZ)
+		    time_after(jiffies, error_time + 5 * HZ))
 		{
 			printk(KERN_WARNING 
 			       "fd_offset is not page aligned. Please convert program: %s\n",
@@ -498,7 +499,7 @@ static int load_aout_library(struct file *file)
 		static unsigned long error_time;
 		loff_t pos = N_TXTOFF(ex);
 
-		if ((jiffies-error_time) > 5*HZ)
+		if (time_after(jiffies ,error_time + 5 * HZ))
 		{
 			printk(KERN_WARNING 
 			       "N_TXTOFF is not page aligned. Please convert library: %s\n",
-- 
1.5.3.7


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

* Re: [PATCH 12/14] fs/binfmt_aout.c: Use time_* macros
  2008-02-14 15:36 [PATCH 12/14] fs/binfmt_aout.c: Use time_* macros S.Çağlar Onur
@ 2008-02-14 19:46 ` Geert Uytterhoeven
  2008-02-15  1:19   ` S.Çağlar Onur
  0 siblings, 1 reply; 3+ messages in thread
From: Geert Uytterhoeven @ 2008-02-14 19:46 UTC (permalink / raw)
  To: S.Çağlar Onur; +Cc: linux-kernel, linux-arch

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: TEXT/PLAIN; charset=UTF-8, Size: 2248 bytes --]

On Thu, 14 Feb 2008, S.Ã~GaÄ~_lar Onur wrote:
> The functions time_before, time_before_eq, time_after, and time_after_eq are more robust for comparing jiffies against other values.
> 
> So following patch implements usage of the time_after() macro, defined at linux/jiffies.h, which deals with wrapping correctly
> 
> Cc: linux-arch@vger.kernel.org
> Signed-off-by: S.Çağlar Onur <caglar@pardus.org.tr>
> ---
>  fs/binfmt_aout.c |    7 ++++---
>  1 files changed, 4 insertions(+), 3 deletions(-)
> 
> diff --git a/fs/binfmt_aout.c b/fs/binfmt_aout.c
> index a1bb224..72757fe 100644
> --- a/fs/binfmt_aout.c
> +++ b/fs/binfmt_aout.c
> @@ -6,6 +6,7 @@
>  
>  #include <linux/module.h>
>  
> +#include <linux/jiffies.h>
>  #include <linux/time.h>
>  #include <linux/kernel.h>
>  #include <linux/mm.h>
> @@ -374,14 +375,14 @@ static int load_aout_binary(struct linux_binprm * bprm, struct pt_regs * regs)
>  	} else {
>  		static unsigned long error_time, error_time2;
>  		if ((ex.a_text & 0xfff || ex.a_data & 0xfff) &&
> -		    (N_MAGIC(ex) != NMAGIC) && (jiffies-error_time2) > 5*HZ)
> +		    (N_MAGIC(ex) != NMAGIC) && time_after(jiffies, error_time2 + 5 * HZ))
>  		{
>  			printk(KERN_NOTICE "executable not page aligned\n");
>  			error_time2 = jiffies;
>  		}
>
>  
>  		if ((fd_offset & ~PAGE_MASK) != 0 &&
> -		    (jiffies-error_time) > 5*HZ)
> +		    time_after(jiffies, error_time + 5 * HZ))
>  		{
>  			printk(KERN_WARNING 
>  			       "fd_offset is not page aligned. Please convert program: %s\n",
> @@ -498,7 +499,7 @@ static int load_aout_library(struct file *file)
>  		static unsigned long error_time;
>  		loff_t pos = N_TXTOFF(ex);
>  
> -		if ((jiffies-error_time) > 5*HZ)
> +		if (time_after(jiffies ,error_time + 5 * HZ))
>  		{
>  			printk(KERN_WARNING 
>  			       "N_TXTOFF is not page aligned. Please convert library: %s\n",

To me these constructs look like good candidates for replacement by
printk_ratelimit()?

Gr{oetje,eeting}s,

						Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
							    -- Linus Torvalds

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

* Re: [PATCH 12/14] fs/binfmt_aout.c: Use time_* macros
  2008-02-14 19:46 ` Geert Uytterhoeven
@ 2008-02-15  1:19   ` S.Çağlar Onur
  0 siblings, 0 replies; 3+ messages in thread
From: S.Çağlar Onur @ 2008-02-15  1:19 UTC (permalink / raw)
  To: Geert Uytterhoeven; +Cc: linux-kernel, linux-arch

14 Şub 2008 Per tarihinde, Geert Uytterhoeven şunları yazmıştı: 
> To me these constructs look like good candidates for replacement by
> printk_ratelimit()?
> 
> Gr{oetje,eeting}s,

What about something like following?


Use printk_ratelimit() instead of jiffies based arithmetic, suggested by Geert Uytterhoeven

Signed-off-by: S.Çağlar Onur <caglar@pardus.org.tr>

 fs/binfmt_aout.c |   12 +++---------
 1 files changed, 3 insertions(+), 9 deletions(-)

diff --git a/fs/binfmt_aout.c b/fs/binfmt_aout.c
index a1bb224..ba4cddb 100644
--- a/fs/binfmt_aout.c
+++ b/fs/binfmt_aout.c
@@ -372,21 +372,17 @@ static int load_aout_binary(struct linux_binprm * bprm, struct pt_regs * regs)
 			 
 		flush_icache_range(text_addr, text_addr+ex.a_text+ex.a_data);
 	} else {
-		static unsigned long error_time, error_time2;
 		if ((ex.a_text & 0xfff || ex.a_data & 0xfff) &&
-		    (N_MAGIC(ex) != NMAGIC) && (jiffies-error_time2) > 5*HZ)
+		    (N_MAGIC(ex) != NMAGIC) && printk_ratelimit())
 		{
 			printk(KERN_NOTICE "executable not page aligned\n");
-			error_time2 = jiffies;
 		}
 
-		if ((fd_offset & ~PAGE_MASK) != 0 &&
-		    (jiffies-error_time) > 5*HZ)
+		if ((fd_offset & ~PAGE_MASK) != 0 && printk_ratelimit())
 		{
 			printk(KERN_WARNING 
 			       "fd_offset is not page aligned. Please convert program: %s\n",
 			       bprm->file->f_path.dentry->d_name.name);
-			error_time = jiffies;
 		}
 
 		if (!bprm->file->f_op->mmap||((fd_offset & ~PAGE_MASK) != 0)) {
@@ -495,15 +491,13 @@ static int load_aout_library(struct file *file)
 	start_addr =  ex.a_entry & 0xfffff000;
 
 	if ((N_TXTOFF(ex) & ~PAGE_MASK) != 0) {
-		static unsigned long error_time;
 		loff_t pos = N_TXTOFF(ex);
 
-		if ((jiffies-error_time) > 5*HZ)
+		if (printk_ratelimit())
 		{
 			printk(KERN_WARNING 
 			       "N_TXTOFF is not page aligned. Please convert library: %s\n",
 			       file->f_path.dentry->d_name.name);
-			error_time = jiffies;
 		}
 		down_write(&current->mm->mmap_sem);
 		do_brk(start_addr, ex.a_text + ex.a_data + ex.a_bss);

Cheers
-- 
S.Çağlar Onur <caglar@pardus.org.tr>
http://cekirdek.pardus.org.tr/~caglar/

Linux is like living in a teepee. No Windows, no Gates and an Apache in house!

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

end of thread, other threads:[~2008-02-15  1:22 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-02-14 15:36 [PATCH 12/14] fs/binfmt_aout.c: Use time_* macros S.Çağlar Onur
2008-02-14 19:46 ` Geert Uytterhoeven
2008-02-15  1:19   ` S.Çağlar Onur

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).