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

usb: musb: ux500: harden checks for platform data

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>

authored by

Lee Jones and committed by
Linus Walleij
5f6091a0 1e6eebb4

+8 -3
+8 -3
drivers/usb/musb/ux500_dma.c
··· 289 289 struct musb *musb = controller->private_data; 290 290 struct device *dev = musb->controller; 291 291 struct musb_hdrc_platform_data *plat = dev->platform_data; 292 - struct ux500_musb_board_data *data = plat->board_data; 292 + struct ux500_musb_board_data *data; 293 293 struct dma_channel *dma_channel = NULL; 294 294 u32 ch_num; 295 295 u8 dir; ··· 299 299 struct ux500_dma_channel *channel_array; 300 300 dma_cap_mask_t mask; 301 301 302 + if (!plat) { 303 + dev_err(musb->controller, "No platform data\n"); 304 + return -EINVAL; 305 + } 302 306 307 + data = plat->board_data; 303 308 304 309 dma_cap_zero(mask); 305 310 dma_cap_set(DMA_SLAVE, mask); 306 311 307 312 /* Prepare the loop for RX channels */ 308 313 channel_array = controller->rx_channel; 309 - param_array = data->dma_rx_param_array; 314 + param_array = data ? data->dma_rx_param_array : NULL; 310 315 311 316 for (dir = 0; dir < 2; dir++) { 312 317 for (ch_num = 0; ··· 344 339 345 340 /* Prepare the loop for TX channels */ 346 341 channel_array = controller->tx_channel; 347 - param_array = data->dma_tx_param_array; 342 + param_array = data ? data->dma_tx_param_array : NULL; 348 343 is_tx = 1; 349 344 } 350 345