public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] FLAT: use IS_ERR_VALUE() helper macro
@ 2009-07-01 18:26 Mike Frysinger
  2009-07-01 23:54 ` David McCullough
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: Mike Frysinger @ 2009-07-01 18:26 UTC (permalink / raw)
  To: linux-kernel
  Cc: uclinux-dist-devel, David Howells, David McCullough, Greg Ungerer,
	Paul Mundt, uclinux-dev

There is a common macro now for testing mixed pointer/errno values, so use
that rather than handling the casts ourself.

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
---
 fs/binfmt_flat.c |   22 ++++++++++------------
 1 files changed, 10 insertions(+), 12 deletions(-)

diff --git a/fs/binfmt_flat.c b/fs/binfmt_flat.c
index 697f6b5..f22b312 100644
--- a/fs/binfmt_flat.c
+++ b/fs/binfmt_flat.c
@@ -278,8 +278,6 @@ static int decompress_exec(
 		ret = bprm->file->f_op->read(bprm->file, buf, LBUFSIZE, &fpos);
 		if (ret <= 0)
 			break;
-		if (ret >= (unsigned long) -4096)
-			break;
 		len -= ret;
 
 		strm.next_in = buf;
@@ -335,7 +333,7 @@ calc_reloc(unsigned long r, struct lib_info *p, int curid, int internalp)
 					"(%d != %d)", (unsigned) r, curid, id);
 			goto failed;
 		} else if ( ! p->lib_list[id].loaded &&
-				load_flat_shared_library(id, p) > (unsigned long) -4096) {
+				IS_ERR_VALUE(load_flat_shared_library(id, p))) {
 			printk("BINFMT_FLAT: failed to load library %d", id);
 			goto failed;
 		}
@@ -545,7 +543,7 @@ static int load_flat_file(struct linux_binprm * bprm,
 		textpos = do_mmap(bprm->file, 0, text_len, PROT_READ|PROT_EXEC,
 				  MAP_PRIVATE|MAP_EXECUTABLE, 0);
 		up_write(&current->mm->mmap_sem);
-		if (!textpos  || textpos >= (unsigned long) -4096) {
+		if (!textpos || IS_ERR_VALUE(textpos)) {
 			if (!textpos)
 				textpos = (unsigned long) -ENOMEM;
 			printk("Unable to mmap process text, errno %d\n", (int)-textpos);
@@ -560,7 +558,7 @@ static int load_flat_file(struct linux_binprm * bprm,
 			PROT_READ|PROT_WRITE|PROT_EXEC, MAP_PRIVATE, 0);
 		up_write(&current->mm->mmap_sem);
 
-		if (realdatastart == 0 || realdatastart >= (unsigned long)-4096) {
+		if (realdatastart == 0 || IS_ERR_VALUE(realdatastart)) {
 			if (!realdatastart)
 				realdatastart = (unsigned long) -ENOMEM;
 			printk("Unable to allocate RAM for process data, errno %d\n",
@@ -587,7 +585,7 @@ static int load_flat_file(struct linux_binprm * bprm,
 			result = bprm->file->f_op->read(bprm->file, (char *) datapos,
 					data_len + (relocs * sizeof(unsigned long)), &fpos);
 		}
-		if (result >= (unsigned long)-4096) {
+		if (IS_ERR_VALUE(result)) {
 			printk("Unable to read data+bss, errno %d\n", (int)-result);
 			do_munmap(current->mm, textpos, text_len);
 			do_munmap(current->mm, realdatastart, data_len + extra);
@@ -607,7 +605,7 @@ static int load_flat_file(struct linux_binprm * bprm,
 			PROT_READ | PROT_EXEC | PROT_WRITE, MAP_PRIVATE, 0);
 		up_write(&current->mm->mmap_sem);
 
-		if (!textpos  || textpos >= (unsigned long) -4096) {
+		if (!textpos || IS_ERR_VALUE(textpos)) {
 			if (!textpos)
 				textpos = (unsigned long) -ENOMEM;
 			printk("Unable to allocate RAM for process text/data, errno %d\n",
@@ -641,7 +639,7 @@ static int load_flat_file(struct linux_binprm * bprm,
 			fpos = 0;
 			result = bprm->file->f_op->read(bprm->file,
 					(char *) textpos, text_len, &fpos);
-			if (result < (unsigned long) -4096)
+			if (!IS_ERR_VALUE(result))
 				result = decompress_exec(bprm, text_len, (char *) datapos,
 						 data_len + (relocs * sizeof(unsigned long)), 0);
 		}
@@ -651,13 +649,13 @@ static int load_flat_file(struct linux_binprm * bprm,
 			fpos = 0;
 			result = bprm->file->f_op->read(bprm->file,
 					(char *) textpos, text_len, &fpos);
-			if (result < (unsigned long) -4096) {
+			if (!IS_ERR_VALUE(result)) {
 				fpos = ntohl(hdr->data_start);
 				result = bprm->file->f_op->read(bprm->file, (char *) datapos,
 					data_len + (relocs * sizeof(unsigned long)), &fpos);
 			}
 		}
-		if (result >= (unsigned long)-4096) {
+		if (IS_ERR_VALUE(result)) {
 			printk("Unable to read code+data+bss, errno %d\n",(int)-result);
 			do_munmap(current->mm, textpos, text_len + data_len + extra +
 				MAX_SHARED_LIBS * sizeof(unsigned long));
@@ -830,7 +828,7 @@ static int load_flat_shared_library(int id, struct lib_info *libs)
 
 	res = prepare_binprm(&bprm);
 
-	if (res <= (unsigned long)-4096)
+	if (!IS_ERR_VALUE(res))
 		res = load_flat_file(&bprm, libs, id, NULL);
 	if (bprm.file) {
 		allow_write_access(bprm.file);
@@ -873,7 +871,7 @@ static int load_flat_binary(struct linux_binprm * bprm, struct pt_regs * regs)
 	stack_len += FLAT_DATA_ALIGN - 1;  /* reserve for upcoming alignment */
 	
 	res = load_flat_file(bprm, &libinfo, 0, &stack_len);
-	if (res > (unsigned long)-4096)
+	if (IS_ERR_VALUE(res))
 		return res;
 	
 	/* Update data segment pointers for all libraries */
-- 
1.6.3.3


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

* Re: [PATCH] FLAT: use IS_ERR_VALUE() helper macro
  2009-07-01 18:26 [PATCH] FLAT: use IS_ERR_VALUE() helper macro Mike Frysinger
@ 2009-07-01 23:54 ` David McCullough
  2009-07-02  0:21 ` Greg Ungerer
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: David McCullough @ 2009-07-01 23:54 UTC (permalink / raw)
  To: Mike Frysinger
  Cc: linux-kernel, uclinux-dist-devel, David Howells, Greg Ungerer,
	Paul Mundt, uclinux-dev


Jivin Mike Frysinger lays it down ...
> There is a common macro now for testing mixed pointer/errno values, so use
> that rather than handling the casts ourself.
> 
> Signed-off-by: Mike Frysinger <vapier@gentoo.org>

Acked-by: David McCullough <david_mccullough@securecomputing.com>

Cheers,
Davidm

> ---
>  fs/binfmt_flat.c |   22 ++++++++++------------
>  1 files changed, 10 insertions(+), 12 deletions(-)
> 
> diff --git a/fs/binfmt_flat.c b/fs/binfmt_flat.c
> index 697f6b5..f22b312 100644
> --- a/fs/binfmt_flat.c
> +++ b/fs/binfmt_flat.c
> @@ -278,8 +278,6 @@ static int decompress_exec(
>  		ret = bprm->file->f_op->read(bprm->file, buf, LBUFSIZE, &fpos);
>  		if (ret <= 0)
>  			break;
> -		if (ret >= (unsigned long) -4096)
> -			break;
>  		len -= ret;
>  
>  		strm.next_in = buf;
> @@ -335,7 +333,7 @@ calc_reloc(unsigned long r, struct lib_info *p, int curid, int internalp)
>  					"(%d != %d)", (unsigned) r, curid, id);
>  			goto failed;
>  		} else if ( ! p->lib_list[id].loaded &&
> -				load_flat_shared_library(id, p) > (unsigned long) -4096) {
> +				IS_ERR_VALUE(load_flat_shared_library(id, p))) {
>  			printk("BINFMT_FLAT: failed to load library %d", id);
>  			goto failed;
>  		}
> @@ -545,7 +543,7 @@ static int load_flat_file(struct linux_binprm * bprm,
>  		textpos = do_mmap(bprm->file, 0, text_len, PROT_READ|PROT_EXEC,
>  				  MAP_PRIVATE|MAP_EXECUTABLE, 0);
>  		up_write(&current->mm->mmap_sem);
> -		if (!textpos  || textpos >= (unsigned long) -4096) {
> +		if (!textpos || IS_ERR_VALUE(textpos)) {
>  			if (!textpos)
>  				textpos = (unsigned long) -ENOMEM;
>  			printk("Unable to mmap process text, errno %d\n", (int)-textpos);
> @@ -560,7 +558,7 @@ static int load_flat_file(struct linux_binprm * bprm,
>  			PROT_READ|PROT_WRITE|PROT_EXEC, MAP_PRIVATE, 0);
>  		up_write(&current->mm->mmap_sem);
>  
> -		if (realdatastart == 0 || realdatastart >= (unsigned long)-4096) {
> +		if (realdatastart == 0 || IS_ERR_VALUE(realdatastart)) {
>  			if (!realdatastart)
>  				realdatastart = (unsigned long) -ENOMEM;
>  			printk("Unable to allocate RAM for process data, errno %d\n",
> @@ -587,7 +585,7 @@ static int load_flat_file(struct linux_binprm * bprm,
>  			result = bprm->file->f_op->read(bprm->file, (char *) datapos,
>  					data_len + (relocs * sizeof(unsigned long)), &fpos);
>  		}
> -		if (result >= (unsigned long)-4096) {
> +		if (IS_ERR_VALUE(result)) {
>  			printk("Unable to read data+bss, errno %d\n", (int)-result);
>  			do_munmap(current->mm, textpos, text_len);
>  			do_munmap(current->mm, realdatastart, data_len + extra);
> @@ -607,7 +605,7 @@ static int load_flat_file(struct linux_binprm * bprm,
>  			PROT_READ | PROT_EXEC | PROT_WRITE, MAP_PRIVATE, 0);
>  		up_write(&current->mm->mmap_sem);
>  
> -		if (!textpos  || textpos >= (unsigned long) -4096) {
> +		if (!textpos || IS_ERR_VALUE(textpos)) {
>  			if (!textpos)
>  				textpos = (unsigned long) -ENOMEM;
>  			printk("Unable to allocate RAM for process text/data, errno %d\n",
> @@ -641,7 +639,7 @@ static int load_flat_file(struct linux_binprm * bprm,
>  			fpos = 0;
>  			result = bprm->file->f_op->read(bprm->file,
>  					(char *) textpos, text_len, &fpos);
> -			if (result < (unsigned long) -4096)
> +			if (!IS_ERR_VALUE(result))
>  				result = decompress_exec(bprm, text_len, (char *) datapos,
>  						 data_len + (relocs * sizeof(unsigned long)), 0);
>  		}
> @@ -651,13 +649,13 @@ static int load_flat_file(struct linux_binprm * bprm,
>  			fpos = 0;
>  			result = bprm->file->f_op->read(bprm->file,
>  					(char *) textpos, text_len, &fpos);
> -			if (result < (unsigned long) -4096) {
> +			if (!IS_ERR_VALUE(result)) {
>  				fpos = ntohl(hdr->data_start);
>  				result = bprm->file->f_op->read(bprm->file, (char *) datapos,
>  					data_len + (relocs * sizeof(unsigned long)), &fpos);
>  			}
>  		}
> -		if (result >= (unsigned long)-4096) {
> +		if (IS_ERR_VALUE(result)) {
>  			printk("Unable to read code+data+bss, errno %d\n",(int)-result);
>  			do_munmap(current->mm, textpos, text_len + data_len + extra +
>  				MAX_SHARED_LIBS * sizeof(unsigned long));
> @@ -830,7 +828,7 @@ static int load_flat_shared_library(int id, struct lib_info *libs)
>  
>  	res = prepare_binprm(&bprm);
>  
> -	if (res <= (unsigned long)-4096)
> +	if (!IS_ERR_VALUE(res))
>  		res = load_flat_file(&bprm, libs, id, NULL);
>  	if (bprm.file) {
>  		allow_write_access(bprm.file);
> @@ -873,7 +871,7 @@ static int load_flat_binary(struct linux_binprm * bprm, struct pt_regs * regs)
>  	stack_len += FLAT_DATA_ALIGN - 1;  /* reserve for upcoming alignment */
>  	
>  	res = load_flat_file(bprm, &libinfo, 0, &stack_len);
> -	if (res > (unsigned long)-4096)
> +	if (IS_ERR_VALUE(res))
>  		return res;
>  	
>  	/* Update data segment pointers for all libraries */
> -- 
> 1.6.3.3
> 

-- 
David McCullough,  david_mccullough@securecomputing.com,  Ph:+61 734352815
McAfee - SnapGear  http://www.snapgear.com                http://www.uCdot.org

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

* Re: [PATCH] FLAT: use IS_ERR_VALUE() helper macro
  2009-07-01 18:26 [PATCH] FLAT: use IS_ERR_VALUE() helper macro Mike Frysinger
  2009-07-01 23:54 ` David McCullough
