[media] videobuf2: avoid memory leak on errors
authorMauro Carvalho Chehab <mchehab@osg.samsung.com>
Fri, 18 Dec 2015 16:11:31 +0000 (14:11 -0200)
committerMauro Carvalho Chehab <mchehab@osg.samsung.com>
Fri, 18 Dec 2015 16:13:38 +0000 (14:13 -0200)
As reported by smatch:
drivers/media/v4l2-core/videobuf2-core.c:2415 __vb2_init_fileio() warn: possible memory leak of 'fileio'

While here, avoid the usage of sizeof(struct foo_struct).

Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
drivers/media/v4l2-core/videobuf2-core.c

index e6890d47cdcb438b6e84680dfbfe6e54f9b1a963..c5d49d7a0d76d09c1ac5598a21ce7726d03190c1 100644 (file)
@@ -2406,13 +2406,15 @@ static int __vb2_init_fileio(struct vb2_queue *q, int read)
                (read) ? "read" : "write", count, q->fileio_read_once,
                q->fileio_write_immediately);
 
-       fileio = kzalloc(sizeof(struct vb2_fileio_data), GFP_KERNEL);
+       fileio = kzalloc(sizeof(*fileio), GFP_KERNEL);
        if (fileio == NULL)
                return -ENOMEM;
 
        fileio->b = kzalloc(q->buf_struct_size, GFP_KERNEL);
-       if (fileio->b == NULL)
+       if (fileio->b == NULL) {
+               kfree(fileio);
                return -ENOMEM;
+       }
 
        fileio->read_once = q->fileio_read_once;
        fileio->write_immediately = q->fileio_write_immediately;