Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1384710 > unrolled thread
| Started by | Vaishali Thakkar <vaishali.thakkar@oracle.com> |
|---|---|
| First post | 2016-04-22 08:00 +0200 |
| Last post | 2016-04-22 09:00 +0200 |
| Articles | 3 — 3 participants |
Back to article view | Back to linux.kernel
[PATCH] usb: core: Do not use sizeof on pointer type Vaishali Thakkar <vaishali.thakkar@oracle.com> - 2016-04-22 08:00 +0200
Re: [PATCH] usb: core: Do not use sizeof on pointer type Bjørn Mork <bjorn@mork.no> - 2016-04-22 09:00 +0200
Re: [PATCH] usb: core: Do not use sizeof on pointer type Clemens Ladisch <clemens@ladisch.de> - 2016-04-22 09:00 +0200
| From | Vaishali Thakkar <vaishali.thakkar@oracle.com> |
|---|---|
| Date | 2016-04-22 08:00 +0200 |
| Subject | [PATCH] usb: core: Do not use sizeof on pointer type |
| Message-ID | <rqCie-5m3-13@gated-at.bofh.it> |
When sizeof is applied to a pointer typed expression, it gives the size of the pointer. So, do not use sizeof on pointer type. Problem found using Coccinelle. Signed-off-by: Vaishali Thakkar <vaishali.thakkar@oracle.com> --- drivers/usb/core/hcd.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/usb/core/hcd.c b/drivers/usb/core/hcd.c index 2ca2cef..2aa352d 100644 --- a/drivers/usb/core/hcd.c +++ b/drivers/usb/core/hcd.c @@ -1386,7 +1386,7 @@ static int hcd_alloc_coherent(struct usb_bus *bus, return -EFAULT; } - vaddr = hcd_buffer_alloc(bus, size + sizeof(vaddr), + vaddr = hcd_buffer_alloc(bus, size + sizeof(*vaddr), mem_flags, dma_handle); if (!vaddr) return -ENOMEM; -- 2.1.4
[toc] | [next] | [standalone]
| From | Bjørn Mork <bjorn@mork.no> |
|---|---|
| Date | 2016-04-22 09:00 +0200 |
| Message-ID | <rqDei-697-5@gated-at.bofh.it> |
| In reply to | #1384710 |
Vaishali Thakkar <vaishali.thakkar@oracle.com> writes: > When sizeof is applied to a pointer typed expression, it gives > the size of the pointer. So, do not use sizeof on pointer type. What if the intended result was the size of the pointer? > Problem found using Coccinelle. Yes, sure. But you cannot just blindly apply the result without reading and understanding the code. Bjørn
[toc] | [prev] | [next] | [standalone]
| From | Clemens Ladisch <clemens@ladisch.de> |
|---|---|
| Date | 2016-04-22 09:00 +0200 |
| Message-ID | <rqDei-697-17@gated-at.bofh.it> |
| In reply to | #1384710 |
Vaishali Thakkar wrote: > When sizeof is applied to a pointer typed expression, it gives > the size of the pointer. And why would that be wrong in this case? > +++ b/drivers/usb/core/hcd.c > @@ -1386,7 +1386,7 @@ static int hcd_alloc_coherent(struct usb_bus *bus, > return -EFAULT; > } > > - vaddr = hcd_buffer_alloc(bus, size + sizeof(vaddr), > + vaddr = hcd_buffer_alloc(bus, size + sizeof(*vaddr), > mem_flags, dma_handle); > if (!vaddr) > return -ENOMEM; > Please note the following comment: /* * Store the virtual address of the buffer at the end * of the allocated dma buffer. [...] Regards, Clemens
[toc] | [prev] | [standalone]
Back to top | Article view | linux.kernel
csiph-web