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

watchdog: pcwd_usb: Use allocated buffer for usb_control_msg

usb_control_msg() must use a dma-capable buffer.

This fixes the following error reported by smatch:

drivers/watchdog/pcwd_usb.c:257 usb_pcwd_send_command() error: doing dma on the
stack (buf)

Signed-off-by: Guenter Roeck <linux@roeck-us.net>
Acked-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Wim Van Sebroeck <wim@iguana.be>

authored by

Guenter Roeck and committed by
Wim Van Sebroeck
5412df0b b1f9cd32

+7 -1
+7 -1
drivers/watchdog/pcwd_usb.c
··· 235 235 unsigned char cmd, unsigned char *msb, unsigned char *lsb) 236 236 { 237 237 int got_response, count; 238 - unsigned char buf[6]; 238 + unsigned char *buf; 239 239 240 240 /* We will not send any commands if the USB PCWD device does 241 241 * not exist */ 242 242 if ((!usb_pcwd) || (!usb_pcwd->exists)) 243 243 return -1; 244 + 245 + buf = kmalloc(6, GFP_KERNEL); 246 + if (buf == NULL) 247 + return 0; 244 248 245 249 /* The USB PC Watchdog uses a 6 byte report format. 246 250 * The board currently uses only 3 of the six bytes of the report. */ ··· 280 276 *msb = usb_pcwd->cmd_data_msb; 281 277 *lsb = usb_pcwd->cmd_data_lsb; 282 278 } 279 + 280 + kfree(buf); 283 281 284 282 return got_response; 285 283 }