Skip to content

Commit c336988

Browse files
Andrey Konovalovjb-essential
authored andcommitted
USB: core: only clean up what we allocated
When cleaning up the configurations, make sure we only free the number of configurations and interfaces that we could have allocated. Change-Id: I6f19c372f499b7becc39e31b9f80b17f6659ec81 Reported-by: Andrey Konovalov <andreyknvl@xxxxxxxxxx> Cc: stable <stable@xxxxxxxxxxxxxxx> Signed-off-by: Greg Kroah-Hartman <gregkh@xxxxxxxxxxxxxxxxxxx>
1 parent 66f4e9b commit c336988

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

drivers/usb/core/config.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -732,18 +732,21 @@ void usb_destroy_configuration(struct usb_device *dev)
732732
return;
733733

734734
if (dev->rawdescriptors) {
735-
for (i = 0; i < dev->descriptor.bNumConfigurations; i++)
735+
for (i = 0; i < dev->descriptor.bNumConfigurations &&
736+
i < USB_MAXCONFIG; i++)
736737
kfree(dev->rawdescriptors[i]);
737738

738739
kfree(dev->rawdescriptors);
739740
dev->rawdescriptors = NULL;
740741
}
741742

742-
for (c = 0; c < dev->descriptor.bNumConfigurations; c++) {
743+
for (c = 0; c < dev->descriptor.bNumConfigurations &&
744+
c < USB_MAXCONFIG; c++) {
743745
struct usb_host_config *cf = &dev->config[c];
744746

745747
kfree(cf->string);
746-
for (i = 0; i < cf->desc.bNumInterfaces; i++) {
748+
for (i = 0; i < cf->desc.bNumInterfaces &&
749+
i < USB_MAXINTERFACES; i++) {
747750
if (cf->intf_cache[i])
748751
kref_put(&cf->intf_cache[i]->ref,
749752
usb_release_interface_cache);

0 commit comments

Comments
 (0)