From patchwork Thu Mar 31 08:35:50 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chris Wilson X-Patchwork-Id: 8708381 Return-Path: X-Original-To: patchwork-linux-media@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 05EE5C0553 for ; Thu, 31 Mar 2016 08:36:09 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 2E7B8201C8 for ; Thu, 31 Mar 2016 08:36:08 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 773FC2012D for ; Thu, 31 Mar 2016 08:36:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754737AbcCaIgA (ORCPT ); Thu, 31 Mar 2016 04:36:00 -0400 Received: from mail-wm0-f68.google.com ([74.125.82.68]:35911 "EHLO mail-wm0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753071AbcCaIf5 (ORCPT ); Thu, 31 Mar 2016 04:35:57 -0400 Received: by mail-wm0-f68.google.com with SMTP id 20so21521880wmh.3 for ; Thu, 31 Mar 2016 01:35:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:from:to:cc:subject:date:message-id; bh=Zt7J1ySY6/y6PFnciYmUr/9OhPgNTnymrBVYPh09Zgo=; b=mqXffPTPPbLFfXCTIfaqnFTo4SYJSPsxaHPiX0HBniTYCtmhtBZ2bmSDZ8F7+wPO1S 50O+55W8o8FPERc5t9fdzrcDacgAuYSE9lbF4orThvPGMxazpzu8D0KYYUp9EkW3TS9R 5Fk/aU9ICb64s1UdXRe8te/z020hBmWhf1kdawaug2w08qvGEKbuNfA0cqSTP1y3O2o1 Sbc8I6xzTVfsZzgRWvDrQOncp0UCpSqivw7qaQFUYDZOJcWZVOHngt0cPmBCWHQMyqbf ANKDZSYy8P9Hz6buG8+iZAusP1Uuu2appq5v0Gcx3Jx3HgDIruE5Hahlr5Uc3bNc8xH5 bfUg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id; bh=Zt7J1ySY6/y6PFnciYmUr/9OhPgNTnymrBVYPh09Zgo=; b=XibENG2fzu/TaArPkcw4xE5XcCDy+lclwSP7Xcoe5yBTTJHn90lb3UfpsJ95r0Cdp8 OB7Cjt5fO+kElzZSoHAHN3jtyAhKRrU5wWYWKZ3CviBb11LxZfdZ5CdkZ720LtdwL8Po RuZR96Dd/b5CjJQ/q9PUujLP4an7846cuhv7xQeowdZfTfSB+ogf4vQ3RiXbAo7mlrUO 1CCzXho8HVFF/8NmSILJ1hGOV/Bk8fjXnhPuCfUkjoI32xUBL5gAczXHytIqQU5BMKz3 WCDwyJsWIWGNZi09nMFvc6X3d0g6Lb+gK9AqCt6PD6b81deiFQsMzgls6F1DblL8Fcvp 2Dpg== X-Gm-Message-State: AD7BkJKI5GanLHHUmdDF+H4at54tGUP2piSsSBpOyB+IugZVZseMUXX7W4fgaK59REbC+A== X-Received: by 10.28.101.133 with SMTP id z127mr15069501wmb.84.1459413356446; Thu, 31 Mar 2016 01:35:56 -0700 (PDT) Received: from haswell.alporthouse.com ([78.156.65.138]) by smtp.gmail.com with ESMTPSA id y62sm8332307wmg.12.2016.03.31.01.35.55 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 31 Mar 2016 01:35:55 -0700 (PDT) From: Chris Wilson To: intel-gfx@lists.freedesktop.org Cc: Chris Wilson , Sumit Semwal , Daniel Vetter , linux-media@vger.kernel.org, dri-devel@lists.freedesktop.org, linaro-mm-sig@lists.linaro.org Subject: [PATCH] dma-buf: Release module reference on creation failure Date: Thu, 31 Mar 2016 09:35:50 +0100 Message-Id: <1459413350-31082-1-git-send-email-chris@chris-wilson.co.uk> X-Mailer: git-send-email 2.8.0.rc3 Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org X-Spam-Status: No, score=-7.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,RP_MATCHES_RCVD,T_DKIM_INVALID,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 If we fail to create the anon file, we need to remember to release the module reference on the owner. Signed-off-by: Chris Wilson Cc: Sumit Semwal Cc: Daniel Vetter Cc: linux-media@vger.kernel.org Cc: dri-devel@lists.freedesktop.org Cc: linaro-mm-sig@lists.linaro.org Reviewed-by: Joonas Lahtinen --- drivers/dma-buf/dma-buf.c | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/drivers/dma-buf/dma-buf.c b/drivers/dma-buf/dma-buf.c index 4a2c07ee6677..6f0f0b10a241 100644 --- a/drivers/dma-buf/dma-buf.c +++ b/drivers/dma-buf/dma-buf.c @@ -333,6 +333,7 @@ struct dma_buf *dma_buf_export(const struct dma_buf_export_info *exp_info) struct reservation_object *resv = exp_info->resv; struct file *file; size_t alloc_size = sizeof(struct dma_buf); + int ret; if (!exp_info->resv) alloc_size += sizeof(struct reservation_object); @@ -356,8 +357,8 @@ struct dma_buf *dma_buf_export(const struct dma_buf_export_info *exp_info) dmabuf = kzalloc(alloc_size, GFP_KERNEL); if (!dmabuf) { - module_put(exp_info->owner); - return ERR_PTR(-ENOMEM); + ret = -ENOMEM; + goto free_module; } dmabuf->priv = exp_info->priv; @@ -378,8 +379,8 @@ struct dma_buf *dma_buf_export(const struct dma_buf_export_info *exp_info) file = anon_inode_getfile("dmabuf", &dma_buf_fops, dmabuf, exp_info->flags); if (IS_ERR(file)) { - kfree(dmabuf); - return ERR_CAST(file); + ret = PTR_ERR(file); + goto free_dmabuf; } file->f_mode |= FMODE_LSEEK; @@ -393,6 +394,12 @@ struct dma_buf *dma_buf_export(const struct dma_buf_export_info *exp_info) mutex_unlock(&db_list.lock); return dmabuf; + +free_dmabuf: + kfree(dmabuf); +free_module: + module_put(exp_info->owner); + return ERR_PTR(ret); } EXPORT_SYMBOL_GPL(dma_buf_export);