Message ID | 20230626143331.640454-1-suijingfeng@loongson.cn |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp7552798vqr; Mon, 26 Jun 2023 08:11:17 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7oryc7HIO5vz/SUhHGGNA/2jwrTEF3yQkym3Qv89uf0q0pFfVKDjYGfDD50fcDl9cmfLXE X-Received: by 2002:a05:6870:9513:b0:1ad:e92:62e1 with SMTP id u19-20020a056870951300b001ad0e9262e1mr13016551oal.54.1687792277531; Mon, 26 Jun 2023 08:11:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687792277; cv=none; d=google.com; s=arc-20160816; b=mQTNY7q6mQn/92a8jjjX5VsvCez3m7IulJIMWIfwSAmdlZ092O5DF49TljcfAh82Qb ET+xaC9hKPLfGDk3P4cqTbCea+UG1TaUAdDf3RT+W6rOgmA8/0JisW3IBx1EW6G7mv8i cURz8YIZ4VpdulmZpYd+MBh863ro2WycmtSDzt/actO0Ie8r08ZAq8Yja7SSXvVxbLdF RwCmT3XIaKX/WNYtrhB+p5piFwN2e131bbTRWCebVjwZ/K7SJ0DeqbPl+40mhCE9d4yW aMELBbAIwBat+KCOKYhIiwLvZyDUAAh3kFyVE7c1DnOVlzLxBJjtgux1Xmio81nbNYN0 2UpQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from; bh=HRVfvckNMeCGnwLSwP+O9ncqUcSKD/yM/H0YpWTScnY=; fh=96qtDnTU/URrOT6i7uaKTwabo9K0PbhXvr8DzFjxXtc=; b=TnXugsmwAkK4aBIswsDbvi58BE8C96hMe6TwDr9/TO2OSSFA5ra4xJpg8cLjecplgD uFD6oucB0lD5uR/xsbKMRJCeCbfXYZcSD8w39NTPBAUH2Fm4LuKg4iOZFrpciLD1Rj/N lBNWJY0wLQCrS1dH4dAovufmAsiBRPUENraJybaSGJX+hkD/zDsz5IlSSTQosUwuj45F yVkhS+q/iGO1JY0EQxaC/UzAq1ZUzA4irrSHySgz0oBsBs5U1IXB4Uz+ztEla5Ij9fKv 2bIt85jLFtflVG3nxQma2xhp+oMZoDcQpn1gMc5PTYDDtv0vncUQcKjcJQHIwP8rYXvD +BVQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id r189-20020a632bc6000000b00502f4fd0c16si5648827pgr.653.2023.06.26.08.11.04; Mon, 26 Jun 2023 08:11:17 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230409AbjFZOdj (ORCPT <rfc822;filip.gregor98@gmail.com> + 99 others); Mon, 26 Jun 2023 10:33:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48492 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229783AbjFZOdh (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Mon, 26 Jun 2023 10:33:37 -0400 Received: from mail.loongson.cn (mail.loongson.cn [114.242.206.163]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 6BF83194; Mon, 26 Jun 2023 07:33:34 -0700 (PDT) Received: from loongson.cn (unknown [10.20.42.43]) by gateway (Coremail) with SMTP id _____8CxqMW8oZlkiW8CAA--.3740S3; Mon, 26 Jun 2023 22:33:32 +0800 (CST) Received: from openarena.loongson.cn (unknown [10.20.42.43]) by localhost.localdomain (Coremail) with SMTP id AQAAf8CxvM67oZlk7cUJAA--.43395S2; Mon, 26 Jun 2023 22:33:31 +0800 (CST) From: Sui Jingfeng <suijingfeng@loongson.cn> To: Thierry Reding <thierry.reding@gmail.com>, Mikko Perttunen <mperttunen@nvidia.com>, David Airlie <airlied@gmail.com>, Daniel Vetter <daniel@ffwll.ch>, Jonathan Hunter <jonathanh@nvidia.com> Cc: dri-devel@lists.freedesktop.org, linux-tegra@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 1/2] drm/tegra: Return an error code if fails Date: Mon, 26 Jun 2023 22:33:30 +0800 Message-Id: <20230626143331.640454-1-suijingfeng@loongson.cn> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-CM-TRANSID: AQAAf8CxvM67oZlk7cUJAA--.43395S2 X-CM-SenderInfo: xvxlyxpqjiv03j6o00pqjv00gofq/ X-Coremail-Antispam: 1Uk129KBj9xXoWrXr17Kr17Kw15Zw4UGF48AFc_yoWxXrgEk3 W0qr47X34IkF4DZF1qvry3Xryayas5uFs7Z3ySy3s3Gw47Zr13XryUuryDur13u3ZxGF98 t3yIqFn8t3Z3GosvyTuYvTs0mTUanT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUj1kv1TuYvT s0mT0YCTnIWjqI5I8CrVACY4xI64kE6c02F40Ex7xfYxn0WfASr-VFAUDa7-sFnT9fnUUI cSsGvfJTRUUUb28YFVCjjxCrM7AC8VAFwI0_Jr0_Gr1l1xkIjI8I6I8E6xAIw20EY4v20x vaj40_Wr0E3s1l1IIY67AEw4v_JrI_Jryl8cAvFVAK0II2c7xJM28CjxkF64kEwVA0rcxS w2x7M28EF7xvwVC0I7IYx2IY67AKxVWUJVWUCwA2z4x0Y4vE2Ix0cI8IcVCY1x0267AKxV WUJVW8JwA2z4x0Y4vEx4A2jsIE14v26r4UJVWxJr1l84ACjcxK6I8E87Iv6xkF7I0E14v2 6r4UJVWxJr1le2I262IYc4CY6c8Ij28IcVAaY2xG8wAqjxCEc2xF0cIa020Ex4CE44I27w Aqx4xG64xvF2IEw4CE5I8CrVC2j2WlYx0E2Ix0cI8IcVAFwI0_JrI_JrylYx0Ex4A2jsIE 14v26r4j6F4UMcvjeVCFs4IE7xkEbVWUJVW8JwACjcxG0xvY0x0EwIxGrwCF04k20xvY0x 0EwIxGrwCFx2IqxVCFs4IE7xkEbVWUJVW8JwC20s026c02F40E14v26r1j6r18MI8I3I0E 7480Y4vE14v26r106r1rMI8E67AF67kF1VAFwI0_Jw0_GFylIxkGc2Ij64vIr41lIxAIcV C0I7IYx2IY67AKxVWUJVWUCwCI42IY6xIIjxv20xvEc7CjxVAFwI0_Jr0_Gr1lIxAIcVCF 04k26cxKx2IYs7xG6r1j6r1xMIIF0xvEx4A2jsIE14v26r1j6r4UMIIF0xvEx4A2jsIEc7 CjxVAFwI0_Gr0_Gr1UYxBIdaVFxhVjvjDU0xZFpf9x07j0sjUUUUUU= X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1769778474757352819?= X-GMAIL-MSGID: =?utf-8?q?1769778474757352819?= |
Series |
[1/2] drm/tegra: Return an error code if fails
|
|
Commit Message
Sui Jingfeng
June 26, 2023, 2:33 p.m. UTC
Return -ENOMEM if tegra_bo_mmap() fails.
Signed-off-by: Sui Jingfeng <suijingfeng@loongson.cn>
---
drivers/gpu/drm/tegra/gem.c | 2 ++
1 file changed, 2 insertions(+)
Comments
Hi, Gentle ping for this series. On 2023/6/26 22:33, Sui Jingfeng wrote: > Return -ENOMEM if tegra_bo_mmap() fails. > > Signed-off-by: Sui Jingfeng <suijingfeng@loongson.cn> > --- > drivers/gpu/drm/tegra/gem.c | 2 ++ > 1 file changed, 2 insertions(+) > > diff --git a/drivers/gpu/drm/tegra/gem.c b/drivers/gpu/drm/tegra/gem.c > index dea38892d6e6..0ce22935fbd3 100644 > --- a/drivers/gpu/drm/tegra/gem.c > +++ b/drivers/gpu/drm/tegra/gem.c > @@ -710,6 +710,8 @@ static int tegra_gem_prime_vmap(struct dma_buf *buf, struct iosys_map *map) > void *vaddr; > > vaddr = tegra_bo_mmap(&bo->base); > + if (!vaddr) > + return -ENOMEM; > if (IS_ERR(vaddr)) > return PTR_ERR(vaddr); >
On Mon, Jun 26, 2023 at 10:33:30PM +0800, Sui Jingfeng wrote: > Return -ENOMEM if tegra_bo_mmap() fails. > > Signed-off-by: Sui Jingfeng <suijingfeng@loongson.cn> > --- > drivers/gpu/drm/tegra/gem.c | 2 ++ > 1 file changed, 2 insertions(+) Sorry, this fell through the cracks. I think it'd be better if tegra_bo_mmap() were to be improved to always return either an ERR_PTR() encoded error code or a valid pointer. Throwing NULL into the mix isn't useful because it typically means something like -ENOMEM anyway. Error codes are more explicit, so since we're already using them for some cases, might as well return them for all. Actually, looks like tegra_bo_mmap() never actually returns an ERR_PTR() encoded error code. It's either obj->vaddr, the return value of vmap() (which is either NULL or the address of the mapping), or the address obtained from dma_buf_vmap_unlocked() (i.e. map.vaddr) or NULL on failure. So I think it would equally make sense to keep your patch and to remove the IS_ERR() check below it. I would slightly prefer the first option, but either is fine. Thierry > diff --git a/drivers/gpu/drm/tegra/gem.c b/drivers/gpu/drm/tegra/gem.c > index dea38892d6e6..0ce22935fbd3 100644 > --- a/drivers/gpu/drm/tegra/gem.c > +++ b/drivers/gpu/drm/tegra/gem.c > @@ -710,6 +710,8 @@ static int tegra_gem_prime_vmap(struct dma_buf *buf, struct iosys_map *map) > void *vaddr; > > vaddr = tegra_bo_mmap(&bo->base); > + if (!vaddr) > + return -ENOMEM; > if (IS_ERR(vaddr)) > return PTR_ERR(vaddr); > > -- > 2.25.1 >
On Tue, Oct 10, 2023 at 03:22:56PM +0200, Thierry Reding wrote: > On Mon, Jun 26, 2023 at 10:33:30PM +0800, Sui Jingfeng wrote: > > Return -ENOMEM if tegra_bo_mmap() fails. > > > > Signed-off-by: Sui Jingfeng <suijingfeng@loongson.cn> > > --- > > drivers/gpu/drm/tegra/gem.c | 2 ++ > > 1 file changed, 2 insertions(+) > > Sorry, this fell through the cracks. I think it'd be better if > tegra_bo_mmap() were to be improved to always return either an ERR_PTR() > encoded error code or a valid pointer. Throwing NULL into the mix isn't > useful because it typically means something like -ENOMEM anyway. Error > codes are more explicit, so since we're already using them for some > cases, might as well return them for all. > > Actually, looks like tegra_bo_mmap() never actually returns an ERR_PTR() > encoded error code. It's either obj->vaddr, the return value of vmap() > (which is either NULL or the address of the mapping), or the address > obtained from dma_buf_vmap_unlocked() (i.e. map.vaddr) or NULL on > failure. So I think it would equally make sense to keep your patch and > to remove the IS_ERR() check below it. > > I would slightly prefer the first option, but either is fine. How about the attached patch? Thierry From b34a09efcf7b1d2c25d3baf8c6d91c5ca09b4e0f Mon Sep 17 00:00:00 2001 From: Thierry Reding <treding@nvidia.com> Date: Tue, 10 Oct 2023 17:26:14 +0200 Subject: [PATCH] drm/tegra: gem: Do not return NULL in tegra_bo_mmap() It's confusing for a function to return NULL and ERR_PTR()-encoded error codes on failure. Make sure we only ever return the latter since that's what callers already expect. Signed-off-by: Thierry Reding <treding@nvidia.com> --- drivers/gpu/drm/tegra/gem.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/drivers/gpu/drm/tegra/gem.c b/drivers/gpu/drm/tegra/gem.c index 11296de59c5a..679460e05c05 100644 --- a/drivers/gpu/drm/tegra/gem.c +++ b/drivers/gpu/drm/tegra/gem.c @@ -178,6 +178,7 @@ static void *tegra_bo_mmap(struct host1x_bo *bo) { struct tegra_bo *obj = host1x_to_tegra_bo(bo); struct iosys_map map; + void *vaddr; int ret; if (obj->vaddr) @@ -185,10 +186,18 @@ static void *tegra_bo_mmap(struct host1x_bo *bo) if (obj->gem.import_attach) { ret = dma_buf_vmap_unlocked(obj->gem.import_attach->dmabuf, &map); - return ret ? NULL : map.vaddr; + if (ret < 0) + return ERR_PTR(ret); + + return map.vaddr; } - return vmap(obj->pages, obj->num_pages, VM_MAP, pgprot_writecombine(PAGE_KERNEL)); + vaddr = vmap(obj->pages, obj->num_pages, VM_MAP, + pgprot_writecombine(PAGE_KERNEL)); + if (!vaddr) + return -ENOMEM; + + return vaddr; } static void tegra_bo_munmap(struct host1x_bo *bo, void *addr)
Hi, On 2023/10/10 23:31, Thierry Reding wrote: > On Tue, Oct 10, 2023 at 03:22:56PM +0200, Thierry Reding wrote: >> On Mon, Jun 26, 2023 at 10:33:30PM +0800, Sui Jingfeng wrote: >>> Return -ENOMEM if tegra_bo_mmap() fails. >>> >>> Signed-off-by: Sui Jingfeng <suijingfeng@loongson.cn> >>> --- >>> drivers/gpu/drm/tegra/gem.c | 2 ++ >>> 1 file changed, 2 insertions(+) >> Sorry, this fell through the cracks. I think it'd be better if >> tegra_bo_mmap() were to be improved to always return either an ERR_PTR() >> encoded error code or a valid pointer. Throwing NULL into the mix isn't >> useful because it typically means something like -ENOMEM anyway. Error >> codes are more explicit, so since we're already using them for some >> cases, might as well return them for all. >> >> Actually, looks like tegra_bo_mmap() never actually returns an ERR_PTR() >> encoded error code. It's either obj->vaddr, the return value of vmap() >> (which is either NULL or the address of the mapping), or the address >> obtained from dma_buf_vmap_unlocked() (i.e. map.vaddr) or NULL on >> failure. So I think it would equally make sense to keep your patch and >> to remove the IS_ERR() check below it. >> >> I would slightly prefer the first option, but either is fine. > How about the attached patch? I also prefer the prefer the first option. The attached patch is more better, because it solve the problem at lower level. Reviewed-by: Sui Jingfeng <suijingfeng@loongson.cn> > Thierry
diff --git a/drivers/gpu/drm/tegra/gem.c b/drivers/gpu/drm/tegra/gem.c index dea38892d6e6..0ce22935fbd3 100644 --- a/drivers/gpu/drm/tegra/gem.c +++ b/drivers/gpu/drm/tegra/gem.c @@ -710,6 +710,8 @@ static int tegra_gem_prime_vmap(struct dma_buf *buf, struct iosys_map *map) void *vaddr; vaddr = tegra_bo_mmap(&bo->base); + if (!vaddr) + return -ENOMEM; if (IS_ERR(vaddr)) return PTR_ERR(vaddr);