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

USB: usblp: fix DMA to stack

Stack-allocated buffers cannot be used for DMA (on all architectures).

Replace the HP-channel macro with a helper function that allocates a
dedicated transfer buffer so that it can continue to be used with
arguments from the stack.

Note that the buffer is cleared on allocation as usblp_ctrl_msg()
returns success also on short transfers (the buffer is only used for
debugging).

Cc: stable@vger.kernel.org
Signed-off-by: Johan Hovold <johan@kernel.org>
Link: https://lore.kernel.org/r/20210104145302.2087-1-johan@kernel.org
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

authored by

Johan Hovold and committed by
Greg Kroah-Hartman
020a1f45 c318840f

+19 -2
+19 -2
drivers/usb/class/usblp.c
··· 274 274 #define usblp_reset(usblp)\ 275 275 usblp_ctrl_msg(usblp, USBLP_REQ_RESET, USB_TYPE_CLASS, USB_DIR_OUT, USB_RECIP_OTHER, 0, NULL, 0) 276 276 277 - #define usblp_hp_channel_change_request(usblp, channel, buffer) \ 278 - usblp_ctrl_msg(usblp, USBLP_REQ_HP_CHANNEL_CHANGE_REQUEST, USB_TYPE_VENDOR, USB_DIR_IN, USB_RECIP_INTERFACE, channel, buffer, 1) 277 + static int usblp_hp_channel_change_request(struct usblp *usblp, int channel, u8 *new_channel) 278 + { 279 + u8 *buf; 280 + int ret; 281 + 282 + buf = kzalloc(1, GFP_KERNEL); 283 + if (!buf) 284 + return -ENOMEM; 285 + 286 + ret = usblp_ctrl_msg(usblp, USBLP_REQ_HP_CHANNEL_CHANGE_REQUEST, 287 + USB_TYPE_VENDOR, USB_DIR_IN, USB_RECIP_INTERFACE, 288 + channel, buf, 1); 289 + if (ret == 0) 290 + *new_channel = buf[0]; 291 + 292 + kfree(buf); 293 + 294 + return ret; 295 + } 279 296 280 297 /* 281 298 * See the description for usblp_select_alts() below for the usage