[PATCH] Fix warning in fs/select.c

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



fs/select.c: In function `core_sys_select':
fs/select.c:339: warning: assignment from incompatible pointer type
fs/select.c:376: warning: comparison of distinct pointer types lacks a cast

	char *bits;
	long stack_fds[SELECT_STACK_ALLOC/sizeof(long)];
...
		bits = stack_fds;
...
        if (bits != stack_fds)

Fix this warning by calculating the number of longs we need for 'n' fds.
This then allows us to do correct pointer arithmetic with the minimum
of fuss.

Signed-off-by: Russell King <[email protected]>

diff --git a/fs/select.c b/fs/select.c
--- a/fs/select.c
+++ b/fs/select.c
@@ -310,8 +310,8 @@ static int core_sys_select(int n, fd_set
 			   fd_set __user *exp, s64 *timeout)
 {
 	fd_set_bits fds;
-	char *bits;
-	int ret, size, max_fdset;
+	long *bits;
+	int ret, size_longs, max_fdset;
 	struct fdtable *fdt;
 	/* Allocate small arguments on the stack to save memory and be faster */
 	long stack_fds[SELECT_STACK_ALLOC/sizeof(long)];
@@ -334,19 +334,19 @@ static int core_sys_select(int n, fd_set
 	 * long-words. 
 	 */
 	ret = -ENOMEM;
-	size = FDS_BYTES(n);
-	if (6*size < SELECT_STACK_ALLOC)
+	size_longs = FDS_LONGS(n);
+	if (6 * size_longs * sizeof(long) < SELECT_STACK_ALLOC)
 		bits = stack_fds;
 	else
-		bits = kmalloc(6 * size, GFP_KERNEL);
+		bits = kmalloc(6 * size_longs * sizeof(long), GFP_KERNEL);
 	if (!bits)
 		goto out_nofds;
-	fds.in      = (unsigned long *)  bits;
-	fds.out     = (unsigned long *) (bits +   size);
-	fds.ex      = (unsigned long *) (bits + 2*size);
-	fds.res_in  = (unsigned long *) (bits + 3*size);
-	fds.res_out = (unsigned long *) (bits + 4*size);
-	fds.res_ex  = (unsigned long *) (bits + 5*size);
+	fds.in      = bits;
+	fds.out     = bits +     size_longs;
+	fds.ex      = bits + 2 * size_longs;
+	fds.res_in  = bits + 3 * size_longs;
+	fds.res_out = bits + 4 * size_longs;
+	fds.res_ex  = bits + 5 * size_longs;
 
 	if ((ret = get_fd_set(n, inp, fds.in)) ||
 	    (ret = get_fd_set(n, outp, fds.out)) ||

-- 
Russell King
 Linux kernel    2.6 ARM Linux   - http://www.arm.linux.org.uk/
 maintainer of:  2.6 Serial core
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

[Index of Archives]     [Kernel Newbies]     [Netfilter]     [Bugtraq]     [Photo]     [Stuff]     [Gimp]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Video 4 Linux]     [Linux for the blind]     [Linux Resources]
  Powered by Linux