Skip to content

Commit b7d4909

Browse files
novitollgregkh
authored andcommitted
drivers/usb/gadget: refactor min with min_t
Ensure type safety by using min_t() instead of casted min(). Signed-off-by: Sabyrzhan Tasbolatov <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 12bbabd commit b7d4909

File tree

8 files changed

+21
-21
lines changed

8 files changed

+21
-21
lines changed

drivers/usb/gadget/composite.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1844,7 +1844,7 @@ composite_setup(struct usb_gadget *gadget, const struct usb_ctrlrequest *ctrl)
18441844
cdev->desc.bcdUSB = cpu_to_le16(0x0200);
18451845
}
18461846

1847-
value = min(w_length, (u16) sizeof cdev->desc);
1847+
value = min_t(u16, w_length, sizeof(cdev->desc));
18481848
memcpy(req->buf, &cdev->desc, value);
18491849
break;
18501850
case USB_DT_DEVICE_QUALIFIER:
@@ -1863,19 +1863,19 @@ composite_setup(struct usb_gadget *gadget, const struct usb_ctrlrequest *ctrl)
18631863
case USB_DT_CONFIG:
18641864
value = config_desc(cdev, w_value);
18651865
if (value >= 0)
1866-
value = min(w_length, (u16) value);
1866+
value = min_t(u16, w_length, value);
18671867
break;
18681868
case USB_DT_STRING:
18691869
value = get_string(cdev, req->buf,
18701870
w_index, w_value & 0xff);
18711871
if (value >= 0)
1872-
value = min(w_length, (u16) value);
1872+
value = min_t(u16, w_length, value);
18731873
break;
18741874
case USB_DT_BOS:
18751875
if (gadget_is_superspeed(gadget) ||
18761876
gadget->lpm_capable || cdev->use_webusb) {
18771877
value = bos_desc(cdev);
1878-
value = min(w_length, (u16) value);
1878+
value = min_t(u16, w_length, value);
18791879
}
18801880
break;
18811881
case USB_DT_OTG:
@@ -1930,7 +1930,7 @@ composite_setup(struct usb_gadget *gadget, const struct usb_ctrlrequest *ctrl)
19301930
*(u8 *)req->buf = cdev->config->bConfigurationValue;
19311931
else
19321932
*(u8 *)req->buf = 0;
1933-
value = min(w_length, (u16) 1);
1933+
value = min_t(u16, w_length, 1);
19341934
break;
19351935

