* [PATCH 1/2] drm/tegra: Return an error code if fails @ 2023-06-26 14:33 Sui Jingfeng 2023-06-26 14:33 ` [PATCH 2/2] drm/tegra: Remove surplus else after return Sui Jingfeng ` (2 more replies) 0 siblings, 3 replies; 7+ messages in thread From: Sui Jingfeng @ 2023-06-26 14:33 UTC (permalink / raw) To: Thierry Reding, Mikko Perttunen, David Airlie, Daniel Vetter, Jonathan Hunter Cc: dri-devel, linux-tegra, linux-kernel 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); -- 2.25.1 ^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH 2/2] drm/tegra: Remove surplus else after return 2023-06-26 14:33 [PATCH 1/2] drm/tegra: Return an error code if fails Sui Jingfeng @ 2023-06-26 14:33 ` Sui Jingfeng 2023-10-10 15:28 ` Thierry Reding 2023-07-27 10:02 ` [1/2] drm/tegra: Return an error code if fails suijingfeng 2023-10-10 13:22 ` [PATCH 1/2] " Thierry Reding 2 siblings, 1 reply; 7+ messages in thread From: Sui Jingfeng @ 2023-06-26 14:33 UTC (permalink / raw) To: Thierry Reding, Mikko Perttunen, David Airlie, Daniel Vetter, Jonathan Hunter Cc: dri-devel, linux-tegra, linux-kernel else is not generally useful after return Signed-off-by: Sui Jingfeng <suijingfeng@loongson.cn> --- drivers/gpu/drm/tegra/gem.c | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/drivers/gpu/drm/tegra/gem.c b/drivers/gpu/drm/tegra/gem.c index 0ce22935fbd3..26d64f4545bd 100644 --- a/drivers/gpu/drm/tegra/gem.c +++ b/drivers/gpu/drm/tegra/gem.c @@ -180,15 +180,15 @@ static void *tegra_bo_mmap(struct host1x_bo *bo) struct iosys_map map; int ret; - if (obj->vaddr) { + if (obj->vaddr) return obj->vaddr; - } else if (obj->gem.import_attach) { + + if (obj->gem.import_attach) { ret = dma_buf_vmap_unlocked(obj->gem.import_attach->dmabuf, &map); return ret ? NULL : map.vaddr; - } else { - return vmap(obj->pages, obj->num_pages, VM_MAP, - pgprot_writecombine(PAGE_KERNEL)); } + + return vmap(obj->pages, obj->num_pages, VM_MAP, pgprot_writecombine(PAGE_KERNEL)); } static void tegra_bo_munmap(struct host1x_bo *bo, void *addr) @@ -198,10 +198,11 @@ static void tegra_bo_munmap(struct host1x_bo *bo, void *addr) if (obj->vaddr) return; - else if (obj->gem.import_attach) - dma_buf_vunmap_unlocked(obj->gem.import_attach->dmabuf, &map); - else - vunmap(addr); + + if (obj->gem.import_attach) + return dma_buf_vunmap_unlocked(obj->gem.import_attach->dmabuf, &map); + + vunmap(addr); } static struct host1x_bo *tegra_bo_get(struct host1x_bo *bo) -- 2.25.1 ^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [PATCH 2/2] drm/tegra: Remove surplus else after return 2023-06-26 14:33 ` [PATCH 2/2] drm/tegra: Remove surplus else after return Sui Jingfeng @ 2023-10-10 15:28 ` Thierry Reding 0 siblings, 0 replies; 7+ messages in thread From: Thierry Reding @ 2023-10-10 15:28 UTC (permalink / raw) To: Sui Jingfeng Cc: Mikko Perttunen, David Airlie, Daniel Vetter, Jonathan Hunter, dri-devel, linux-tegra, linux-kernel [-- Attachment #1: Type: text/plain, Size: 317 bytes --] On Mon, Jun 26, 2023 at 10:33:31PM +0800, Sui Jingfeng wrote: > else is not generally useful after return > > Signed-off-by: Sui Jingfeng <suijingfeng@loongson.cn> > --- > drivers/gpu/drm/tegra/gem.c | 19 ++++++++++--------- > 1 file changed, 10 insertions(+), 9 deletions(-) Applied, thanks. Thierry [-- Attachment #2: signature.asc --] [-- Type: application/pgp-signature, Size: 833 bytes --] ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [1/2] drm/tegra: Return an error code if fails 2023-06-26 14:33 [PATCH 1/2] drm/tegra: Return an error code if fails Sui Jingfeng 2023-06-26 14:33 ` [PATCH 2/2] drm/tegra: Remove surplus else after return Sui Jingfeng @ 2023-07-27 10:02 ` suijingfeng 2023-10-10 13:22 ` [PATCH 1/2] " Thierry Reding 2 siblings, 0 replies; 7+ messages in thread From: suijingfeng @ 2023-07-27 10:02 UTC (permalink / raw) To: Thierry Reding, Mikko Perttunen, David Airlie, Daniel Vetter, Jonathan Hunter Cc: linux-tegra, linux-kernel, dri-devel 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); > ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH 1/2] drm/tegra: Return an error code if fails 2023-06-26 14:33 [PATCH 1/2] drm/tegra: Return an error code if fails Sui Jingfeng 2023-06-26 14:33 ` [PATCH 2/2] drm/tegra: Remove surplus else after return Sui Jingfeng 2023-07-27 10:02 ` [1/2] drm/tegra: Return an error code if fails suijingfeng @ 2023-10-10 13:22 ` Thierry Reding 2023-10-10 15:31 ` Thierry Reding 2 siblings, 1 reply; 7+ messages in thread From: Thierry Reding @ 2023-10-10 13:22 UTC (permalink / raw) To: Sui Jingfeng Cc: Mikko Perttunen, David Airlie, Daniel Vetter, Jonathan Hunter, dri-devel, linux-tegra, linux-kernel [-- Attachment #1: Type: text/plain, Size: 1592 bytes --] 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 > [-- Attachment #2: signature.asc --] [-- Type: application/pgp-signature, Size: 833 bytes --] ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH 1/2] drm/tegra: Return an error code if fails 2023-10-10 13:22 ` [PATCH 1/2] " Thierry Reding @ 2023-10-10 15:31 ` Thierry Reding 2023-10-11 3:06 ` Sui Jingfeng 0 siblings, 1 reply; 7+ messages in thread From: Thierry Reding @ 2023-10-10 15:31 UTC (permalink / raw) To: Sui Jingfeng Cc: Mikko Perttunen, David Airlie, Daniel Vetter, Jonathan Hunter, dri-devel, linux-tegra, linux-kernel [-- Attachment #1.1: Type: text/plain, Size: 1264 bytes --] 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 [-- Attachment #1.2: 0001-drm-tegra-gem-Do-not-return-NULL-in-tegra_bo_mmap.patch --] [-- Type: text/plain, Size: 1561 bytes --] 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) -- 2.42.0 [-- Attachment #2: signature.asc --] [-- Type: application/pgp-signature, Size: 833 bytes --] ^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [PATCH 1/2] drm/tegra: Return an error code if fails 2023-10-10 15:31 ` Thierry Reding @ 2023-10-11 3:06 ` Sui Jingfeng 0 siblings, 0 replies; 7+ messages in thread From: Sui Jingfeng @ 2023-10-11 3:06 UTC (permalink / raw) To: Thierry Reding Cc: Mikko Perttunen, David Airlie, Daniel Vetter, Jonathan Hunter, dri-devel, linux-tegra, linux-kernel 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 ^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2023-10-11 3:06 UTC | newest] Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2023-06-26 14:33 [PATCH 1/2] drm/tegra: Return an error code if fails Sui Jingfeng 2023-06-26 14:33 ` [PATCH 2/2] drm/tegra: Remove surplus else after return Sui Jingfeng 2023-10-10 15:28 ` Thierry Reding 2023-07-27 10:02 ` [1/2] drm/tegra: Return an error code if fails suijingfeng 2023-10-10 13:22 ` [PATCH 1/2] " Thierry Reding 2023-10-10 15:31 ` Thierry Reding 2023-10-11 3:06 ` Sui Jingfeng
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for NNTP newsgroup(s).