drivers/usb/gadget: refactor min with min_t

Ensure type safety by using min_t() instead of casted min().

Signed-off-by: Sabyrzhan Tasbolatov <snovitoll@gmail.com>
Link: https://lore.kernel.org/r/20241112155817.3512577-2-snovitoll@gmail.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
This commit is contained in:
Sabyrzhan Tasbolatov 2024-11-12 20:58:10 +05:00 committed by Greg Kroah-Hartman
parent 12bbabd3ca
commit b7d49096d5
8 changed files with 21 additions and 21 deletions

View file

@ -1844,7 +1844,7 @@ composite_setup(struct usb_gadget *gadget, const struct usb_ctrlrequest *ctrl)
cdev->desc.bcdUSB = cpu_to_le16(0x0200); cdev->desc.bcdUSB = cpu_to_le16(0x0200);
} }
value = min(w_length, (u16) sizeof cdev->desc); value = min_t(u16, w_length, sizeof(cdev->desc));
memcpy(req->buf, &cdev->desc, value); memcpy(req->buf, &cdev->desc, value);
break; break;
case USB_DT_DEVICE_QUALIFIER: case USB_DT_DEVICE_QUALIFIER:
@ -1863,19 +1863,19 @@ composite_setup(struct usb_gadget *gadget, const struct usb_ctrlrequest *ctrl)
case USB_DT_CONFIG: case USB_DT_CONFIG:
value = config_desc(cdev, w_value); value = config_desc(cdev, w_value);
if (value >= 0) if (value >= 0)
value = min(w_length, (u16) value); value = min_t(u16, w_length, value);
break; break;
case USB_DT_STRING: case USB_DT_STRING:
value = get_string(cdev, req->buf, value = get_string(cdev, req->buf,
w_index, w_value & 0xff); w_index, w_value & 0xff);
if (value >= 0) if (value >= 0)
value = min(w_length, (u16) value); value = min_t(u16, w_length, value);
break; break;
case USB_DT_BOS: case USB_DT_BOS:
if (gadget_is_superspeed(gadget) || if (gadget_is_superspeed(gadget) ||
gadget->lpm_capable || cdev->use_webusb) { gadget->lpm_capable || cdev->use_webusb) {
value = bos_desc(cdev); value = bos_desc(cdev);
value = min(w_length, (u16) value); value = min_t(u16, w_length, value);
} }
break; break;
case USB_DT_OTG: case USB_DT_OTG:
@ -1930,7 +1930,7 @@ composite_setup(struct usb_gadget *gadget, const struct usb_ctrlrequest *ctrl)
*(u8 *)req->buf = cdev->config->bConfigurationValue; *(u8 *)req->buf = cdev->config->bConfigurationValue;
else else
*(u8 *)req->buf = 0; *(u8 *)req->buf = 0;
value = min(w_length, (u16) 1); value = min_t(u16, w_length, 1);
break; break;
/* function drivers must handle get/set altsetting */ /* function drivers must handle get/set altsetting */
@ -1976,7 +1976,7 @@ composite_setup(struct usb_gadget *gadget, const struct usb_ctrlrequest *ctrl)
if (value < 0) if (value < 0)
break; break;
*((u8 *)req->buf) = value; *((u8 *)req->buf) = value;
value = min(w_length, (u16) 1); value = min_t(u16, w_length, 1);
break; break;
case USB_REQ_GET_STATUS: case USB_REQ_GET_STATUS:
if (gadget_is_otg(gadget) && gadget->hnp_polling_support && if (gadget_is_otg(gadget) && gadget->hnp_polling_support &&

View file

@ -1184,7 +1184,7 @@ static ssize_t os_desc_qw_sign_store(struct config_item *item, const char *page,
struct gadget_info *gi = os_desc_item_to_gadget_info(item); struct gadget_info *gi = os_desc_item_to_gadget_info(item);
int res, l; int res, l;
l = min((int)len, OS_STRING_QW_SIGN_LEN >> 1); l = min_t(int, len, OS_STRING_QW_SIGN_LEN >> 1);
if (page[l - 1] == '\n') if (page[l - 1] == '\n')
--l; --l;

View file

@ -456,7 +456,7 @@ static ssize_t ffs_ep0_write(struct file *file, const char __user *buf,
} }
/* FFS_SETUP_PENDING and not stall */ /* FFS_SETUP_PENDING and not stall */
len = min(len, (size_t)le16_to_cpu(ffs->ev.setup.wLength)); len = min_t(size_t, len, le16_to_cpu(ffs->ev.setup.wLength));
spin_unlock_irq(&ffs->ev.waitq.lock); spin_unlock_irq(&ffs->ev.waitq.lock);
@ -590,7 +590,7 @@ static ssize_t ffs_ep0_read(struct file *file, char __user *buf,
/* unlocks spinlock */ /* unlocks spinlock */
return __ffs_ep0_read_events(ffs, buf, return __ffs_ep0_read_events(ffs, buf,
min(n, (size_t)ffs->ev.count)); min_t(size_t, n, ffs->ev.count));
case FFS_SETUP_PENDING: case FFS_SETUP_PENDING:
if (ffs->ev.setup.bRequestType & USB_DIR_IN) { if (ffs->ev.setup.bRequestType & USB_DIR_IN) {
@ -599,7 +599,7 @@ static ssize_t ffs_ep0_read(struct file *file, char __user *buf,
goto done_mutex; goto done_mutex;
} }
len = min(len, (size_t)le16_to_cpu(ffs->ev.setup.wLength)); len = min_t(size_t, len, le16_to_cpu(ffs->ev.setup.wLength));
spin_unlock_irq(&ffs->ev.waitq.lock); spin_unlock_irq(&ffs->ev.waitq.lock);

View file

@ -500,7 +500,7 @@ static int fsg_setup(struct usb_function *f,
*(u8 *)req->buf = _fsg_common_get_max_lun(fsg->common); *(u8 *)req->buf = _fsg_common_get_max_lun(fsg->common);
/* Respond with data/status */ /* Respond with data/status */
req->length = min((u16)1, w_length); req->length = min_t(u16, 1, w_length);
return ep0_queue(fsg->common); return ep0_queue(fsg->common);
} }
@ -655,7 +655,7 @@ static int do_read(struct fsg_common *common)
* And don't try to read past the end of the file. * And don't try to read past the end of the file.
*/ */
amount = min(amount_left, FSG_BUFLEN); amount = min(amount_left, FSG_BUFLEN);
amount = min((loff_t)amount, amount = min_t(loff_t, amount,
curlun->file_length - file_offset); curlun->file_length - file_offset);
/* Wait for the next buffer to become available */ /* Wait for the next buffer to become available */
@ -1005,7 +1005,7 @@ static int do_verify(struct fsg_common *common)
* And don't try to read past the end of the file. * And don't try to read past the end of the file.
*/ */
amount = min(amount_left, FSG_BUFLEN); amount = min(amount_left, FSG_BUFLEN);
amount = min((loff_t)amount, amount = min_t(loff_t, amount,
curlun->file_length - file_offset); curlun->file_length - file_offset);
if (amount == 0) { if (amount == 0) {
curlun->sense_data = curlun->sense_data =
@ -2167,7 +2167,7 @@ unknown_cmnd:
if (reply == -EINVAL) if (reply == -EINVAL)
reply = 0; /* Error reply length */ reply = 0; /* Error reply length */
if (reply >= 0 && common->data_dir == DATA_DIR_TO_HOST) { if (reply >= 0 && common->data_dir == DATA_DIR_TO_HOST) {
reply = min((u32)reply, common->data_size_from_cmnd); reply = min_t(u32, reply, common->data_size_from_cmnd);
bh->inreq->length = reply; bh->inreq->length = reply;
bh->state = BUF_STATE_FULL; bh->state = BUF_STATE_FULL;
common->residue -= reply; common->residue -= reply;

View file

@ -79,7 +79,7 @@ uvc_video_encode_data(struct uvc_video *video, struct uvc_buffer *buf,
/* Copy video data to the USB buffer. */ /* Copy video data to the USB buffer. */
mem = buf->mem + queue->buf_used; mem = buf->mem + queue->buf_used;
nbytes = min((unsigned int)len, buf->bytesused - queue->buf_used); nbytes = min_t(unsigned int, len, buf->bytesused - queue->buf_used);
memcpy(data, mem, nbytes); memcpy(data, mem, nbytes);
queue->buf_used += nbytes; queue->buf_used += nbytes;
@ -105,7 +105,7 @@ uvc_video_encode_bulk(struct usb_request *req, struct uvc_video *video,
} }
/* Process video data. */ /* Process video data. */
len = min((int)(video->max_payload_size - video->payload_size), len); len = min_t(int, video->max_payload_size - video->payload_size, len);
ret = uvc_video_encode_data(video, buf, mem, len); ret = uvc_video_encode_data(video, buf, mem, len);
video->payload_size += ret; video->payload_size += ret;

View file

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

View file

@ -576,13 +576,13 @@ static void finish_in_dma(struct omap_ep *ep, struct omap_req *req, int status)
static void next_out_dma(struct omap_ep *ep, struct omap_req *req) static void next_out_dma(struct omap_ep *ep, struct omap_req *req)
{ {
unsigned packets = req->req.length - req->req.actual; unsigned int packets = req->req.length - req->req.actual;
int dma_trigger = 0; int dma_trigger = 0;
u16 w; u16 w;
/* set up this DMA transfer, enable the fifo, start */ /* set up this DMA transfer, enable the fifo, start */
packets /= ep->ep.maxpacket; packets /= ep->ep.maxpacket;
packets = min(packets, (unsigned)UDC_RXN_TC + 1); packets = min_t(unsigned int, packets, UDC_RXN_TC + 1);
req->dma_bytes = packets * ep->ep.maxpacket; req->dma_bytes = packets * ep->ep.maxpacket;
omap_set_dma_transfer_params(ep->lch, OMAP_DMA_DATA_TYPE_S16, omap_set_dma_transfer_params(ep->lch, OMAP_DMA_DATA_TYPE_S16,
ep->ep.maxpacket >> 1, packets, ep->ep.maxpacket >> 1, packets,

View file

@ -55,7 +55,7 @@ usb_gadget_get_string (const struct usb_gadget_strings *table, int id, u8 *buf)
return -EINVAL; return -EINVAL;
/* string descriptors have length, tag, then UTF16-LE text */ /* string descriptors have length, tag, then UTF16-LE text */
len = min((size_t)USB_MAX_STRING_LEN, strlen(s->s)); len = min_t(size_t, USB_MAX_STRING_LEN, strlen(s->s));
len = utf8s_to_utf16s(s->s, len, UTF16_LITTLE_ENDIAN, len = utf8s_to_utf16s(s->s, len, UTF16_LITTLE_ENDIAN,
(wchar_t *) &buf[2], USB_MAX_STRING_LEN); (wchar_t *) &buf[2], USB_MAX_STRING_LEN);
if (len < 0) if (len < 0)