19361936
/* function drivers must handle get/set altsetting */
@@ -1976,7 +1976,7 @@ composite_setup(struct usb_gadget *gadget, const struct usb_ctrlrequest *ctrl)
19761976
if (value < 0)
19771977
break;
19781978
*((u8 *)req->buf) = value;
1979-
value = min(w_length, (u16) 1);
1979+
value = min_t(u16, w_length, 1);
19801980
break;
19811981
case USB_REQ_GET_STATUS:
19821982
if (gadget_is_otg(gadget) && gadget->hnp_polling_support &&

drivers/usb/gadget/configfs.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1184,7 +1184,7 @@ static ssize_t os_desc_qw_sign_store(struct config_item *item, const char *page,
11841184
struct gadget_info *gi = os_desc_item_to_gadget_info(item);
11851185
int res, l;
11861186

1187-
l = min((int)len, OS_STRING_QW_SIGN_LEN >> 1);
1187+
l = min_t(int, len, OS_STRING_QW_SIGN_LEN >> 1);
11881188
if (page[l - 1] == '\n')
11891189
--l;
11901190

drivers/usb/gadget/function/f_fs.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -456,7 +456,7 @@ static ssize_t ffs_ep0_write(struct file *file, const char __user *buf,
456456
}
457457

458458
/* FFS_SETUP_PENDING and not stall */
459-
len = min(len, (size_t)le16_to_cpu(ffs->ev.setup.wLength));
459+
len = min_t(size_t, len, le16_to_cpu(ffs->ev.setup.wLength));
460460

461461
spin_unlock_irq(&ffs->ev.waitq.lock);
462462

@@ -590,7 +590,7 @@ static ssize_t ffs_ep0_read(struct file *file, char __user *buf,
590590

591591
/* unlocks spinlock */
592592
return __ffs_ep0_read_events(ffs, buf,
593-
min(n, (size_t)ffs->ev.count));
593+
min_t(size_t, n, ffs->ev.count));
594594

595595
case FFS_SETUP_PENDING:
596596
if (ffs->ev.setup.bRequestType & USB_DIR_IN) {
@@ -599,7 +599,7 @@ static ssize_t ffs_ep0_read(struct file *file, char __user *buf,
599599
goto done_mutex;
600600
}
601601

602-
len = min(len, (size_t)le16_to_cpu(ffs->ev.setup.wLength));
602+
len = min_t(size_t, len, le16_to_cpu(ffs->ev.setup.wLength));
603603

604604
spin_unlock_irq(&ffs->ev.waitq.lock);
605605

drivers/usb/gadget/function/f_mass_storage.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -500,7 +500,7 @@ static int fsg_setup(struct usb_function *f,
500500
*(u8 *)req->buf = _fsg_common_get_max_lun(fsg->common);
501501

502502
/* Respond with data/status */
503-
req->length = min((u16)1, w_length);
503+
req->length = min_t(u16, 1, w_length);
504504
return ep0_queue(fsg->common);
505505
}
506506

@@ -655,7 +655,7 @@ static int do_read(struct fsg_common *common)
655655
* And don't try to read past the end of the file.
656656
*/
657657
amount = min(amount_left, FSG_BUFLEN);
658-
amount = min((loff_t)amount,
658+
amount = min_t(loff_t, amount,
659659
curlun->file_length - file_offset);
660660

661661
/* Wait for the next buffer to become available */
@@ -1005,7 +1005,7 @@ static int do_verify(struct fsg_common *common)
10051005
* And don't try to read past the end of the file.
10061006
*/
10071007
amount = min(amount_left, FSG_BUFLEN);
1008-
amount = min((loff_t)amount,
1008+
amount = min_t(loff_t, amount,
10091009
curlun->file_length - file_offset);
10101010
if (amount == 0) {
10111011
curlun->sense_data =
@@ -2167,7 +2167,7 @@ static int do_scsi_command(struct fsg_common *common)
21672167
if (reply == -EINVAL)
21682168
reply = 0; /* Error reply length */
21692169
if (reply >= 0 && common->data_dir == DATA_DIR_TO_HOST) {
2170-
reply = min((u32)reply, common->data_size_from_cmnd);
2170+
reply = min_t(u32, reply, common->data_size_from_cmnd);
21712171
bh->inreq->length = reply;
21722172
bh->state = BUF_STATE_FULL;
21732173
common->residue -= reply;

drivers/usb/gadget/function/uvc_video.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ uvc_video_encode_data(struct uvc_video *video, struct uvc_buffer *buf,
7979

8080
/* Copy video data to the USB buffer. */
8181
mem = buf->mem + queue->buf_used;
82-
nbytes = min((unsigned int)len, buf->bytesused - queue->buf_used);
82+
nbytes = min_t(unsigned int, len, buf->bytesused - queue->buf_used);
8383

8484
memcpy(data, mem, nbytes);
8585
queue->buf_used += nbytes;
@@ -105,7 +105,7 @@ uvc_video_encode_bulk(struct usb_request *req, struct uvc_video *video,
105105
}
106106

107107
/* Process video data. */
108-
len = min((int)(video->max_payload_size - video->payload_size), len);
108+
len = min_t(int, video->max_payload_size - video->payload_size, len);
109109
ret = uvc_video_encode_data(video, buf, mem, len);
110110

111111
video->payload_size += ret;

drivers/usb/gadget/legacy/raw_gadget.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -782,7 +782,7 @@ static int raw_ioctl_ep0_read(struct raw_dev *dev, unsigned long value)
782782
if (ret < 0)
783783
goto free;
784784

785-
length = min(io.length, (unsigned int)ret);
785+
length = min_t(unsigned int, io.length, ret);
786786
if (copy_to_user((void __user *)(value + sizeof(io)), data, length))
787787
ret = -EFAULT;
788788
else
@@ -1168,7 +1168,7 @@ static int raw_ioctl_ep_read(struct raw_dev *dev, unsigned long value)
11681168
if (ret < 0)
11691169
goto free;
11701170

1171-
length = min(io.length, (unsigned int)ret);
1171+
length = min_t(unsigned int, io.length, ret);
11721172
if (copy_to_user((void __user *)(value + sizeof(io)), data, length))
11731173
ret = -EFAULT;
11741174
else

drivers/usb/gadget/udc/omap_udc.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -576,13 +576,13 @@ static void finish_in_dma(struct omap_ep *ep, struct omap_req *req, int status)
576576

577577
static void next_out_dma(struct omap_ep *ep, struct omap_req *req)
578578
{
579-
unsigned packets = req->req.length - req->req.actual;
579+
unsigned int packets = req->req.length - req->req.actual;
580580
int dma_trigger = 0;
581581
u16 w;
582582

583583
/* set up this DMA transfer, enable the fifo, start */
584584
packets /= ep->ep.maxpacket;
585-
packets = min(packets, (unsigned)UDC_RXN_TC + 1);
585+
packets = min_t(unsigned int, packets, UDC_RXN_TC + 1);
586586
req->dma_bytes = packets * ep->ep.maxpacket;
587587
omap_set_dma_transfer_params(ep->lch, OMAP_DMA_DATA_TYPE_S16,
588588
ep->ep.maxpacket >> 1, packets,

drivers/usb/gadget/usbstring.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ usb_gadget_get_string (const struct usb_gadget_strings *table, int id, u8 *buf)
5555
return -EINVAL;
5656

5757
/* string descriptors have length, tag, then UTF16-LE text */
58-
len = min((size_t)USB_MAX_STRING_LEN, strlen(s->s));
58+
len = min_t(size_t, USB_MAX_STRING_LEN, strlen(s->s));
5959
len = utf8s_to_utf16s(s->s, len, UTF16_LITTLE_ENDIAN,
6060
(wchar_t *) &buf[2], USB_MAX_STRING_LEN);
6161
if (len < 0)

0 commit comments

Comments
 (0)