diff options
author | Al Viro <viro@ftp.linux.org.uk> | 2007-10-29 01:11:28 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@woody.linux-foundation.org> | 2007-10-29 10:41:33 -0400 |
commit | 142956af525002c5378e7d91d81a01189841a785 (patch) | |
tree | bcf73cc0e2d56d8d46d470fcedaadf42ae0602bd | |
parent | 0c7eb2eb800c4afb2205bbaa1bc633eb29082fef (diff) |
fix abuses of ptrdiff_t
Use of ptrdiff_t in places like
- if (!access_ok(VERIFY_WRITE, u_tmp->rx_buf, u_tmp->len))
+ if (!access_ok(VERIFY_WRITE, (u8 __user *)
+ (ptrdiff_t) u_tmp->rx_buf,
+ u_tmp->len))
is wrong; for one thing, it's a bad C (it's what uintptr_t is for; in general
we are not even promised that ptrdiff_t is large enough to hold a pointer,
just enough to hold a difference between two pointers within the same object).
For another, it confuses the fsck out of sparse.
Use unsigned long or uintptr_t instead. There are several places misusing
ptrdiff_t; fixed.
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
-rw-r--r-- | drivers/scsi/aacraid/commctrl.c | 12 | ||||
-rw-r--r-- | drivers/scsi/aacraid/comminit.c | 2 | ||||
-rw-r--r-- | drivers/scsi/aacraid/dpcsup.c | 2 | ||||
-rw-r--r-- | drivers/spi/spidev.c | 6 | ||||
-rw-r--r-- | include/linux/types.h | 2 |
5 files changed, 13 insertions, 11 deletions
diff --git a/drivers/scsi/aacraid/commctrl.c b/drivers/scsi/aacraid/commctrl.c index 72b0393b4596..1e6d7a9c75bf 100644 --- a/drivers/scsi/aacraid/commctrl.c +++ b/drivers/scsi/aacraid/commctrl.c | |||
@@ -391,7 +391,7 @@ static int close_getadapter_fib(struct aac_dev * dev, void __user *arg) | |||
391 | /* | 391 | /* |
392 | * Extract the fibctx from the input parameters | 392 | * Extract the fibctx from the input parameters |
393 | */ | 393 | */ |
394 | if (fibctx->unique == (u32)(ptrdiff_t)arg) /* We found a winner */ | 394 | if (fibctx->unique == (u32)(uintptr_t)arg) /* We found a winner */ |
395 | break; | 395 | break; |
396 | entry = entry->next; | 396 | entry = entry->next; |
397 | fibctx = NULL; | 397 | fibctx = NULL; |
@@ -590,7 +590,7 @@ static int aac_send_raw_srb(struct aac_dev* dev, void __user * arg) | |||
590 | } | 590 | } |
591 | addr = (u64)upsg->sg[i].addr[0]; | 591 | addr = (u64)upsg->sg[i].addr[0]; |
592 | addr += ((u64)upsg->sg[i].addr[1]) << 32; | 592 | addr += ((u64)upsg->sg[i].addr[1]) << 32; |
593 | sg_user[i] = (void __user *)(ptrdiff_t)addr; | 593 | sg_user[i] = (void __user *)(uintptr_t)addr; |
594 | sg_list[i] = p; // save so we can clean up later | 594 | sg_list[i] = p; // save so we can clean up later |
595 | sg_indx = i; | 595 | sg_indx = i; |
596 | 596 | ||
@@ -633,7 +633,7 @@ static int aac_send_raw_srb(struct aac_dev* dev, void __user * arg) | |||
633 | rcode = -ENOMEM; | 633 | rcode = -ENOMEM; |
634 | goto cleanup; | 634 | goto cleanup; |
635 | } | 635 | } |
636 | sg_user[i] = (void __user *)(ptrdiff_t)usg->sg[i].addr; | 636 | sg_user[i] = (void __user *)(uintptr_t)usg->sg[i].addr; |
637 | sg_list[i] = p; // save so we can clean up later | 637 | sg_list[i] = p; // save so we can clean up later |
638 | sg_indx = i; | 638 | sg_indx = i; |
639 | 639 | ||
@@ -664,7 +664,7 @@ static int aac_send_raw_srb(struct aac_dev* dev, void __user * arg) | |||
664 | if (actual_fibsize64 == fibsize) { | 664 | if (actual_fibsize64 == fibsize) { |
665 | struct user_sgmap64* usg = (struct user_sgmap64 *)upsg; | 665 | struct user_sgmap64* usg = (struct user_sgmap64 *)upsg; |
666 | for (i = 0; i < upsg->count; i++) { | 666 | for (i = 0; i < upsg->count; i++) { |
667 | u64 addr; | 667 | uintptr_t addr; |
668 | void* p; | 668 | void* p; |
669 | /* Does this really need to be GFP_DMA? */ | 669 | /* Does this really need to be GFP_DMA? */ |
670 | p = kmalloc(usg->sg[i].count,GFP_KERNEL|__GFP_DMA); | 670 | p = kmalloc(usg->sg[i].count,GFP_KERNEL|__GFP_DMA); |
@@ -676,7 +676,7 @@ static int aac_send_raw_srb(struct aac_dev* dev, void __user * arg) | |||
676 | } | 676 | } |
677 | addr = (u64)usg->sg[i].addr[0]; | 677 | addr = (u64)usg->sg[i].addr[0]; |
678 | addr += ((u64)usg->sg[i].addr[1]) << 32; | 678 | addr += ((u64)usg->sg[i].addr[1]) << 32; |
679 | sg_user[i] = (void __user *)(ptrdiff_t)addr; | 679 | sg_user[i] = (void __user *)addr; |
680 | sg_list[i] = p; // save so we can clean up later | 680 | sg_list[i] = p; // save so we can clean up later |
681 | sg_indx = i; | 681 | sg_indx = i; |
682 | 682 | ||
@@ -704,7 +704,7 @@ static int aac_send_raw_srb(struct aac_dev* dev, void __user * arg) | |||
704 | rcode = -ENOMEM; | 704 | rcode = -ENOMEM; |
705 | goto cleanup; | 705 | goto cleanup; |
706 | } | 706 | } |
707 | sg_user[i] = (void __user *)(ptrdiff_t)upsg->sg[i].addr; | 707 | sg_user[i] = (void __user *)(uintptr_t)upsg->sg[i].addr; |
708 | sg_list[i] = p; // save so we can clean up later | 708 | sg_list[i] = p; // save so we can clean up later |
709 | sg_indx = i; | 709 | sg_indx = i; |
710 | 710 | ||
diff --git a/drivers/scsi/aacraid/comminit.c b/drivers/scsi/aacraid/comminit.c index 3009ad8c4073..8736813a0296 100644 --- a/drivers/scsi/aacraid/comminit.c +++ b/drivers/scsi/aacraid/comminit.c | |||
@@ -110,7 +110,7 @@ static int aac_alloc_comm(struct aac_dev *dev, void **commaddr, unsigned long co | |||
110 | /* | 110 | /* |
111 | * Align the beginning of Headers to commalign | 111 | * Align the beginning of Headers to commalign |
112 | */ | 112 | */ |
113 | align = (commalign - ((ptrdiff_t)(base) & (commalign - 1))); | 113 | align = (commalign - ((uintptr_t)(base) & (commalign - 1))); |
114 | base = base + align; | 114 | base = base + align; |
115 | phys = phys + align; | 115 | phys = phys + align; |
116 | /* | 116 | /* |
diff --git a/drivers/scsi/aacraid/dpcsup.c b/drivers/scsi/aacraid/dpcsup.c index fcd25f7d0bc6..e6032ffc66a6 100644 --- a/drivers/scsi/aacraid/dpcsup.c +++ b/drivers/scsi/aacraid/dpcsup.c | |||
@@ -254,7 +254,7 @@ unsigned int aac_intr_normal(struct aac_dev * dev, u32 Index) | |||
254 | kfree (fib); | 254 | kfree (fib); |
255 | return 1; | 255 | return 1; |
256 | } | 256 | } |
257 | memcpy(hw_fib, (struct hw_fib *)(((ptrdiff_t)(dev->regs.sa)) + | 257 | memcpy(hw_fib, (struct hw_fib *)(((uintptr_t)(dev->regs.sa)) + |
258 | (index & ~0x00000002L)), sizeof(struct hw_fib)); | 258 | (index & ~0x00000002L)), sizeof(struct hw_fib)); |
259 | INIT_LIST_HEAD(&fib->fiblink); | 259 | INIT_LIST_HEAD(&fib->fiblink); |
260 | fib->type = FSAFS_NTC_FIB_CONTEXT; | 260 | fib->type = FSAFS_NTC_FIB_CONTEXT; |
diff --git a/drivers/spi/spidev.c b/drivers/spi/spidev.c index c55459c592b8..b3518ca9f04e 100644 --- a/drivers/spi/spidev.c +++ b/drivers/spi/spidev.c | |||
@@ -184,14 +184,14 @@ static int spidev_message(struct spidev_data *spidev, | |||
184 | if (u_tmp->rx_buf) { | 184 | if (u_tmp->rx_buf) { |
185 | k_tmp->rx_buf = buf; | 185 | k_tmp->rx_buf = buf; |
186 | if (!access_ok(VERIFY_WRITE, (u8 __user *) | 186 | if (!access_ok(VERIFY_WRITE, (u8 __user *) |
187 | (ptrdiff_t) u_tmp->rx_buf, | 187 | (uintptr_t) u_tmp->rx_buf, |
188 | u_tmp->len)) | 188 | u_tmp->len)) |
189 | goto done; | 189 | goto done; |
190 | } | 190 | } |
191 | if (u_tmp->tx_buf) { | 191 | if (u_tmp->tx_buf) { |
192 | k_tmp->tx_buf = buf; | 192 | k_tmp->tx_buf = buf; |
193 | if (copy_from_user(buf, (const u8 __user *) | 193 | if (copy_from_user(buf, (const u8 __user *) |
194 | (ptrdiff_t) u_tmp->tx_buf, | 194 | (uintptr_t) u_tmp->tx_buf, |
195 | u_tmp->len)) | 195 | u_tmp->len)) |
196 | goto done; | 196 | goto done; |
197 | } | 197 | } |
@@ -224,7 +224,7 @@ static int spidev_message(struct spidev_data *spidev, | |||
224 | for (n = n_xfers, u_tmp = u_xfers; n; n--, u_tmp++) { | 224 | for (n = n_xfers, u_tmp = u_xfers; n; n--, u_tmp++) { |
225 | if (u_tmp->rx_buf) { | 225 | if (u_tmp->rx_buf) { |
226 | if (__copy_to_user((u8 __user *) | 226 | if (__copy_to_user((u8 __user *) |
227 | (ptrdiff_t) u_tmp->rx_buf, buf, | 227 | (uintptr_t) u_tmp->rx_buf, buf, |
228 | u_tmp->len)) { | 228 | u_tmp->len)) { |
229 | status = -EFAULT; | 229 | status = -EFAULT; |
230 | goto done; | 230 | goto done; |
diff --git a/include/linux/types.h b/include/linux/types.h index 4f0dad21c917..f4f8d19158e4 100644 --- a/include/linux/types.h +++ b/include/linux/types.h | |||
@@ -37,6 +37,8 @@ typedef __kernel_gid32_t gid_t; | |||
37 | typedef __kernel_uid16_t uid16_t; | 37 | typedef __kernel_uid16_t uid16_t; |
38 | typedef __kernel_gid16_t gid16_t; | 38 | typedef __kernel_gid16_t gid16_t; |
39 | 39 | ||
40 | typedef unsigned long uintptr_t; | ||
41 | |||
40 | #ifdef CONFIG_UID16 | 42 | #ifdef CONFIG_UID16 |
41 | /* This is defined by include/asm-{arch}/posix_types.h */ | 43 | /* This is defined by include/asm-{arch}/posix_types.h */ |
42 | typedef __kernel_old_uid_t old_uid_t; | 44 | typedef __kernel_old_uid_t old_uid_t; |