mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] ivtv: Fix a sleep-in-atomic bug in snd_ivtv_pcm_hw_free
@ 2017-06-01  3:25 Jia-Ju Bai
  2017-06-01  5:53 ` kbuild test robot
  0 siblings, 1 reply; 2+ messages in thread
From: Jia-Ju Bai @ 2017-06-01  3:25 UTC (permalink / raw)
  To: awalls, mchehab; +Cc: linux-media, linux-kernel, Jia-Ju Bai

The driver may sleep under a spin lock, and the function call path is:
snd_ivtv_pcm_hw_free (acquire the lock by spin_lock_irqsave)
  vfree --> may sleep

To fix it, the "substream->runtime->dma_area" is passed to a temporary
value, and mark it NULL when holding the lock. The memory is freed by
vfree through the temporary value outside the lock holding.

Signed-off-by: Jia-Ju Bai <baijiaju1990@163.com>
---
 drivers/media/pci/ivtv/ivtv-alsa-pcm.c |    4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/media/pci/ivtv/ivtv-alsa-pcm.c b/drivers/media/pci/ivtv/ivtv-alsa-pcm.c
index 807ead2..92d088c 100644
--- a/drivers/media/pci/ivtv/ivtv-alsa-pcm.c
+++ b/drivers/media/pci/ivtv/ivtv-alsa-pcm.c
@@ -262,14 +262,16 @@ static int snd_ivtv_pcm_hw_free(struct snd_pcm_substream *substream)
 {
 	struct snd_ivtv_card *itvsc = snd_pcm_substream_chip(substream);
 	unsigned long flags;
+	unsigned char *dma_area;
 
 	spin_lock_irqsave(&itvsc->slock, flags);
 	if (substream->runtime->dma_area) {
 		dprintk("freeing pcm capture region\n");
-		vfree(substream->runtime->dma_area);
+		dma_area = substream->runtime->dma_area;
 		substream->runtime->dma_area = NULL;
 	}
 	spin_unlock_irqrestore(&itvsc->slock, flags);
+	vfree(dma_area);
 
 	return 0;
 }
-- 
1.7.9.5

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

* Re: [PATCH] ivtv: Fix a sleep-in-atomic bug in snd_ivtv_pcm_hw_free
  2017-06-01  3:25 [PATCH] ivtv: Fix a sleep-in-atomic bug in snd_ivtv_pcm_hw_free Jia-Ju Bai
@ 2017-06-01  5:53 ` kbuild test robot
  0 siblings, 0 replies; 2+ messages in thread
From: kbuild test robot @ 2017-06-01  5:53 UTC (permalink / raw)
  To: Jia-Ju Bai
  Cc: kbuild-all, awalls, mchehab, linux-media, linux-kernel, Jia-Ju Bai

[-- Attachment #1: Type: text/plain, Size: 2192 bytes --]

Hi Jia-Ju,

[auto build test WARNING on linuxtv-media/master]
[also build test WARNING on v4.12-rc3 next-20170531]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system]

url:    https://github.com/0day-ci/linux/commits/Jia-Ju-Bai/ivtv-Fix-a-sleep-in-atomic-bug-in-snd_ivtv_pcm_hw_free/20170601-131112
base:   git://linuxtv.org/media_tree.git master
config: xtensa-allmodconfig (attached as .config)
compiler: xtensa-linux-gcc (GCC) 4.9.0
reproduce:
        wget https://raw.githubusercontent.com/01org/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
        chmod +x ~/bin/make.cross
        # save the attached .config to linux build tree
        make.cross ARCH=xtensa 

Note: it may well be a FALSE warning. FWIW you are at least aware of it now.
http://gcc.gnu.org/wiki/Better_Uninitialized_Warnings

All warnings (new ones prefixed by >>):

   drivers/media//pci/ivtv/ivtv-alsa-pcm.c: In function 'snd_ivtv_pcm_hw_free':
>> drivers/media//pci/ivtv/ivtv-alsa-pcm.c:274:2: warning: 'dma_area' may be used uninitialized in this function [-Wmaybe-uninitialized]
     vfree(dma_area);
     ^

vim +/dma_area +274 drivers/media//pci/ivtv/ivtv-alsa-pcm.c

   258						   params_buffer_bytes(params));
   259	}
   260	
   261	static int snd_ivtv_pcm_hw_free(struct snd_pcm_substream *substream)
   262	{
   263		struct snd_ivtv_card *itvsc = snd_pcm_substream_chip(substream);
   264		unsigned long flags;
   265		unsigned char *dma_area;
   266	
   267		spin_lock_irqsave(&itvsc->slock, flags);
   268		if (substream->runtime->dma_area) {
   269			dprintk("freeing pcm capture region\n");
   270			dma_area = substream->runtime->dma_area;
   271			substream->runtime->dma_area = NULL;
   272		}
   273		spin_unlock_irqrestore(&itvsc->slock, flags);
 > 274		vfree(dma_area);
   275	
   276		return 0;
   277	}
   278	
   279	static int snd_ivtv_pcm_prepare(struct snd_pcm_substream *substream)
   280	{
   281		struct snd_ivtv_card *itvsc = snd_pcm_substream_chip(substream);
   282	

---
0-DAY kernel test infrastructure                Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all                   Intel Corporation

[-- Attachment #2: .config.gz --]
[-- Type: application/gzip, Size: 50141 bytes --]

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

end of thread, other threads:[~2017-06-01  5:54 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-06-01  3:25 [PATCH] ivtv: Fix a sleep-in-atomic bug in snd_ivtv_pcm_hw_free Jia-Ju Bai
2017-06-01  5:53 ` kbuild test robot

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

all inboxes | Powered by JetHome®