Re: [PATCH] usb: gadget: Check for NULL pointer in disconnect

From: Peter Chen
Date: Sun Mar 22 2015 - 03:45:15 EST


On Fri, Mar 20, 2015 at 04:40:52PM -0700, Badhri Jagan Sridharan wrote:
> Added a safety net to make sure that
> composite_disconnect does not end up disconneting
> a NULL device. Prevents NULL pointer crash.
>
> Signed-off-by: Badhri Jagan Sridharan <Badhri@xxxxxxxxxx>
> ---
> drivers/usb/gadget/composite.c | 5 +++++
> 1 file changed, 5 insertions(+)
>
> diff --git a/drivers/usb/gadget/composite.c b/drivers/usb/gadget/composite.c
> index 13adfd1..90b37bd 100644
> --- a/drivers/usb/gadget/composite.c
> +++ b/drivers/usb/gadget/composite.c
> @@ -1823,6 +1823,11 @@ void composite_disconnect(struct usb_gadget *gadget)
> struct usb_composite_dev *cdev = get_gadget_data(gadget);
> unsigned long flags;
>
> + if (!cdev) {
> + WARN(1, "Trying to disconnect a NULL composite device\n");
> + return;
> + }
> +

Do you really see some udc drivers call it after composite_unbind is
called? If it is, you may add dump_stack() to track that error.

Besides this, function suspended_show is needed to add cdev NULL pointer
checking.

> /* REVISIT: should we have config and device level
> * disconnect callbacks?
> */
> --
> 2.2.0.rc0.207.ga3a616c
>
> --
> To unsubscribe from this list: send the line "unsubscribe linux-usb" in
> the body of a message to majordomo@xxxxxxxxxxxxxxx
> More majordomo info at http://vger.kernel.org/majordomo-info.html

--

Best Regards,
Peter Chen
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/