Re: [PATCH] drivers: usb: gadget: udc: remove pointer dereference after free

From: Andy Shevchenko
Date: Wed Feb 08 2017 - 14:40:42 EST


On Wed, 2017-02-08 at 13:15 -0600, Gustavo A. R. Silva wrote:
> Remove pointer dereference and write after free.

It's wrong description. There is no write after free. The memory is
still in pool and one may access it. Though the access is *formally*
illegal.

Code itself looks interesting.

>
> Addresses-Coverity-ID: 1091173
> Signed-off-by: Gustavo A. R. Silva <garsilva@xxxxxxxxxxxxxx>
> ---
> Âdrivers/usb/gadget/udc/pch_udc.c | 1 -
> Â1 file changed, 1 deletion(-)
>
> diff --git a/drivers/usb/gadget/udc/pch_udc.c
> b/drivers/usb/gadget/udc/pch_udc.c
> index a97da64..8a365aa 100644
> --- a/drivers/usb/gadget/udc/pch_udc.c
> +++ b/drivers/usb/gadget/udc/pch_udc.c
> @@ -1523,7 +1523,6 @@ static void pch_udc_free_dma_chain(struct
> pch_udc_dev *dev,
> Â td = phys_to_virt(addr);
> Â addr2 = (dma_addr_t)td->next;
> Â pci_pool_free(dev->data_requests, td, addr);
> - td->next = 0x00;

I think the better fix is to move this line before pci_pool_free() call.
I dunno those td->next = 0x00; make any sense there.

Is it done under some lock / serialization?

> Â addr = addr2;
> Â }
> Â req->chain_len = 1;

--
Andy Shevchenko <andriy.shevchenko@xxxxxxxxxxxxxxx>
Intel Finland Oy