From patchwork Mon Jul 18 11:16:22 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chris Wilson X-Patchwork-Id: 9234427 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 789B56075D for ; Mon, 18 Jul 2016 11:16:41 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6A8CD200F5 for ; Mon, 18 Jul 2016 11:16:41 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5EF51228C8; Mon, 18 Jul 2016 11:16:41 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2BC98200F5 for ; Mon, 18 Jul 2016 11:16:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751695AbcGRLQi (ORCPT ); Mon, 18 Jul 2016 07:16:38 -0400 Received: from mail-wm0-f66.google.com ([74.125.82.66]:35467 "EHLO mail-wm0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751441AbcGRLQh (ORCPT ); Mon, 18 Jul 2016 07:16:37 -0400 Received: by mail-wm0-f66.google.com with SMTP id i5so12174062wmg.2 for ; Mon, 18 Jul 2016 04:16:36 -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=bxnbitItHW7e5YnCuPgx26lkIHtOtipUkaFuKmweG5g=; b=IqtfcR/NevYbTUGxhu/JIlKXt1WRTyCwjXgIhqkUi2J+i5daYcOYBGZ6wV1BXkkI9G 7ZvS67QWKxCwryh6U2deB0Q9aQCjSyG4BPv2dDgry+iIH/K1JXeOQqDoxHiQZSYtIvJN sQweSZeonG6ANOorcV69PGYvEvrn7j4ZegzA7GPamggBsmxhhE9tgIjx1Mz8WqfqfFq9 GdMOsHW4yL68vg83qr5YsuhEJ6iGtJyyYwcW9XuHiKK8MWWFENlmhIjML/rIBY1LOfzm BSBCtk6gsJ5nlKcjux+HvFlCCA+MjcYx75eBuHTD51CtK4P2mMYsnZ8l7IChc+1SIVGT Gbow== 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=bxnbitItHW7e5YnCuPgx26lkIHtOtipUkaFuKmweG5g=; b=FLmshnTcjhWV0Ig+XZSb45oCxzO8ehS5I1V2nf7MBNftQrSAnFW1bBt+gj1ODzf23P 2WTWLZTYrzgu9qPbBLG+sxu+xuDyUcngY6fRaVdrcSQiNNxOUfb6rvqxLKmFKFVvcXss cDt42R16sjFRu8y+8eOznwcqytHgnTR+p5pCYJtr59YYUE9/8vdQhuQ4B44Gv5Sieu+K xa7IzZwv7+SOoC5jOtwTYTjWlWqTnN9N9wXnWnQbSTopuO0ji3u0m2YDb8oVMB8D9hTr X6Vd3jJnFrNth5vbezuKSYgqL4VEmJo4qpPOJp2Wt5G3eRfT8HJ4kmRAxgkG0XbDZvc3 S7oA== X-Gm-Message-State: ALyK8tJbJWiLhw0bHVQo+WdAqQVokx4/Jk4crWEyOOQQvESWVKq6eCI8VyleA4zyJNNvdg== X-Received: by 10.195.18.226 with SMTP id gp2mr647236wjd.63.1468840595814; Mon, 18 Jul 2016 04:16:35 -0700 (PDT) Received: from haswell.alporthouse.com ([78.156.65.138]) by smtp.gmail.com with ESMTPSA id 17sm16143289wmf.6.2016.07.18.04.16.29 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 18 Jul 2016 04:16:30 -0700 (PDT) From: Chris Wilson To: dri-devel@lists.freedesktop.org Cc: intel-gfx@lists.freedesktop.org, Chris Wilson , Joonas Lahtinen , Sumit Semwal , Daniel Vetter , linux-media@vger.kernel.org, linaro-mm-sig@lists.linaro.org Subject: [PATCH] dma-buf: Release module reference on creation failure Date: Mon, 18 Jul 2016 12:16:22 +0100 Message-Id: <1468840582-21469-1-git-send-email-chris@chris-wilson.co.uk> X-Mailer: git-send-email 2.8.1 Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.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 Reviewed-by: Joonas Lahtinen Cc: Joonas Lahtinen 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 Acked-by: Sumit Semwal --- 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 20ce0687b111..ddaee60ae52a 100644 --- a/drivers/dma-buf/dma-buf.c +++ b/drivers/dma-buf/dma-buf.c @@ -334,6 +334,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); @@ -357,8 +358,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 err_module; } dmabuf->priv = exp_info->priv; @@ -379,8 +380,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 err_dmabuf; } file->f_mode |= FMODE_LSEEK; @@ -394,6 +395,12 @@ struct dma_buf *dma_buf_export(const struct dma_buf_export_info *exp_info) mutex_unlock(&db_list.lock); return dmabuf; + +err_dmabuf: + kfree(dmabuf); +err_module: + module_put(exp_info->owner); + return ERR_PTR(ret); } EXPORT_SYMBOL_GPL(dma_buf_export);