usb: musb: ux500: harden checks for platform data
authorLee Jones <lee.jones@linaro.org>
Wed, 15 May 2013 09:51:46 +0000 (10:51 +0100)
committerLinus Walleij <linus.walleij@linaro.org>
Tue, 4 Jun 2013 09:12:04 +0000 (11:12 +0200)
In its current state, the ux500-musb driver uses platform data pointers
blindly with no prior checking. If no platform data pointer is passed
this will Oops the kernel. In this patch we ensure platform data and
board data are present prior to using them.

Cc: linux-usb@vger.kernel.org
Acked-by: Felipe Balbi <balbi@ti.com>
Acked-by: Fabio Baltieri <fabio.baltieri@linaro.org>
Signed-off-by: Lee Jones <lee.jones@linaro.org>
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
drivers/usb/musb/ux500_dma.c

index 382291b91f7b6fe75368a1344a45182dee8a626e..4bd5400e0395a863b83a22a63f4c066a50593868 100644 (file)
@@ -289,7 +289,7 @@ static int ux500_dma_controller_start(struct dma_controller *c)
        struct musb *musb = controller->private_data;
        struct device *dev = musb->controller;
        struct musb_hdrc_platform_data *plat = dev->platform_data;
-       struct ux500_musb_board_data *data = plat->board_data;
+       struct ux500_musb_board_data *data;
        struct dma_channel *dma_channel = NULL;
        u32 ch_num;
        u8 dir;
@@ -299,14 +299,19 @@ static int ux500_dma_controller_start(struct dma_controller *c)
        struct ux500_dma_channel *channel_array;
        dma_cap_mask_t mask;
 
+       if (!plat) {
+               dev_err(musb->controller, "No platform data\n");
+               return -EINVAL;
+       }
 
+       data = plat->board_data;
 
        dma_cap_zero(mask);
        dma_cap_set(DMA_SLAVE, mask);
 
        /* Prepare the loop for RX channels */
        channel_array = controller->rx_channel;
-       param_array = data->dma_rx_param_array;
+       param_array = data ? data->dma_rx_param_array : NULL;
 
        for (dir = 0; dir < 2; dir++) {
                for (ch_num = 0;
@@ -339,7 +344,7 @@ static int ux500_dma_controller_start(struct dma_controller *c)
 
                /* Prepare the loop for TX channels */
                channel_array = controller->tx_channel;
-               param_array = data->dma_tx_param_array;
+               param_array = data ? data->dma_tx_param_array : NULL;
                is_tx = 1;
        }