em28xx_v4l2_create_entities() dereferences a failed builtin decoder allocation. The release path also unregisters the decoder without checking for NULL. Skip the optional entity on allocation failure and guard its unregistration against NULL. Found by LLM-assisted static analysis. Build tested with allmodconfig; no runtime fault-injection test. Fixes: 8e53399c63c3 ("media: em28xx: Add support for Empia em2828X bridge") Cc: stable@vger.kernel.org Signed-off-by: Ziheng Wei --- drivers/media/usb/em28xx/em28xx-video.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/drivers/media/usb/em28xx/em28xx-video.c b/drivers/media/usb/em28xx/em28xx-video.c index 84424284d..bb258de0f 100644 --- a/drivers/media/usb/em28xx/em28xx-video.c +++ b/drivers/media/usb/em28xx/em28xx-video.c @@ -1018,7 +1018,7 @@ static void em28xx_v4l2_media_release(struct em28xx *dev) #ifdef CONFIG_MEDIA_CONTROLLER int i; - if (dev->board.decoder == EM28XX_BUILTIN) { + if (dev->board.decoder == EM28XX_BUILTIN && dev->v4l2->decoder) { media_device_unregister_entity(dev->v4l2->decoder); kfree(dev->v4l2->decoder); dev->v4l2->decoder = NULL; @@ -1170,6 +1170,9 @@ static void em28xx_v4l2_create_entities(struct em28xx *dev) v4l2->decoder_pads[EM2828X_PAD_VID_OUT].sig_type = PAD_SIGNAL_DV; v4l2->decoder = kzalloc_obj(*v4l2->decoder); + if (!v4l2->decoder) + return; + v4l2->decoder->name = "em2828x_builtin"; v4l2->decoder->function = MEDIA_ENT_F_ATV_DECODER; base-commit: 97d73c8251226cf27cc6656b4c542869bb8c69fa -- 2.43.0