Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

USB: fsl_qe_udc: Check for muram allocation errors

The QE UDC doesn't check for cpm_muram_alloc() return values, this
might cause all sorts of misbehaviour when cpm_muram_alloc() failed
to allocate the muram memory.

While at at, change few dev_dbg() calls to dev_err(), so that the
driver would not die silently.

Signed-off-by: Anton Vorontsov <avorontsov@ru.mvista.com>
Cc: David Brownell <dbrownell@users.sourceforge.net>
Cc: Kumar Gala <galak@kernel.crashing.org>
Cc: Li Yang <leoli@freescale.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>

authored by

Anton Vorontsov and committed by
Greg Kroah-Hartman
cd40c4c4 011b15df

+9 -3
+9 -3
drivers/usb/gadget/fsl_qe_udc.c
··· 26 26 #include <linux/ioport.h> 27 27 #include <linux/types.h> 28 28 #include <linux/errno.h> 29 + #include <linux/err.h> 29 30 #include <linux/slab.h> 30 31 #include <linux/list.h> 31 32 #include <linux/interrupt.h> ··· 371 370 /* alloc multi-ram for BD rings and set the ep parameters */ 372 371 tmp_addr = cpm_muram_alloc(sizeof(struct qe_bd) * (bdring_len + 373 372 USB_BDRING_LEN_TX), QE_ALIGNMENT_OF_BD); 373 + if (IS_ERR_VALUE(tmp_addr)) 374 + return -ENOMEM; 375 + 374 376 out_be16(&epparam->rbase, (u16)tmp_addr); 375 377 out_be16(&epparam->tbase, (u16)(tmp_addr + 376 378 (sizeof(struct qe_bd) * bdring_len))); ··· 693 689 en_done1: 694 690 spin_unlock_irqrestore(&udc->lock, flags); 695 691 en_done: 696 - dev_dbg(udc->dev, "failed to initialize %s\n", ep->ep.name); 692 + dev_err(udc->dev, "failed to initialize %s\n", ep->ep.name); 697 693 return -ENODEV; 698 694 } 699 695 ··· 2412 2408 tmp_addr = cpm_muram_alloc((USB_MAX_ENDPOINTS * 2413 2409 sizeof(struct usb_ep_para)), 2414 2410 USB_EP_PARA_ALIGNMENT); 2411 + if (IS_ERR_VALUE(tmp_addr)) 2412 + goto cleanup; 2415 2413 2416 2414 for (i = 0; i < USB_MAX_ENDPOINTS; i++) { 2417 2415 out_be16(&usbpram->epptr[i], (u16)tmp_addr); ··· 2519 2513 /* Initialize the udc structure including QH member and other member */ 2520 2514 udc_controller = qe_udc_config(ofdev); 2521 2515 if (!udc_controller) { 2522 - dev_dbg(&ofdev->dev, "udc_controll is NULL\n"); 2516 + dev_err(&ofdev->dev, "failed to initialize\n"); 2523 2517 return -ENOMEM; 2524 2518 } 2525 2519 ··· 2574 2568 /* create a buf for ZLP send, need to remain zeroed */ 2575 2569 udc_controller->nullbuf = kzalloc(256, GFP_KERNEL); 2576 2570 if (udc_controller->nullbuf == NULL) { 2577 - dev_dbg(udc_controller->dev, "cannot alloc nullbuf\n"); 2571 + dev_err(udc_controller->dev, "cannot alloc nullbuf\n"); 2578 2572 ret = -ENOMEM; 2579 2573 goto err3; 2580 2574 }