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

media: common: saa7146: Avoid a leak in vmalloc_to_sg()

Commit in Fixes turned a BUG() into a "normal" memory allocation failure.
While at it, it introduced a memory leak.
So fix it.

Also update the comment on top of the function to reflect what has been
change by the commit in Fixes.

Fixes: 40e986c99624 ("media: common: saa7146: replace BUG_ON by WARN_ON")
Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
Signed-off-by: Hans Verkuil <hverkuil-cisco@xs4all.nl>

authored by

Christophe JAILLET and committed by
Hans Verkuil
b2aa8ac6 4a357000

+3 -3
+3 -3
drivers/media/common/saa7146/saa7146_core.c
··· 133 133 ****************************************************************************/ 134 134 135 135 /* this is videobuf_vmalloc_to_sg() from videobuf-dma-sg.c 136 - make sure virt has been allocated with vmalloc_32(), otherwise the BUG() 137 - may be triggered on highmem machines */ 136 + make sure virt has been allocated with vmalloc_32(), otherwise return NULL 137 + on highmem machines */ 138 138 static struct scatterlist* vmalloc_to_sg(unsigned char *virt, int nr_pages) 139 139 { 140 140 struct scatterlist *sglist; ··· 150 150 if (NULL == pg) 151 151 goto err; 152 152 if (WARN_ON(PageHighMem(pg))) 153 - return NULL; 153 + goto err; 154 154 sg_set_page(&sglist[i], pg, PAGE_SIZE, 0); 155 155 } 156 156 return sglist;