From nobody Mon Feb 9 14:14:54 2026 Received: from mail-lf1-f67.google.com (mail-lf1-f67.google.com [209.85.167.67]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id CB059342CB1 for ; Wed, 14 Jan 2026 10:32:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.67 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768386750; cv=none; b=ar6R36yxBLq/OUIwXvpOsilD/HKYmmsXnOpY7Qe2m6IP4WOKGPUHrtPiPhDQXi08YepmvAtJKFY2E++Kjye1mwpct8CAPAHGMJzvcyMcKNvIqfR1Pr70Z3fDFSKb29tEeAbomk4RaEKM02t1mW68rzR2lBjixj0NOkRD7b6uP1U= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768386750; c=relaxed/simple; bh=fLDCCM5+VCZGP7XXhipvWTv4MC0kLaeDD1P3yoqPOXc=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=c/kqZsyN/GF/2NlVVLhYBHxHFrlbRg0K3A5GUAQg8j7D3cTQw++ZRsYVV+8tNXlK838MM6v1Ssqn3VFs+k03kvCand+MoN3XMV3Cax3LKQ1G05d83yzUPeHi2X8g109v8D19rNvNB66UXxdDltM2awXSNUgSdQMfmYmiVOqKgTE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org; spf=pass smtp.mailfrom=chromium.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b=HINSe01x; arc=none smtp.client-ip=209.85.167.67 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=chromium.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="HINSe01x" Received: by mail-lf1-f67.google.com with SMTP id 2adb3069b0e04-59b6f59c4f5so9774685e87.3 for ; Wed, 14 Jan 2026 02:32:26 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1768386744; x=1768991544; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=hiAWrXH6x8EcXbUPmtbuPYc6WD9v4tNKnw7z9A4t3d0=; b=HINSe01xosE8PcxbLvhfhZ9sSg53ycT3mscygecOm1/ox5gsDU9fI3WjMp4EcATFWG 3gYYUKDzrIgvOHsxwXhkthTNWRuocmXHuXQcyAFtWJwwln+Ssufv9rs0IDu1fZMA6Ofd u3o+mOryX0CXImuF8jLJaYwWCZTMDYQ02K3wM= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1768386744; x=1768991544; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-gg:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to; bh=hiAWrXH6x8EcXbUPmtbuPYc6WD9v4tNKnw7z9A4t3d0=; b=UaGjuEtGEgTgh5Sm9sm2YlaNnP7LPNfv2mtE+byqE2NqRxahSkdjP754HFiYYWTT9C 3jsWsgNwVPnZJ/WEBOjfNyRmNWKAL1fhSJTlDHrWtkt63M5d7+XEiGapoWF5sxtV9sKf DxlFZ2ADPik48Qo3KvCjA2sIMJZTIFvsP2uthMFKOInz0k6NNBxlSoVrYXzAoIgEyofk 3N8dmsmv9uYodQcfKTYlzA2vDx0brPGa0lUIholsPIhiI0IXiRuPD3yY7osPtYYEO7tW BY1rLFwxI2jxdKFuH3+JE8SscCqUCUjbP9i0tjHMO4Z98WP88ir79fshF6qj9HrSrDNG Ih+Q== X-Forwarded-Encrypted: i=1; AJvYcCXFDGynzEtrR3YKS4RsaS4HPJoODj2EusvSLp40DbRPHiQJ1+p9gaW+8MMzoPCj6rFwWNp3f6KxxnFn4/Q=@vger.kernel.org X-Gm-Message-State: AOJu0Yx4ksdiPlL8sa5yLih5KmZo5I7e9dxQ8tVpp4M4cZdGfRRERty5 6M3UI4z+d4obPImQER1S1FNPJ0Jmco21DMKbvxsGgrL3K5ZOXFt0uhWc5jZZNqBtRw== X-Gm-Gg: AY/fxX4ZAaT9gTwqeTglQHy6HROeq8EP7ieo+nj2k8pxIp4zF1p893WUSEwNciri7xK a7DzqfBmRZId+qWBNUs6jmK2JAf09RXdvFCl8rN6aDaBYKcvLYo9fr2KLkktI3M8ZQpeJ3Na/jP xJQD56002GKzRfO+7E1QpeL1OJDffwnNB6+Um6hHZYzZMXNKsqzoxEWT7v/rMs4OUjENxZtr6V8 tVP59XDdye7paovFtC84ff3B8cqkiIwRanHmj8n18c2vXngftEn2zs0odJ/fxLGDc6ztrweAgst eap7BE3t3ZvnmkAR9SHRG3rNT/SsI3hyyJovN81iDI3wnwLqMo3S/h/FNXNQgebzmD0Ql3mMveU /WFVdZQY8oM1RowURoHHdfH3jHX6RgGG9mIJ53DEeOh9S0h/NzOOGwiutCsY0ahB92KG/b1OCaz qo/TaJN/2CZDPQh8HcRdgY9B9zDYDzQUaECssASYENR5PeSuvOfdeGtr64tycQNVo6hit0rw== X-Received: by 2002:a05:6512:10cd:b0:57a:2be1:d779 with SMTP id 2adb3069b0e04-59ba15502b6mr638673e87.31.1768386743782; Wed, 14 Jan 2026 02:32:23 -0800 (PST) Received: from ribalda.c.googlers.com (181.105.228.35.bc.googleusercontent.com. [35.228.105.181]) by smtp.gmail.com with ESMTPSA id 2adb3069b0e04-59ba10411e5sm573981e87.61.2026.01.14.02.32.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 14 Jan 2026 02:32:20 -0800 (PST) From: Ricardo Ribalda Date: Wed, 14 Jan 2026 10:32:14 +0000 Subject: [PATCH 2/3] media: uvcvideo: Pass allocation size directly to uvc_alloc_urb_buffer Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260114-uvc-alloc-urb-v1-2-cedf3fb66711@chromium.org> References: <20260114-uvc-alloc-urb-v1-0-cedf3fb66711@chromium.org> In-Reply-To: <20260114-uvc-alloc-urb-v1-0-cedf3fb66711@chromium.org> To: Laurent Pinchart , Hans de Goede , Mauro Carvalho Chehab , Johannes Berg Cc: Laurent Pinchart , linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, Ricardo Ribalda X-Mailer: b4 0.14.2 The uvc_alloc_urb_buffer() function implicitly depended on the stream->urb_size field, which was set by its caller, uvc_alloc_urb_buffers(). This implicit data flow makes the code harder to follow. More importantly, stream->urb_size was updated within the allocation loop before the allocation was confirmed to be successful. If the allocation failed, the stream object would be left with a urb_size that doesn't correspond to valid, allocated URB buffers. Refactor uvc_alloc_urb_buffer() to accept the buffer size as an explicit argument. This makes the function's dependencies clear and improves the robustness of the error handling path. The stream->urb_size is now set only after a complete and successful allocation. This is a pure refactoring and introduces no functional changes. Signed-off-by: Ricardo Ribalda Reviewed-by: Laurent Pinchart --- drivers/media/usb/uvc/uvc_video.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/drivers/media/usb/uvc/uvc_video.c b/drivers/media/usb/uvc/uvc_= video.c index ec76595f3c4be0f49b798ec663d6855d78ab21c4..59eb95a4b70c05b1a12986e908b= 7e9979b064fd0 100644 --- a/drivers/media/usb/uvc/uvc_video.c +++ b/drivers/media/usb/uvc/uvc_video.c @@ -1771,12 +1771,13 @@ static void uvc_free_urb_buffers(struct uvc_streami= ng *stream) } =20 static bool uvc_alloc_urb_buffer(struct uvc_streaming *stream, - struct uvc_urb *uvc_urb, gfp_t gfp_flags) + struct uvc_urb *uvc_urb, unsigned int size, + gfp_t gfp_flags) { struct usb_device *udev =3D stream->dev->udev; =20 - uvc_urb->buffer =3D usb_alloc_noncoherent(udev, stream->urb_size, - gfp_flags, &uvc_urb->dma, + uvc_urb->buffer =3D usb_alloc_noncoherent(udev, size, gfp_flags, + &uvc_urb->dma, uvc_stream_dir(stream), &uvc_urb->sgt); return !!uvc_urb->buffer; @@ -1813,12 +1814,13 @@ static int uvc_alloc_urb_buffers(struct uvc_streami= ng *stream, =20 /* Retry allocations until one succeed. */ for (; npackets > 0; npackets /=3D 2) { - stream->urb_size =3D psize * npackets; + unsigned int urb_size =3D psize * npackets; =20 for (i =3D 0; i < UVC_URBS; ++i) { struct uvc_urb *uvc_urb =3D &stream->uvc_urb[i]; =20 - if (!uvc_alloc_urb_buffer(stream, uvc_urb, gfp_flags)) { + if (!uvc_alloc_urb_buffer(stream, uvc_urb, urb_size, + gfp_flags)) { uvc_free_urb_buffers(stream); break; } @@ -1830,6 +1832,7 @@ static int uvc_alloc_urb_buffers(struct uvc_streaming= *stream, uvc_dbg(stream->dev, VIDEO, "Allocated %u URB buffers of %ux%u bytes each\n", UVC_URBS, npackets, psize); + stream->urb_size =3D urb_size; return npackets; } } @@ -1837,7 +1840,6 @@ static int uvc_alloc_urb_buffers(struct uvc_streaming= *stream, uvc_dbg(stream->dev, VIDEO, "Failed to allocate URB buffers (%u bytes per packet)\n", psize); - stream->urb_size =3D 0; return 0; } =20 --=20 2.52.0.457.g6b5491de43-goog