From patchwork Fri Dec 18 16:14:30 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mauro Carvalho Chehab X-Patchwork-Id: 7886901 Return-Path: X-Original-To: patchwork-linux-media@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id B77409F1AF for ; Fri, 18 Dec 2015 16:14:59 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id E235C204AF for ; Fri, 18 Dec 2015 16:14:58 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id CEC632035E for ; Fri, 18 Dec 2015 16:14:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754165AbbLRQO4 (ORCPT ); Fri, 18 Dec 2015 11:14:56 -0500 Received: from bombadil.infradead.org ([198.137.202.9]:42577 "EHLO bombadil.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753869AbbLRQOz (ORCPT ); Fri, 18 Dec 2015 11:14:55 -0500 Received: from 177.17.246.4.dynamic.adsl.gvt.net.br ([177.17.246.4] helo=smtp.w2.samsung.com) by bombadil.infradead.org with esmtpsa (Exim 4.80.1 #2 (Red Hat Linux)) id 1a9xgE-0002Gy-GB; Fri, 18 Dec 2015 16:14:54 +0000 Received: from mchehab by smtp.w2.samsung.com with local (Exim 4.86) (envelope-from ) id 1a9xfr-0001kx-QQ; Fri, 18 Dec 2015 14:14:31 -0200 From: Mauro Carvalho Chehab Cc: Mauro Carvalho Chehab , Linux Media Mailing List , Mauro Carvalho Chehab , Pawel Osciak , Marek Szyprowski , Kyungmin Park Subject: [PATCH] [media] videobuf2: avoid memory leak on errors Date: Fri, 18 Dec 2015 14:14:30 -0200 Message-Id: X-Mailer: git-send-email 2.5.0 To: unlisted-recipients:; (no To-header on input) Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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 Acked-by: Marek Szyprowski --- drivers/media/v4l2-core/videobuf2-core.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/drivers/media/v4l2-core/videobuf2-core.c b/drivers/media/v4l2-core/videobuf2-core.c index e6890d47cdcb..c5d49d7a0d76 100644 --- a/drivers/media/v4l2-core/videobuf2-core.c +++ b/drivers/media/v4l2-core/videobuf2-core.c @@ -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;