Make the code slightly more appealing by making use of min(). There
shall not be any functional change from this patch.
Signed-off-by: Ricardo Ribalda <ribalda@chromium.org>
---
drivers/media/usb/uvc/uvc_video.c | 4 +---
1 file changed, 1 insertion(+), 3 deletions(-)
diff --git a/drivers/media/usb/uvc/uvc_video.c b/drivers/media/usb/uvc/uvc_video.c
index 59eb95a4b70c05b1a12986e908b7e9979b064fd0..db02080f15772e0bc1d5cfcadd32463f4e6ea045 100644
--- a/drivers/media/usb/uvc/uvc_video.c
+++ b/drivers/media/usb/uvc/uvc_video.c
@@ -1808,9 +1808,7 @@ static int uvc_alloc_urb_buffers(struct uvc_streaming *stream,
* Compute the number of packets. Bulk endpoints might transfer UVC
* payloads across multiple URBs.
*/
- npackets = DIV_ROUND_UP(size, psize);
- if (npackets > UVC_MAX_PACKETS)
- npackets = UVC_MAX_PACKETS;
+ npackets = min(UVC_MAX_PACKETS, DIV_ROUND_UP(size, psize));
/* Retry allocations until one succeed. */
for (; npackets > 0; npackets /= 2) {
--
2.52.0.457.g6b5491de43-goog
Hi Ricardo,
Thank you for the patch.
On Wed, Jan 14, 2026 at 10:32:15AM +0000, Ricardo Ribalda wrote:
> Make the code slightly more appealing by making use of min(). There
> shall not be any functional change from this patch.
>
> Signed-off-by: Ricardo Ribalda <ribalda@chromium.org>
> ---
> drivers/media/usb/uvc/uvc_video.c | 4 +---
> 1 file changed, 1 insertion(+), 3 deletions(-)
>
> diff --git a/drivers/media/usb/uvc/uvc_video.c b/drivers/media/usb/uvc/uvc_video.c
> index 59eb95a4b70c05b1a12986e908b7e9979b064fd0..db02080f15772e0bc1d5cfcadd32463f4e6ea045 100644
> --- a/drivers/media/usb/uvc/uvc_video.c
> +++ b/drivers/media/usb/uvc/uvc_video.c
> @@ -1808,9 +1808,7 @@ static int uvc_alloc_urb_buffers(struct uvc_streaming *stream,
> * Compute the number of packets. Bulk endpoints might transfer UVC
> * payloads across multiple URBs.
> */
> - npackets = DIV_ROUND_UP(size, psize);
> - if (npackets > UVC_MAX_PACKETS)
> - npackets = UVC_MAX_PACKETS;
> + npackets = min(UVC_MAX_PACKETS, DIV_ROUND_UP(size, psize));
Do you think this improves readability ? I find the existing code easier
to read, its purpose is immediately clear: it computes npackets and
clamps it to a max value. With min() I have to pause and think.
I'll take patches 1/3 and 2/3 in my tree already as 1/3 fixes an issue.
>
> /* Retry allocations until one succeed. */
> for (; npackets > 0; npackets /= 2) {
--
Regards,
Laurent Pinchart
Hi Laurent
On Thu, 22 Jan 2026 at 02:49, Laurent Pinchart
<laurent.pinchart@ideasonboard.com> wrote:
>
> Hi Ricardo,
>
> Thank you for the patch.
>
> On Wed, Jan 14, 2026 at 10:32:15AM +0000, Ricardo Ribalda wrote:
> > Make the code slightly more appealing by making use of min(). There
> > shall not be any functional change from this patch.
> >
> > Signed-off-by: Ricardo Ribalda <ribalda@chromium.org>
> > ---
> > drivers/media/usb/uvc/uvc_video.c | 4 +---
> > 1 file changed, 1 insertion(+), 3 deletions(-)
> >
> > diff --git a/drivers/media/usb/uvc/uvc_video.c b/drivers/media/usb/uvc/uvc_video.c
> > index 59eb95a4b70c05b1a12986e908b7e9979b064fd0..db02080f15772e0bc1d5cfcadd32463f4e6ea045 100644
> > --- a/drivers/media/usb/uvc/uvc_video.c
> > +++ b/drivers/media/usb/uvc/uvc_video.c
> > @@ -1808,9 +1808,7 @@ static int uvc_alloc_urb_buffers(struct uvc_streaming *stream,
> > * Compute the number of packets. Bulk endpoints might transfer UVC
> > * payloads across multiple URBs.
> > */
> > - npackets = DIV_ROUND_UP(size, psize);
> > - if (npackets > UVC_MAX_PACKETS)
> > - npackets = UVC_MAX_PACKETS;
> > + npackets = min(UVC_MAX_PACKETS, DIV_ROUND_UP(size, psize));
>
> Do you think this improves readability ? I find the existing code easier
> to read, its purpose is immediately clear: it computes npackets and
> clamps it to a max value. With min() I have to pause and think.
I guess it is a matter of taste. I left it as a separate patch for that reason.
>
> I'll take patches 1/3 and 2/3 in my tree already as 1/3 fixes an issue.
Thanks!
Regards!
>
> >
> > /* Retry allocations until one succeed. */
> > for (; npackets > 0; npackets /= 2) {
>
> --
> Regards,
>
> Laurent Pinchart
--
Ricardo Ribalda
© 2016 - 2026 Red Hat, Inc.