Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

usb: gadget: uvc: Fix ERR_PTR dereference in uvc_v4l2.c

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()

Also, fix similar issue in uvc_v4l2_try_format() for potential
dereferencing of ERR_PTR().

Signed-off-by: Abhishek Tamboli <abhishektamboli9@gmail.com>
Link: https://lore.kernel.org/r/20240815102202.594812-1-abhishektamboli9@gmail.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

authored by

Abhishek Tamboli and committed by
Greg Kroah-Hartman
a7bb96b1 8557ef3f

+11 -1
+11 -1
drivers/usb/gadget/function/uvc_v4l2.c
··· 121 121 list_for_each_entry(format, &uvc->header->formats, entry) { 122 122 const struct uvc_format_desc *fmtdesc = to_uvc_format(format->fmt); 123 123 124 + if (IS_ERR(fmtdesc)) 125 + continue; 126 + 124 127 if (fmtdesc->fcc == pixelformat) { 125 128 uformat = format->fmt; 126 129 break; ··· 243 240 struct uvc_video *video = &uvc->video; 244 241 struct uvcg_format *uformat; 245 242 struct uvcg_frame *uframe; 243 + const struct uvc_format_desc *fmtdesc; 246 244 u8 *fcc; 247 245 248 246 if (fmt->type != video->queue.queue.type) ··· 281 277 fmt->fmt.pix.height = uframe->frame.w_height; 282 278 fmt->fmt.pix.bytesperline = uvc_v4l2_get_bytesperline(uformat, uframe); 283 279 fmt->fmt.pix.sizeimage = uvc_get_frame_size(uformat, uframe); 284 - fmt->fmt.pix.pixelformat = to_uvc_format(uformat)->fcc; 280 + fmtdesc = to_uvc_format(uformat); 281 + if (IS_ERR(fmtdesc)) 282 + return PTR_ERR(fmtdesc); 283 + fmt->fmt.pix.pixelformat = fmtdesc->fcc; 285 284 } 286 285 fmt->fmt.pix.field = V4L2_FIELD_NONE; 287 286 fmt->fmt.pix.colorspace = V4L2_COLORSPACE_SRGB; ··· 396 389 return -EINVAL; 397 390 398 391 fmtdesc = to_uvc_format(uformat); 392 + if (IS_ERR(fmtdesc)) 393 + return PTR_ERR(fmtdesc); 394 + 399 395 f->pixelformat = fmtdesc->fcc; 400 396 401 397 return 0;