From patchwork Thu Feb 15 13:59:26 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Rob Herring (Arm)" X-Patchwork-Id: 10221303 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 4CD4F6055C for ; Thu, 15 Feb 2018 13:59:38 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3D21329347 for ; Thu, 15 Feb 2018 13:59:38 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3088A2934C; Thu, 15 Feb 2018 13:59:38 +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=-4.2 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id E045A29347 for ; Thu, 15 Feb 2018 13:59:37 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 1515B6E527; Thu, 15 Feb 2018 13:59:35 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-oi0-f67.google.com (mail-oi0-f67.google.com [209.85.218.67]) by gabe.freedesktop.org (Postfix) with ESMTPS id 796EC6E527 for ; Thu, 15 Feb 2018 13:59:33 +0000 (UTC) Received: by mail-oi0-f67.google.com with SMTP id u6so19109295oiv.9 for ; Thu, 15 Feb 2018 05:59:33 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=9mg8HhSu6iYxNfzTjy0+I5ntssfhVWMX1w9+ahFPWjE=; b=MT7zhIVCXKTSC/9eQo+vKdzMyaeYXppzXGXumgxW5YSeqqbiyqUSzAVrdvIIe5T827 uTt/dvJk1YwSHH5WR3HHYqx66DPp749kVOq8JoTlAypBWMpGO7VxZYvvqMu+8FOnd0ZR WLL9Sd6QeL50OliQ9BIItFwGR+MVcMNl1aRN2pnkUFqerDJYXa/WzoDguVOB50rFmFoR 2yeZtLmfZFjuRkgDo6XIWhQYj7yoL8qqj0KyhuAZo4Di+wfjBqB+si4DT7roID55YKdT N4pl6G9SBDmHAIZW+uy0NPjfmeMWqJ0BmoDToqgM/sjYi01p28JOu173MYTJ/ySBp8cI V4eg== X-Gm-Message-State: APf1xPBXYXSsXhKH1JH9EE9rHz33bvc1EWuOw3tBK8Gsq0g7wKpEwatV kNBsdCNnz7uO0WPYKjdVa0FnFns= X-Google-Smtp-Source: AH8x2254iRY7lm8SL+mFmoheN0djnHKbRV05FKQSwA54zfinSvxrw8c6qVVD0guPOQeE+SmC9/XyNQ== X-Received: by 10.202.8.76 with SMTP id 73mr1719895oii.326.1518703172563; Thu, 15 Feb 2018 05:59:32 -0800 (PST) Received: from xps15.herring.priv (216-188-254-6.dyn.grandenetworks.net. [216.188.254.6]) by smtp.googlemail.com with ESMTPSA id t8sm8677327otj.31.2018.02.15.05.59.31 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 15 Feb 2018 05:59:32 -0800 (PST) From: Rob Herring To: dri-devel@lists.freedesktop.org Subject: [PATCH libdrm 4/4] android: fix gralloc_handle_create() problems Date: Thu, 15 Feb 2018 07:59:26 -0600 Message-Id: <20180215135926.9502-5-robh@kernel.org> X-Mailer: git-send-email 2.14.1 In-Reply-To: <20180215135926.9502-1-robh@kernel.org> References: <20180215135926.9502-1-robh@kernel.org> X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Robert Foss MIME-Version: 1.0 Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" X-Virus-Scanned: ClamAV using ClamSMTP There's a number of problems with gralloc_handle_create starting with it doesn't even compile. More importantly, it doesn't really create (i.e. allocate) a handle. It allocates a native_handle_t, copies it to a struct gralloc_handle_t on the stack and returns the struct (not a ptr). So the caller still has to allocate a struct gralloc_handle_t to hold the returned struct. Rework gralloc_handle_create() to allocate a new handle and return the pointer to the allocated handle. Callers should free the handle with native_handle_close() and native_handle_delete(). Signed-off-by: Rob Herring --- android/gralloc_handle.h | 32 +++++++++++++++----------------- 1 file changed, 15 insertions(+), 17 deletions(-) diff --git a/android/gralloc_handle.h b/android/gralloc_handle.h index 43255ba539c2..3177f7a1fd8f 100644 --- a/android/gralloc_handle.h +++ b/android/gralloc_handle.h @@ -84,28 +84,26 @@ static inline struct gralloc_handle_t *gralloc_handle(buffer_handle_t handle) /** * Create a buffer handle. */ -static struct gralloc_handle_t gralloc_handle_create(int32_t width, +static inline struct gralloc_handle_t *gralloc_handle_create(int32_t width, int32_t height, int32_t format, int32_t usage) { - struct alloc_handle_t handle = { - .magic = GRALLOC_HANDLE_MAGIC, - .version = GRALLOC_HANDLE_VERSION }; - + struct gralloc_handle_t *handle; native_handle_t *nhandle = native_handle_create(GRALLOC_HANDLE_NUM_FDS, - GRALLOC_HANDLE_NUM_INTS); - handle.base = *nhandle; - native_handle_delete(nhandle); - - handle.width = width; - handle.height = height; - handle.format = format; - handle.usage = usage; - handle.prime_fd = -1; - - handle->data_owner = getpid(); - handle->data = bo; + GRALLOC_HANDLE_NUM_INTS); + + if (!nhandle) + return NULL; + + handle = gralloc_handle(nhandle); + handle->magic = GRALLOC_HANDLE_MAGIC; + handle->version = GRALLOC_HANDLE_VERSION; + handle->width = width; + handle->height = height; + handle->format = format; + handle->usage = usage; + handle->prime_fd = -1; return handle; }