]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
usb: gadget: Check bmAttributes only if configuration is valid
authorPrashanth K <prashanth.k@oss.qualcomm.com>
Mon, 24 Feb 2025 08:56:04 +0000 (14:26 +0530)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Mon, 3 Mar 2025 09:12:14 +0000 (10:12 +0100)
If the USB configuration is not valid, then avoid checking for
bmAttributes to prevent null pointer deference.

Cc: stable <stable@kernel.org>
Fixes: 40e89ff5750f ("usb: gadget: Set self-powered based on MaxPower and bmAttributes")
Signed-off-by: Prashanth K <prashanth.k@oss.qualcomm.com>
Link: https://lore.kernel.org/r/20250224085604.417327-1-prashanth.k@oss.qualcomm.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/usb/gadget/composite.c

index 4bcf73bae761077056bcd5941dd3912968eb6117..869ad99afb48bbeed623224f1b5b5aebc1dce256 100644 (file)
@@ -1051,7 +1051,7 @@ static int set_config(struct usb_composite_dev *cdev,
                usb_gadget_set_remote_wakeup(gadget, 0);
 done:
        if (power > USB_SELF_POWER_VBUS_MAX_DRAW ||
-           !(c->bmAttributes & USB_CONFIG_ATT_SELFPOWER))
+           (c && !(c->bmAttributes & USB_CONFIG_ATT_SELFPOWER)))
                usb_gadget_clear_selfpowered(gadget);
        else
                usb_gadget_set_selfpowered(gadget);