public inbox for linux-kernel-mentees@lists.linux-foundation.org
 help / color / mirror / Atom feed
* [PATCH] usb: gadget: uvc: Fix ERR_PTR dereference in uvc_v4l2.c
@ 2024-08-02 18:02 Abhishek Tamboli
  2024-08-02 18:18 ` Laurent Pinchart
                   ` (2 more replies)
  0 siblings, 3 replies; 8+ messages in thread
From: Abhishek Tamboli @ 2024-08-02 18:02 UTC (permalink / raw)
  To: laurent.pinchart, dan.scally
  Cc: gregkh, skhan, dan.carpenter, rbmarliere, linux-kernel-mentees,
	linux-usb, linux-kernel

Fix potential dereferencing of ERR_PTR() in find_format_by_pix()
and uvc_v4l2_enum_format().

Fix the following smatch errors:

drivers/usb/gadget/function/uvc_v4l2.c:124 find_format_by_pix()
error: 'fmtdesc' dereferencing possible ERR_PTR()
drivers/usb/gadget/function/uvc_v4l2.c:392 uvc_v4l2_enum_format()
error: 'fmtdesc' dereferencing possible ERR_PTR()

Signed-off-by: Abhishek Tamboli <abhishektamboli9@gmail.com>
---
 drivers/usb/gadget/function/uvc_v4l2.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/drivers/usb/gadget/function/uvc_v4l2.c b/drivers/usb/gadget/function/uvc_v4l2.c
index a024aecb76dc..9dd602a742c4 100644
--- a/drivers/usb/gadget/function/uvc_v4l2.c
+++ b/drivers/usb/gadget/function/uvc_v4l2.c
@@ -121,6 +121,9 @@ static struct uvcg_format *find_format_by_pix(struct uvc_device *uvc,
 	list_for_each_entry(format, &uvc->header->formats, entry) {
 		const struct uvc_format_desc *fmtdesc = to_uvc_format(format->fmt);

+		if (IS_ERR(fmtdesc))
+			continue;
+
 		if (fmtdesc->fcc == pixelformat) {
 			uformat = format->fmt;
 			break;
@@ -389,6 +392,9 @@ uvc_v4l2_enum_format(struct file *file, void *fh, struct v4l2_fmtdesc *f)
 		return -EINVAL;

 	fmtdesc = to_uvc_format(uformat);
+	if (IS_ERR(fmtdesc))
+		return -EINVAL;
+
 	f->pixelformat = fmtdesc->fcc;

 	return 0;
--
2.34.1


^ permalink raw reply related	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2024-08-13 16:17 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-08-02 18:02 [PATCH] usb: gadget: uvc: Fix ERR_PTR dereference in uvc_v4l2.c Abhishek Tamboli
2024-08-02 18:18 ` Laurent Pinchart
2024-08-08 20:51   ` Michael Grzeschik
2024-08-02 18:40 ` Dan Carpenter
2024-08-08 15:19   ` Abhishek Tamboli
2024-08-08 15:25   ` Abhishek Tamboli
2024-08-13  8:11 ` Greg KH
2024-08-13 16:15   ` Abhishek Tamboli

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox