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: 8708391 Return-Path: X-Original-To: patchwork-dri-devel@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 77E99C0553 for ; Thu, 31 Mar 2016 08:36:12 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 9D45020120 for ; Thu, 31 Mar 2016 08:36:11 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) by mail.kernel.org (Postfix) with ESMTP id C4A5B2012D for ; Thu, 31 Mar 2016 08:36:10 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 081F76E161; Thu, 31 Mar 2016 08:36:01 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-wm0-x243.google.com (mail-wm0-x243.google.com [IPv6:2a00:1450:400c:c09::243]) by gabe.freedesktop.org (Postfix) with ESMTPS id 90DBB6E054; Thu, 31 Mar 2016 08:35:58 +0000 (UTC) Received: by mail-wm0-x243.google.com with SMTP id p65so21511995wmp.1; Thu, 31 Mar 2016 01:35:58 -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=MTc1N6kZiS43bHfQEWQOl2d8/WV+QDKZiVnoLGbRspl6+SDoRPBD1PIRCKr/MV6DxV kI+bAzB/clRvmsum2cBK+gnbGDiv0M1MUC5tbXuUwDCQu7lDCOxtICdre5Tuu+hqSA4s f3BhgTFUFY7XeoSjH5dyt+DkoRMf2S7k1ARbkX4kY4foSFFw685cpzG1K1hIRCBZgXxN RUlAFj/Tyah9XAHSrmI9DI54Y2vfkQHyLOMjvMz2gbsVxVA3oDCCy1YkP0GM+uG1183v 5bVovAm3rzhkic6mOeKyFpbs0tmCsY6W9pyauZ+2BZapoNcr6OgnbZRQVaVBACVm6pQ7 bsLg== X-Gm-Message-State: AD7BkJJUCb155uQQn4VgvwNpA49erC2l+TanpfiWN0JmsXKmGKAEylan3qxaTmavg7sgPA== 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 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 Cc: Daniel Vetter , dri-devel@lists.freedesktop.org, linaro-mm-sig@lists.linaro.org, linux-media@vger.kernel.org X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" X-Spam-Status: No, score=-5.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_MED,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);