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

usb: misc: usbsevseg: update to use usb_control_msg_send()

The newer usb_control_msg_{send|recv}() API ensures that a short read is
treated as an error, data can be used off the stack, and raw usb pipes
need not be created in the calling functions.
For this reason, instances of usb_control_msg() have been replaced with
usb_control_msg_send() appropriately.

Signed-off-by: Anant Thazhemadam <anant.thazhemadam@gmail.com>
Link: https://lore.kernel.org/r/20210326223251.753952-4-anant.thazhemadam@gmail.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

authored by

Anant Thazhemadam and committed by
Greg Kroah-Hartman
38833cbd ced6a0ba

+17 -43
+17 -43
drivers/usb/misc/usbsevseg.c
··· 74 74 if (mydev->shadow_power != 1) 75 75 return; 76 76 77 - rc = usb_control_msg(mydev->udev, 78 - usb_sndctrlpipe(mydev->udev, 0), 79 - 0x12, 80 - 0x48, 81 - (80 * 0x100) + 10, /* (power mode) */ 82 - (0x00 * 0x100) + (mydev->powered ? 1 : 0), 83 - NULL, 84 - 0, 85 - 2000); 77 + rc = usb_control_msg_send(mydev->udev, 0, 0x12, 0x48, 78 + (80 * 0x100) + 10, /* (power mode) */ 79 + (0x00 * 0x100) + (mydev->powered ? 1 : 0), 80 + NULL, 0, 2000, GFP_KERNEL); 86 81 if (rc < 0) 87 82 dev_dbg(&mydev->udev->dev, "power retval = %d\n", rc); 88 83 ··· 94 99 if(mydev->shadow_power != 1) 95 100 return; 96 101 97 - rc = usb_control_msg(mydev->udev, 98 - usb_sndctrlpipe(mydev->udev, 0), 99 - 0x12, 100 - 0x48, 101 - (82 * 0x100) + 10, /* (set mode) */ 102 - (mydev->mode_msb * 0x100) + mydev->mode_lsb, 103 - NULL, 104 - 0, 105 - 2000); 102 + rc = usb_control_msg_send(mydev->udev, 0, 0x12, 0x48, 103 + (82 * 0x100) + 10, /* (set mode) */ 104 + (mydev->mode_msb * 0x100) + mydev->mode_lsb, 105 + NULL, 0, 2000, GFP_NOIO); 106 106 107 107 if (rc < 0) 108 108 dev_dbg(&mydev->udev->dev, "mode retval = %d\n", rc); ··· 107 117 { 108 118 int rc; 109 119 int i; 110 - unsigned char *buffer; 120 + unsigned char buffer[MAXLEN] = {0}; 111 121 u8 decimals = 0; 112 122 113 123 if(mydev->shadow_power != 1) 114 - return; 115 - 116 - buffer = kzalloc(MAXLEN, mf); 117 - if (!buffer) 118 124 return; 119 125 120 126 /* The device is right to left, where as you write left to right */ 121 127 for (i = 0; i < mydev->textlength; i++) 122 128 buffer[i] = mydev->text[mydev->textlength-1-i]; 123 129 124 - rc = usb_control_msg(mydev->udev, 125 - usb_sndctrlpipe(mydev->udev, 0), 126 - 0x12, 127 - 0x48, 128 - (85 * 0x100) + 10, /* (write text) */ 129 - (0 * 0x100) + mydev->textmode, /* mode */ 130 - buffer, 131 - mydev->textlength, 132 - 2000); 130 + rc = usb_control_msg_send(mydev->udev, 0, 0x12, 0x48, 131 + (85 * 0x100) + 10, /* (write text) */ 132 + (0 * 0x100) + mydev->textmode, /* mode */ 133 + &buffer, mydev->textlength, 2000, mf); 133 134 134 135 if (rc < 0) 135 136 dev_dbg(&mydev->udev->dev, "write retval = %d\n", rc); 136 - 137 - kfree(buffer); 138 137 139 138 /* The device is right to left, where as you write left to right */ 140 139 for (i = 0; i < sizeof(mydev->decimals); i++) 141 140 decimals |= mydev->decimals[i] << i; 142 141 143 - rc = usb_control_msg(mydev->udev, 144 - usb_sndctrlpipe(mydev->udev, 0), 145 - 0x12, 146 - 0x48, 147 - (86 * 0x100) + 10, /* (set decimal) */ 148 - (0 * 0x100) + decimals, /* decimals */ 149 - NULL, 150 - 0, 151 - 2000); 142 + rc = usb_control_msg_send(mydev->udev, 0, 0x12, 0x48, 143 + (86 * 0x100) + 10, /* (set decimal) */ 144 + (0 * 0x100) + decimals, /* decimals */ 145 + NULL, 0, 2000, mf); 152 146 153 147 if (rc < 0) 154 148 dev_dbg(&mydev->udev->dev, "decimal retval = %d\n", rc);