From patchwork Fri Feb 13 22:39:03 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexey Khoroshilov X-Patchwork-Id: 5827911 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 5C7D39F30C for ; Fri, 13 Feb 2015 22:39:43 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 8DFF52021A for ; Fri, 13 Feb 2015 22:39:42 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id C205120148 for ; Fri, 13 Feb 2015 22:39:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753122AbbBMWjW (ORCPT ); Fri, 13 Feb 2015 17:39:22 -0500 Received: from mail.ispras.ru ([83.149.199.45]:53363 "EHLO mail.ispras.ru" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752758AbbBMWjV (ORCPT ); Fri, 13 Feb 2015 17:39:21 -0500 Received: from localhost.localdomain (ppp85-141-240-59.pppoe.mtu-net.ru [85.141.240.59]) by mail.ispras.ru (Postfix) with ESMTPSA id 9DA2854006F; Sat, 14 Feb 2015 01:39:18 +0300 (MSK) From: Alexey Khoroshilov To: Mauro Carvalho Chehab , Guennadi Liakhovetski Cc: Alexey Khoroshilov , linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, ldv-project@linuxtesting.org Subject: [PATCH] sh_vou: fix memory leak on error paths in sh_vou_open() Date: Sat, 14 Feb 2015 01:39:03 +0300 Message-Id: <1423867143-8332-1-git-send-email-khoroshilov@ispras.ru> X-Mailer: git-send-email 1.9.1 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 Memory allocated for sh_vou_file is not deallocated on error paths in sh_vou_open(). Found by Linux Driver Verification project (linuxtesting.org). Signed-off-by: Alexey Khoroshilov --- drivers/media/platform/sh_vou.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/drivers/media/platform/sh_vou.c b/drivers/media/platform/sh_vou.c index 261f1195b49f..6d1959d1ad02 100644 --- a/drivers/media/platform/sh_vou.c +++ b/drivers/media/platform/sh_vou.c @@ -1168,10 +1168,10 @@ static int sh_vou_open(struct file *file) dev_dbg(vou_dev->v4l2_dev.dev, "%s()\n", __func__); - file->private_data = vou_file; - - if (mutex_lock_interruptible(&vou_dev->fop_lock)) + if (mutex_lock_interruptible(&vou_dev->fop_lock)) { + kfree(vou_file); return -ERESTARTSYS; + } if (atomic_inc_return(&vou_dev->use_count) == 1) { int ret; /* First open */ @@ -1183,6 +1183,7 @@ static int sh_vou_open(struct file *file) pm_runtime_put(vou_dev->v4l2_dev.dev); vou_dev->status = SH_VOU_IDLE; mutex_unlock(&vou_dev->fop_lock); + kfree(vou_file); return ret; } } @@ -1195,6 +1196,8 @@ static int sh_vou_open(struct file *file) vou_dev->vdev, &vou_dev->fop_lock); mutex_unlock(&vou_dev->fop_lock); + file->private_data = vou_file; + return 0; }