summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPrashanth K <prashanth.k@oss.qualcomm.com>2025-02-24 14:26:04 +0530
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2025-03-13 12:47:42 +0100
commitd7256759f4683121d97f7aaf3287a308d562a69e (patch)
tree039cc7f63ead2d3264e8f7a75538d99262f8d4c1
parent2b3a4faf0479ab8e1cb293d3ef7c096695627f5f (diff)
downloadlinux-d7256759f4683121d97f7aaf3287a308d562a69e.tar.gz
linux-d7256759f4683121d97f7aaf3287a308d562a69e.tar.bz2
linux-d7256759f4683121d97f7aaf3287a308d562a69e.zip
usb: gadget: Check bmAttributes only if configuration is valid
commit 8e812e9355a6f14dffd54a33d951ca403b9732f5 upstream. 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>
-rw-r--r--drivers/usb/gadget/composite.c2
1 files changed, 1 insertions, 1 deletions
diff --git a/drivers/usb/gadget/composite.c b/drivers/usb/gadget/composite.c
index daa42e5fe2e7..8adb54886443 100644
--- a/drivers/usb/gadget/composite.c
+++ b/drivers/usb/gadget/composite.c
@@ -916,7 +916,7 @@ static int set_config(struct usb_composite_dev *cdev,
power = min(power, 900U);
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);