@ 2009-07-02  0:21 ` Greg Ungerer
  2009-07-02  8:43 ` David Howells
  2009-07-02 17:21 ` Paul Mundt
  3 siblings, 0 replies; 5+ messages in thread
From: Greg Ungerer @ 2009-07-02  0:21 UTC (permalink / raw)
  To: Mike Frysinger
  Cc: linux-kernel, uclinux-dist-devel, David Howells, David McCullough,
	Paul Mundt, uclinux-dev


Mike Frysinger wrote:
> There is a common macro now for testing mixed pointer/errno values, so use
> that rather than handling the casts ourself.
> 
> Signed-off-by: Mike Frysinger <vapier@gentoo.org>

Acked-by: Greg Ungerer <gerg@uclinux.org>



> ---
>  fs/binfmt_flat.c |   22 ++++++++++------------
>  1 files changed, 10 insertions(+), 12 deletions(-)
> 
> diff --git a/fs/binfmt_flat.c b/fs/binfmt_flat.c
> index 697f6b5..f22b312 100644
> --- a/fs/binfmt_flat.c
> +++ b/fs/binfmt_flat.c
> @@ -278,8 +278,6 @@ static int decompress_exec(
>  		ret = bprm->file->f_op->read(bprm->file, buf, LBUFSIZE, &fpos);
>  		if (ret <= 0)
>  			break;
> -		if (ret >= (unsigned long) -4096)
> -			break;
>  		len -= ret;
>  
>  		strm.next_in = buf;
> @@ -335,7 +333,7 @@ calc_reloc(unsigned long r, struct lib_info *p, int curid, int internalp)
>  					"(%d != %d)", (unsigned) r, curid, id);
>  			goto failed;
>  		} else if ( ! p->lib_list[id].loaded &&
> -				load_flat_shared_library(id, p) > (unsigned long) -4096) {
> +				IS_ERR_VALUE(load_flat_shared_library(id, p))) {
>  			printk("BINFMT_FLAT: failed to load library %d", id);
>  			goto failed;
>  		}
> @@ -545,7 +543,7 @@ static int load_flat_file(struct linux_binprm * bprm,
>  		textpos = do_mmap(bprm->file, 0, text_len, PROT_READ|PROT_EXEC,
>  				  MAP_PRIVATE|MAP_EXECUTABLE, 0);
>  		up_write(&current->mm->mmap_sem);
> -		if (!textpos  || textpos >= (unsigned long) -4096) {
> +		if (!textpos || IS_ERR_VALUE(textpos)) {
>  			if (!textpos)
>  				textpos = (unsigned long) -ENOMEM;
>  			printk("Unable to mmap process text, errno %d\n", (int)-textpos);
> @@ -560,7 +558,7 @@ static int load_flat_file(struct linux_binprm * bprm,
>  			PROT_READ|PROT_WRITE|PROT_EXEC, MAP_PRIVATE, 0);
>  		up_write(&current->mm->mmap_sem);
>  
> -		if (realdatastart == 0 || realdatastart >= (unsigned long)-4096) {
> +		if (realdatastart == 0 || IS_ERR_VALUE(realdatastart)) {
>  			if (!realdatastart)
>  				realdatastart = (unsigned long) -ENOMEM;
>  			printk("Unable to allocate RAM for process data, errno %d\n",
> @@ -587,7 +585,7 @@ static int load_flat_file(struct linux_binprm * bprm,
>  			result = bprm->file->f_op->read(bprm->file, (char *) datapos,
>  					data_len + (relocs * sizeof(unsigned long)), &fpos);
>  		}
> -		if (result >= (unsigned long)-4096) {
> +		if (IS_ERR_VALUE(result)) {
>  			printk("Unable to read data+bss, errno %d\n", (int)-result);
>  			do_munmap(current->mm, textpos, text_len);
>  			do_munmap(current->mm, realdatastart, data_len + extra);
> @@ -607,7 +605,7 @@ static int load_flat_file(struct linux_binprm * bprm,
>  			PROT_READ | PROT_EXEC | PROT_WRITE, MAP_PRIVATE, 0);
>  		up_write(&current->mm->mmap_sem);
>  
> -		if (!textpos  || textpos >= (unsigned long) -4096) {
> +		if (!textpos || IS_ERR_VALUE(textpos)) {
>  			if (!textpos)
>  				textpos = (unsigned long) -ENOMEM;
>  			printk("Unable to allocate RAM for process text/data, errno %d\n",
> @@ -641,7 +639,7 @@ static int load_flat_file(struct linux_binprm * bprm,
>  			fpos = 0;
>  			result = bprm->file->f_op->read(bprm->file,
>  					(char *) textpos, text_len, &fpos);
> -			if (result < (unsigned long) -4096)
> +			if (!IS_ERR_VALUE(result))
>  				result = decompress_exec(bprm, text_len, (char *) datapos,
>  						 data_len + (relocs * sizeof(unsigned long)), 0);
>  		}
> @@ -651,13 +649,13 @@ static int load_flat_file(struct linux_binprm * bprm,
>  			fpos = 0;
>  			result = bprm->file->f_op->read(bprm->file,
>  					(char *) textpos, text_len, &fpos);
> -			if (result < (unsigned long) -4096) {
> +			if (!IS_ERR_VALUE(result)) {
>  				fpos = ntohl(hdr->data_start);
>  				result = bprm->file->f_op->read(bprm->file, (char *) datapos,
>  					data_len + (relocs * sizeof(unsigned long)), &fpos);
>  			}
>  		}
> -		if (result >= (unsigned long)-4096) {
> +		if (IS_ERR_VALUE(result)) {
>  			printk("Unable to read code+data+bss, errno %d\n",(int)-result);
>  			do_munmap(current->mm, textpos, text_len + data_len + extra +
>  				MAX_SHARED_LIBS * sizeof(unsigned long));
> @@ -830,7 +828,7 @@ static int load_flat_shared_library(int id, struct lib_info *libs)
>  
>  	res = prepare_binprm(&bprm);
>  
> -	if (res <= (unsigned long)-4096)
> +	if (!IS_ERR_VALUE(res))
>  		res = load_flat_file(&bprm, libs, id, NULL);
>  	if (bprm.file) {
>  		allow_write_access(bprm.file);
> @@ -873,7 +871,7 @@ static int load_flat_binary(struct linux_binprm * bprm, struct pt_regs * regs)
>  	stack_len += FLAT_DATA_ALIGN - 1;  /* reserve for upcoming alignment */
>  	
>  	res = load_flat_file(bprm, &libinfo, 0, &stack_len);
> -	if (res > (unsigned long)-4096)
> +	if (IS_ERR_VALUE(res))
>  		return res;
>  	
>  	/* Update data segment pointers for all libraries */

-- 
------------------------------------------------------------------------
Greg Ungerer  --  Principal Engineer        EMAIL:     gerg@snapgear.com
SnapGear Group, McAfee                      PHONE:       +61 7 3435 2888
825 Stanley St,                             FAX:         +61 7 3891 3630
Woolloongabba, QLD, 4102, Australia         WEB: http://www.SnapGear.com

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

* Re: [PATCH] FLAT: use IS_ERR_VALUE() helper macro
  2009-07-01 18:26 [PATCH] FLAT: use IS_ERR_VALUE() helper macro Mike Frysinger
  2009-07-01 23:54 ` David McCullough
  2009-07-02  0:21 ` Greg Ungerer
@ 2009-07-02  8:43 ` David Howells
  2009-07-02 17:21 ` Paul Mundt
  3 siblings, 0 replies; 5+ messages in thread
From: David Howells @ 2009-07-02  8:43 UTC (permalink / raw)
  To: Mike Frysinger
  Cc: dhowells, linux-kernel, uclinux-dist-devel, David McCullough,
	Greg Ungerer, Paul Mundt, uclinux-dev

Mike Frysinger <vapier@gentoo.org> wrote:

> There is a common macro now for testing mixed pointer/errno values, so use
> that rather than handling the casts ourself.
> 
> Signed-off-by: Mike Frysinger <vapier@gentoo.org>

Acked-by: David Howells <dhowells@redhat.com>

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

* Re: [PATCH] FLAT: use IS_ERR_VALUE() helper macro
  2009-07-01 18:26 [PATCH] FLAT: use IS_ERR_VALUE() helper macro Mike Frysinger
                   ` (2 preceding siblings ...)
  2009-07-02  8:43 ` David Howells
@ 2009-07-02 17:21 ` Paul Mundt
  3 siblings, 0 replies; 5+ messages in thread
From: Paul Mundt @ 2009-07-02 17:21 UTC (permalink / raw)
  To: Mike Frysinger
  Cc: linux-kernel, uclinux-dist-devel, David Howells, David McCullough,
	Greg Ungerer, uclinux-dev

On Wed, Jul 01, 2009 at 02:26:42PM -0400, Mike Frysinger wrote:
> There is a common macro now for testing mixed pointer/errno values, so use
> that rather than handling the casts ourself.
> 
> Signed-off-by: Mike Frysinger <vapier@gentoo.org>

Acked-by: Paul Mundt <lethal@linux-sh.org>

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

end of thread, other threads:[~2009-07-02 17:21 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-07-01 18:26 [PATCH] FLAT: use IS_ERR_VALUE() helper macro Mike Frysinger
2009-07-01 23:54 ` David McCullough
2009-07-02  0:21 ` Greg Ungerer
2009-07-02  8:43 ` David Howells
2009-07-02 17:21 ` Paul Mundt

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox