From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A6AF8256C84; Wed, 25 Feb 2026 01:45:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1771983958; cv=none; b=qu6GN6L/Z2QAM24mkJCeFjWzTdLJcGyh0AvEcK/YXxMbTxRinLnc0LJImF3gVX+9nfVgHId2VRkJptdUhIb1A2sO52y3VjgasENdo3yjNsVTio7oU5XWaXPXoTq7314zI/5AmLQgShZ2fpTJnPgCdWcg2PLekNniYuXPu5Qq/WQ= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1771983958; c=relaxed/simple; bh=a8Sghkp2A5Zobs0QhKOBdWCrGp+QoVzbAM7dH/+8x/g=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=GcHcNKoHjwiC7vUKCAP0OjaaOnZXKCrusN3AxqcoTI1/PTL3bPH/lLZ3J0+ejqnGB/rx6kcBk8okt1YKT0fOZVJDcJygraNZutiY4ZetyO/zRy67i39qCGMmNoP4MrP0DJkd9wpSS7UbxFVvl06BozOnRjfxIFPHgedP8bq9LUo= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=P5V8mQ4Z; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="P5V8mQ4Z" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 67AA2C116D0; Wed, 25 Feb 2026 01:45:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1771983958; bh=a8Sghkp2A5Zobs0QhKOBdWCrGp+QoVzbAM7dH/+8x/g=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=P5V8mQ4ZAqOg4V9bwO+e/ZL6VafSWPMZ25M9IMb3S5VN8UxpS+XFYrx68TFmUmlsK 3RHgxbbGvrwuCDmEJex15JOYRynr/ZG+mFCzzNWtqjjv8ITMUsr8LdxBo62APb5N6v eA+v5hVBZCUWH8CbEztWyISO0uqPokDaNDKHGSBs= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Itay Chamiel , Ricardo Ribalda , Laurent Pinchart , Hans Verkuil , Sasha Levin Subject: [PATCH 6.18 216/641] media: uvcvideo: Fix allocation for small frame sizes Date: Tue, 24 Feb 2026 17:19:02 -0800 Message-ID: <20260225012354.167753484@linuxfoundation.org> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260225012348.915798704@linuxfoundation.org> References: <20260225012348.915798704@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: stable@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.18-stable review patch. If anyone has any objections, please let me know. ------------------ From: Ricardo Ribalda [ Upstream commit 40d3ac25c11310bfaa50ed7614846ef75cb69a1e ] If a frame has size of less or equal than one packet size uvc_alloc_urb_buffers() is unable to allocate memory for it due to a off-by-one error. Fix the off-by-one-error and now that we are at it, make sure that stream->urb_size has always a valid value when we return from the function, even when an error happens. Fixes: efdc8a9585ce ("V4L/DVB (10295): uvcvideo: Retry URB buffers allocation when the system is low on memory.") Reported-by: Itay Chamiel Closes: https://lore.kernel.org/linux-media/CANiDSCsSoZf2LsCCoWAUbCg6tJT-ypXR1B85aa6rAdMVYr2iBQ@mail.gmail.com/T/#t Co-developed-by: Itay Chamiel Signed-off-by: Itay Chamiel Signed-off-by: Ricardo Ribalda Reviewed-by: Laurent Pinchart Tested-by: Itay Chamiel Link: https://patch.msgid.link/20260114-uvc-alloc-urb-v1-1-cedf3fb66711@chromium.org Signed-off-by: Laurent Pinchart Signed-off-by: Hans Verkuil Signed-off-by: Sasha Levin --- drivers/media/usb/uvc/uvc_video.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/media/usb/uvc/uvc_video.c b/drivers/media/usb/uvc/uvc_video.c index 2094e059d7d39..ec76595f3c4be 100644 --- a/drivers/media/usb/uvc/uvc_video.c +++ b/drivers/media/usb/uvc/uvc_video.c @@ -1812,7 +1812,7 @@ static int uvc_alloc_urb_buffers(struct uvc_streaming *stream, npackets = UVC_MAX_PACKETS; /* Retry allocations until one succeed. */ - for (; npackets > 1; npackets /= 2) { + for (; npackets > 0; npackets /= 2) { stream->urb_size = psize * npackets; for (i = 0; i < UVC_URBS; ++i) { @@ -1837,6 +1837,7 @@ 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 = 0; return 0; } -- 2.51.0