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

[media] media: am437x-vpfe: Fix a race condition during release

There was a race condition where during cleanup/release operation
on-going streaming would cause a kernel panic because the hardware
module was disabled prematurely with IRQ still pending.

Fixes: 417d2e507edc ("[media] media: platform: add VPFE capture driver support for AM437X")

Cc: <stable@vger.kernel.org> # v4.0+
Signed-off-by: Benoit Parrot <bparrot@ti.com>
Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>

authored by

Benoit Parrot and committed by
Mauro Carvalho Chehab
c99235fa 2091f518

+12 -2
+12 -2
drivers/media/platform/am437x/am437x-vpfe.c
··· 1186 1186 static int vpfe_release(struct file *file) 1187 1187 { 1188 1188 struct vpfe_device *vpfe = video_drvdata(file); 1189 + bool fh_singular; 1189 1190 int ret; 1190 1191 1191 1192 mutex_lock(&vpfe->lock); 1192 1193 1193 - if (v4l2_fh_is_singular_file(file)) 1194 - vpfe_ccdc_close(&vpfe->ccdc, vpfe->pdev); 1194 + /* Save the singular status before we call the clean-up helper */ 1195 + fh_singular = v4l2_fh_is_singular_file(file); 1196 + 1197 + /* the release helper will cleanup any on-going streaming */ 1195 1198 ret = _vb2_fop_release(file, NULL); 1199 + 1200 + /* 1201 + * If this was the last open file. 1202 + * Then de-initialize hw module. 1203 + */ 1204 + if (fh_singular) 1205 + vpfe_ccdc_close(&vpfe->ccdc, vpfe->pdev); 1196 1206 1197 1207 mutex_unlock(&vpfe->lock); 1198 1208