Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 311c70e1 authored by Johann Friedrichs's avatar Johann Friedrichs Committed by Mauro Carvalho Chehab
Browse files

V4L/DVB (13239): saa7146: fix memory leakage in pagetable-handling



In buffer_release() the previously allocated pagetables are not
freed,  which might result in a memory leak in certain application
use-cases, where the frame format is changed from planar format to
non-planar format. The fix explicitely frees the page tables when a
format change is done and when buffer_release() is called.

Signed-off-by: default avatarJohann Friedrichs <johann.friedrichs@web.de>
Signed-off-by: default avatarMichael Hunold <hunold@linuxtv.org>
Signed-off-by: default avatarMauro Carvalho Chehab <mchehab@redhat.com>
parent 622b828a
Loading
Loading
Loading
Loading
+11 −5
Original line number Original line Diff line number Diff line
@@ -1205,6 +1205,13 @@ static int buffer_activate (struct saa7146_dev *dev,
	return 0;
	return 0;
}
}


static void release_all_pagetables(struct saa7146_dev *dev, struct saa7146_buf *buf)
{
	saa7146_pgtable_free(dev->pci, &buf->pt[0]);
	saa7146_pgtable_free(dev->pci, &buf->pt[1]);
	saa7146_pgtable_free(dev->pci, &buf->pt[2]);
}

static int buffer_prepare(struct videobuf_queue *q,
static int buffer_prepare(struct videobuf_queue *q,
			  struct videobuf_buffer *vb, enum v4l2_field field)
			  struct videobuf_buffer *vb, enum v4l2_field field)
{
{
@@ -1257,16 +1264,12 @@ static int buffer_prepare(struct videobuf_queue *q,


		sfmt = format_by_fourcc(dev,buf->fmt->pixelformat);
		sfmt = format_by_fourcc(dev,buf->fmt->pixelformat);


		release_all_pagetables(dev, buf);
		if( 0 != IS_PLANAR(sfmt->trans)) {
		if( 0 != IS_PLANAR(sfmt->trans)) {
			saa7146_pgtable_free(dev->pci, &buf->pt[0]);
			saa7146_pgtable_free(dev->pci, &buf->pt[1]);
			saa7146_pgtable_free(dev->pci, &buf->pt[2]);

			saa7146_pgtable_alloc(dev->pci, &buf->pt[0]);
			saa7146_pgtable_alloc(dev->pci, &buf->pt[0]);
			saa7146_pgtable_alloc(dev->pci, &buf->pt[1]);
			saa7146_pgtable_alloc(dev->pci, &buf->pt[1]);
			saa7146_pgtable_alloc(dev->pci, &buf->pt[2]);
			saa7146_pgtable_alloc(dev->pci, &buf->pt[2]);
		} else {
		} else {
			saa7146_pgtable_free(dev->pci, &buf->pt[0]);
			saa7146_pgtable_alloc(dev->pci, &buf->pt[0]);
			saa7146_pgtable_alloc(dev->pci, &buf->pt[0]);
		}
		}


@@ -1329,6 +1332,9 @@ static void buffer_release(struct videobuf_queue *q, struct videobuf_buffer *vb)
	struct saa7146_buf *buf = (struct saa7146_buf *)vb;
	struct saa7146_buf *buf = (struct saa7146_buf *)vb;


	DEB_CAP(("vbuf:%p\n",vb));
	DEB_CAP(("vbuf:%p\n",vb));

	release_all_pagetables(dev, buf);

	saa7146_dma_free(dev,q,buf);
	saa7146_dma_free(dev,q,buf);
}
}