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: 128429 Delivered-To: patch@linaro.org Received: by 10.46.124.24 with SMTP id x24csp1778657ljc; Thu, 15 Feb 2018 06:00:08 -0800 (PST) X-Google-Smtp-Source: AH8x2260H54uBXkreRCklZ7FPTT2nwRLJ32N/hEWNivJgyPIYBZ348ngcTJhAMigyVmHlv4f0Xdk X-Received: by 10.99.117.89 with SMTP id f25mr2273955pgn.18.1518703207969; Thu, 15 Feb 2018 06:00:07 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1518703207; cv=none; d=google.com; s=arc-20160816; b=kiGnsG0cFj+a7GjZVFr4py0OxHtt/FQqmC4zGNb+HIs+LhVQQPRzQ8ydyG0PcnTJ+6 JVHgUM/UrqE8JB3fyqs7KMf0WEjPztp2YxCBKYlM4W1jty0KSo9Z0odqPOOsQan7/Udm VCYx0hKPxxzPdOzisdFB6qt9hQp7KCtOhWVYxAhdHun9KKz1uer58xnOOcluJf0NPPaD FZJBbd7F9JQ3sKTDQbWGsp65TkhApL96YxB/a1KgjizQiPDpBuSrU7Q0Mb5MdfJ6EBPG nsHvmnBCVucpUGPZf6GmJ2j1kFw/Nup09ZwtCizjrQsXzdRZuRSLwQVybDQlanxq8Kiw i6+A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version:cc :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:references:in-reply-to:message-id:date:subject :to:from:delivered-to:arc-authentication-results; bh=FqWrIHfzfmACkqcC5DEWFDkrkJqgiPAfN1osdJsmF/Q=; b=LHDluiF+Hse4VBpbZDIKw4KFIoavLNtlmSm9r+/RK6NGKP8eYziNTjUSB7lzhcAFOL jc0cD7JxGkNK9wg0zaL3vK0KBMkEahzdheWz4YovDxUXThkgcISEF/PaTiazIaOhuXsj eKW5q1kzKUuE0GwAhOZHrGsbd8489roK0s89dPpZh5AlLJpXM0tGPZ1VU8eJSG5WNZxK AqViJDYnKXUG+kF/2iVtOGqfBYywpvSoNrN6z5+B7hFeokgOZkIwIolyDK1E83P7BrNJ J1e4iajBjUTvtaK9mrudN/oG+tTTr9YdgO5OTRMtcegVszsB+dmqk25WBdsf+GCRGSSW gjhA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of dri-devel-bounces@lists.freedesktop.org designates 131.252.210.177 as permitted sender) smtp.mailfrom=dri-devel-bounces@lists.freedesktop.org Return-Path: Received: from gabe.freedesktop.org (gabe.freedesktop.org. [131.252.210.177]) by mx.google.com with ESMTPS id g4si1246695pgr.797.2018.02.15.06.00.07 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 15 Feb 2018 06:00:07 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of dri-devel-bounces@lists.freedesktop.org designates 131.252.210.177 as permitted sender) client-ip=131.252.210.177; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of dri-devel-bounces@lists.freedesktop.org designates 131.252.210.177 as permitted sender) smtp.mailfrom=dri-devel-bounces@lists.freedesktop.org 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-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" 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; }