From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.0 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_PASS,URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id C1FA4C43381 for ; Mon, 1 Apr 2019 13:07:12 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 928AB20828 for ; Mon, 1 Apr 2019 13:07:12 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="un9+wNiy"; dkim=fail reason="signature verification failed" (1024-bit key) header.d=ffwll.ch header.i=@ffwll.ch header.b="Mab1bpzC" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 928AB20828 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=ffwll.ch Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+infradead-linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:To:Subject:Message-ID:Date:From: In-Reply-To:References:MIME-Version:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=pBevtlk9uhyX0xRaRFfZcfFkOpy7zpAGwuFcYJHcrYY=; b=un9+wNiyvxQDNf cdMqCCqWvUqzM431FLTPqRhyf+DBLRJRaEKstytPiF3ioJJztAp1vXecpspbmroum1E8eoqQw23cm DM7k3OjyxwWarSGcQewDEWguKZ3rONZYKII9fTjpCpVlppqMNjvWYt7MHPWDlAoeWxncCJmivmhkl YoJugD855PRlWFisCxb1bFp8ozH5K+MG1k+hP9RetTeF3zTyCeFRnTwpy+wFC1aWTpdxGpQRjHDPQ uwg6E6XEAgWebgUwqIk4qL8OLJEJgpBrRbUOjS+BX2RwG4Eiznbw54dBBywlT3I+lwMJqJTa7MyW3 GyQRlN/9CV1uRVoMYy2g==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1hAweX-0008Mc-41; Mon, 01 Apr 2019 13:07:05 +0000 Received: from mail-it1-x144.google.com ([2607:f8b0:4864:20::144]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1hAweT-0008M0-NA for linux-arm-kernel@lists.infradead.org; Mon, 01 Apr 2019 13:07:03 +0000 Received: by mail-it1-x144.google.com with SMTP id s3so6681793itk.1 for ; Mon, 01 Apr 2019 06:07:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ffwll.ch; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=c7nfqyavCOHYwP5bfIj4Lx+eog2sSv/F9dC/tuo3Ysg=; b=Mab1bpzCeid3WPDcMGc85Hx6aSDmDJ2oRWM5Vn2469/ub/av3WIdBLimt38Jh02V6h d5rLAwo+a+rojnLXmCp0JF4QCabTHbMq3tygfsQih4PbCLlL6kdyw5fifuNo6M6gRPg6 NBpGHwite2rVfW6KQTjRRpJqPW1w97p676KEc= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=c7nfqyavCOHYwP5bfIj4Lx+eog2sSv/F9dC/tuo3Ysg=; b=Lz/fBuH8L3VyEUM2cK9l3HdZM6MEbDTnvGjoUKdz2Xchqx5+7qYn3TomanT6CcHALa 1iOtzoBCBhQeGkU+YDLShnQZ/V75AXetgk1Rq4d9aZ16dSxH3FfsJenhRR9MvyiBFW4u v3BwfqnVKKpWOuYM4v6C4P+TFOwP1BgxbnzQN4FlaAs3jYB3HH9kyAvEagsrNQR2vEB4 Tj9HFuW/zsuqGwV9uiGrB7XiGvhMcS6KFfSs8ir+8gD8q56adVrM05E0ICbyK/DWQMLl 46BXvkfGNJ3FmPBiEQydi5v5vFF+iMabHAh3B0Q2dwQcW29keWoYwxm6tvtxX93VK/OI kGyQ== X-Gm-Message-State: APjAAAXRl8kAfExnBRVVHOsQVEDjCuCD+XVY5arhNxyZA5bXDZE0B+K2 7vY03O9QGfHNG8WFhJCHp30rgm5c70DbaisL++9eeQ== X-Google-Smtp-Source: APXvYqzf03iLejtUCyRwLnD5MaQSvDlC1WnH6z1op2bRWKXEAF8SP0OcHnpYhSZE9YkUYq1GND9jAb7/HJabzxlglPw= X-Received: by 2002:a24:3dc7:: with SMTP id n190mr15546962itn.62.1554124019944; Mon, 01 Apr 2019 06:06:59 -0700 (PDT) MIME-Version: 1.0 References: <20190401074730.12241-1-robh@kernel.org> <20190401074730.12241-3-robh@kernel.org> In-Reply-To: <20190401074730.12241-3-robh@kernel.org> From: Daniel Vetter Date: Mon, 1 Apr 2019 15:06:48 +0200 Message-ID: Subject: Re: [PATCH v2 2/3] drm: Add a drm_gem_objects_lookup helper To: Rob Herring X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190401_060701_809836_E66CD99E X-CRM114-Status: GOOD ( 22.91 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Sean Paul , Lyude Paul , Eric Anholt , Maxime Ripard , Maarten Lankhorst , Joerg Roedel , Neil Armstrong , Will Deacon , Linux Kernel Mailing List , dri-devel , David Airlie , "list@263.net:IOMMU DRIVERS , Joerg Roedel , " , Alyssa Rosenzweig , Robin Murphy , Linux ARM Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+infradead-linux-arm-kernel=archiver.kernel.org@lists.infradead.org On Mon, Apr 1, 2019 at 9:47 AM Rob Herring wrote: > > Similar to the single handle drm_gem_object_lookup(), > drm_gem_objects_lookup() takes an array of handles and returns an array > of GEM objects. > > Cc: Maarten Lankhorst > Cc: Maxime Ripard > Cc: Sean Paul > Cc: David Airlie > Cc: Daniel Vetter > Signed-off-by: Rob Herring > --- > drivers/gpu/drm/drm_gem.c | 46 +++++++++++++++++++++++++++++++-------- > include/drm/drm_gem.h | 2 ++ > 2 files changed, 39 insertions(+), 9 deletions(-) > > diff --git a/drivers/gpu/drm/drm_gem.c b/drivers/gpu/drm/drm_gem.c > index 388b3742e562..5c9bff45e5e1 100644 > --- a/drivers/gpu/drm/drm_gem.c > +++ b/drivers/gpu/drm/drm_gem.c > @@ -663,6 +663,42 @@ void drm_gem_put_pages(struct drm_gem_object *obj, struct page **pages, > } > EXPORT_SYMBOL(drm_gem_put_pages); > > +/** > + * drm_gem_objects_lookup - look up GEM objects from an array of handles > + * @filp: DRM file private date > + * @handle: pointer to array of userspace handle > + * @count: size of handle array > + * @objs: pointer to array of drm_gem_object pointers > + * > + * Returns: > + * > + * @objs filled in with GEM object pointers. -ENOENT is returned on a lookup > + * failure. 0 is returned on success. Bonus points for adding references between the array and normal lookup functions to guide people around. Also a comment that the buffers need to be released with drm_gem_object_put(). > + */ > +int drm_gem_objects_lookup(struct drm_file *filp, u32 *handle, int count, > + struct drm_gem_object **objs) With a pointer to a pointer I'd expect this function to do the allocation, but it doesn't. Normal pointer is enough to pass an array. Also maybe make the handle pointer const, so it's clear that it's an input parameter. With the bikesheds addressed: Reviewed-by: Daniel Vetter > +{ > + int i, ret = 0; > + struct drm_gem_object *obj; > + > + spin_lock(&filp->table_lock); > + > + for (i = 0; i < count; i++) { > + /* Check if we currently have a reference on the object */ > + obj = idr_find(&filp->object_idr, handle[i]); > + if (!obj) { > + ret = -ENOENT; > + break; > + } > + drm_gem_object_get(obj); > + objs[i] = obj; > + } > + spin_unlock(&filp->table_lock); > + > + return ret; > +} > +EXPORT_SYMBOL(drm_gem_objects_lookup); > + > /** > * drm_gem_object_lookup - look up a GEM object from its handle > * @filp: DRM file private date > @@ -678,15 +714,7 @@ drm_gem_object_lookup(struct drm_file *filp, u32 handle) > { > struct drm_gem_object *obj; > > - spin_lock(&filp->table_lock); > - > - /* Check if we currently have a reference on the object */ > - obj = idr_find(&filp->object_idr, handle); > - if (obj) > - drm_gem_object_get(obj); > - > - spin_unlock(&filp->table_lock); > - > + drm_gem_objects_lookup(filp, &handle, 1, &obj); > return obj; > } > EXPORT_SYMBOL(drm_gem_object_lookup); > diff --git a/include/drm/drm_gem.h b/include/drm/drm_gem.h > index 2955aaab3dca..5404225e0194 100644 > --- a/include/drm/drm_gem.h > +++ b/include/drm/drm_gem.h > @@ -381,6 +381,8 @@ struct page **drm_gem_get_pages(struct drm_gem_object *obj); > void drm_gem_put_pages(struct drm_gem_object *obj, struct page **pages, > bool dirty, bool accessed); > > +int drm_gem_objects_lookup(struct drm_file *filp, u32 *handle, int count, > + struct drm_gem_object **objs); > struct drm_gem_object *drm_gem_object_lookup(struct drm_file *filp, u32 handle); > long drm_gem_reservation_object_wait(struct drm_file *filep, u32 handle, > bool wait_all, unsigned long timeout); > -- > 2.19.1 > -- Daniel Vetter Software Engineer, Intel Corporation +41 (0) 79 365 57 48 - http://blog.ffwll.ch _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel