* [PATCH] drm/panthor: Fix NULL vs IS_ERR() bug in panthor_ioctl_tiler_heap_destroy()
@ 2024-04-02 10:33 Harshit Mogalapalli
2024-04-02 12:33 ` Boris Brezillon
0 siblings, 1 reply; 4+ messages in thread
From: Harshit Mogalapalli @ 2024-04-02 10:33 UTC (permalink / raw)
To: Boris Brezillon, Steven Price, Liviu Dudau, Maarten Lankhorst,
Maxime Ripard, Thomas Zimmermann, David Airlie, Daniel Vetter,
Heiko Stuebner, dri-devel, linux-kernel
Cc: dan.carpenter, kernel-janitors, error27, harshit.m.mogalapalli
panthor_vm_get_heap_pool() returns ERR_PTR on failure.
Fixes: 4bdca1150792 ("drm/panthor: Add the driver frontend block")
Signed-off-by: Harshit Mogalapalli <harshit.m.mogalapalli@oracle.com>
---
This is spotted by smatch and the patch is only compile tested
---
drivers/gpu/drm/panthor/panthor_drv.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/drivers/gpu/drm/panthor/panthor_drv.c b/drivers/gpu/drm/panthor/panthor_drv.c
index 11b3ccd58f85..050b905b0453 100644
--- a/drivers/gpu/drm/panthor/panthor_drv.c
+++ b/drivers/gpu/drm/panthor/panthor_drv.c
@@ -1090,8 +1090,8 @@ static int panthor_ioctl_tiler_heap_destroy(struct drm_device *ddev, void *data,
return -EINVAL;
pool = panthor_vm_get_heap_pool(vm, false);
- if (!pool) {
- ret = -EINVAL;
+ if (IS_ERR(pool)) {
+ ret = PTR_ERR(pool);
goto out_put_vm;
}
--
2.39.3
^ permalink raw reply related [flat|nested] 4+ messages in thread* Re: [PATCH] drm/panthor: Fix NULL vs IS_ERR() bug in panthor_ioctl_tiler_heap_destroy() 2024-04-02 10:33 [PATCH] drm/panthor: Fix NULL vs IS_ERR() bug in panthor_ioctl_tiler_heap_destroy() Harshit Mogalapalli @ 2024-04-02 12:33 ` Boris Brezillon 2024-04-02 13:22 ` Harshit Mogalapalli 0 siblings, 1 reply; 4+ messages in thread From: Boris Brezillon @ 2024-04-02 12:33 UTC (permalink / raw) To: Harshit Mogalapalli Cc: Steven Price, Liviu Dudau, Maarten Lankhorst, Maxime Ripard, Thomas Zimmermann, David Airlie, Daniel Vetter, Heiko Stuebner, dri-devel, linux-kernel, dan.carpenter, kernel-janitors, error27 Hello Harshit, On Tue, 2 Apr 2024 03:33:58 -0700 Harshit Mogalapalli <harshit.m.mogalapalli@oracle.com> wrote: > panthor_vm_get_heap_pool() returns ERR_PTR on failure. > > Fixes: 4bdca1150792 ("drm/panthor: Add the driver frontend block") > Signed-off-by: Harshit Mogalapalli <harshit.m.mogalapalli@oracle.com> > --- > This is spotted by smatch and the patch is only compile tested > --- > drivers/gpu/drm/panthor/panthor_drv.c | 4 ++-- > 1 file changed, 2 insertions(+), 2 deletions(-) > > diff --git a/drivers/gpu/drm/panthor/panthor_drv.c b/drivers/gpu/drm/panthor/panthor_drv.c > index 11b3ccd58f85..050b905b0453 100644 > --- a/drivers/gpu/drm/panthor/panthor_drv.c > +++ b/drivers/gpu/drm/panthor/panthor_drv.c > @@ -1090,8 +1090,8 @@ static int panthor_ioctl_tiler_heap_destroy(struct drm_device *ddev, void *data, > return -EINVAL; > > pool = panthor_vm_get_heap_pool(vm, false); > - if (!pool) { > - ret = -EINVAL; > + if (IS_ERR(pool)) { > + ret = PTR_ERR(pool); Actually, panthor_vm_get_heap_pool() will return NULL if there's no heap pool attached to this VM and create=false, so this was correct. This being said, I'm fine making that consistent by returning ERR_PTR(-ENOENT) instead of NULL in that case. This way we don't have two different semantics based on the 'create' value. Oh, and please merge everything into a single patch instead of one patch per call-site. Regards, Boris > goto out_put_vm; > } > ^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] drm/panthor: Fix NULL vs IS_ERR() bug in panthor_ioctl_tiler_heap_destroy() 2024-04-02 12:33 ` Boris Brezillon @ 2024-04-02 13:22 ` Harshit Mogalapalli 2024-04-02 13:25 ` Boris Brezillon 0 siblings, 1 reply; 4+ messages in thread From: Harshit Mogalapalli @ 2024-04-02 13:22 UTC (permalink / raw) To: Boris Brezillon Cc: Steven Price, Liviu Dudau, Maarten Lankhorst, Maxime Ripard, Thomas Zimmermann, David Airlie, Daniel Vetter, Heiko Stuebner, dri-devel, linux-kernel, dan.carpenter, kernel-janitors, error27 Hello Boris, On 02/04/24 18:03, Boris Brezillon wrote: > Hello Harshit, > > On Tue, 2 Apr 2024 03:33:58 -0700 > Harshit Mogalapalli <harshit.m.mogalapalli@oracle.com> wrote: > >> panthor_vm_get_heap_pool() returns ERR_PTR on failure. >> >> Fixes: 4bdca1150792 ("drm/panthor: Add the driver frontend block") >> Signed-off-by: Harshit Mogalapalli <harshit.m.mogalapalli@oracle.com> >> --- >> This is spotted by smatch and the patch is only compile tested >> --- >> drivers/gpu/drm/panthor/panthor_drv.c | 4 ++-- >> 1 file changed, 2 insertions(+), 2 deletions(-) >> >> diff --git a/drivers/gpu/drm/panthor/panthor_drv.c b/drivers/gpu/drm/panthor/panthor_drv.c >> index 11b3ccd58f85..050b905b0453 100644 >> --- a/drivers/gpu/drm/panthor/panthor_drv.c >> +++ b/drivers/gpu/drm/panthor/panthor_drv.c >> @@ -1090,8 +1090,8 @@ static int panthor_ioctl_tiler_heap_destroy(struct drm_device *ddev, void *data, >> return -EINVAL; >> >> pool = panthor_vm_get_heap_pool(vm, false); >> - if (!pool) { >> - ret = -EINVAL; >> + if (IS_ERR(pool)) { >> + ret = PTR_ERR(pool); > > Actually, panthor_vm_get_heap_pool() will return NULL if there's no > heap pool attached to this VM and create=false, so this was correct. > This being said, I'm fine making that consistent by returning > ERR_PTR(-ENOENT) instead of NULL in that case. This way we don't have > two different semantics based on the 'create' value. > Thanks for explaining. I missed the case where create is false and there is no heap pool attached, so panthor_vm_get_heap_pool() can return NULL. 1878 * 1879 * Return: A valid pointer on success, an ERR_PTR() otherwise. 1880 */ 1881 struct panthor_heap_pool *panthor_vm_get_heap_pool(struct panthor_vm *vm, bool create) The documentation says it returns ERR_PTR() on failure, so is it worth doing something like: diff --git a/drivers/gpu/drm/panthor/panthor_mmu.c b/drivers/gpu/drm/panthor/panthor_mmu.c index fdd35249169f..e1285cdb09ff 100644 --- a/drivers/gpu/drm/panthor/panthor_mmu.c +++ b/drivers/gpu/drm/panthor/panthor_mmu.c @@ -1893,6 +1893,8 @@ struct panthor_heap_pool *panthor_vm_get_heap_pool(struct panthor_vm *vm, bool c vm->heaps.pool = panthor_heap_pool_get(pool); } else { pool = panthor_heap_pool_get(vm->heaps.pool); + if (!pool) + pool = ERR_PTR(-ENOENT); } mutex_unlock(&vm->heaps.lock); and change all callers of panthor_vm_get_heap_pool() to only check for IS_ERR() ? > Oh, and please merge everything into a single patch instead of one patch > per call-site. > Sure, I noticed one after the other. I will fix them together in v2. Thanks, Harshit > Regards, > > Boris > >> goto out_put_vm; >> } >> > ^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH] drm/panthor: Fix NULL vs IS_ERR() bug in panthor_ioctl_tiler_heap_destroy() 2024-04-02 13:22 ` Harshit Mogalapalli @ 2024-04-02 13:25 ` Boris Brezillon 0 siblings, 0 replies; 4+ messages in thread From: Boris Brezillon @ 2024-04-02 13:25 UTC (permalink / raw) To: Harshit Mogalapalli Cc: Steven Price, Liviu Dudau, Maarten Lankhorst, Maxime Ripard, Thomas Zimmermann, David Airlie, Daniel Vetter, Heiko Stuebner, dri-devel, linux-kernel, dan.carpenter, kernel-janitors, error27 On Tue, 2 Apr 2024 18:52:12 +0530 Harshit Mogalapalli <harshit.m.mogalapalli@oracle.com> wrote: > Hello Boris, > > On 02/04/24 18:03, Boris Brezillon wrote: > > Hello Harshit, > > > > On Tue, 2 Apr 2024 03:33:58 -0700 > > Harshit Mogalapalli <harshit.m.mogalapalli@oracle.com> wrote: > > > >> panthor_vm_get_heap_pool() returns ERR_PTR on failure. > >> > >> Fixes: 4bdca1150792 ("drm/panthor: Add the driver frontend block") > >> Signed-off-by: Harshit Mogalapalli <harshit.m.mogalapalli@oracle.com> > >> --- > >> This is spotted by smatch and the patch is only compile tested > >> --- > >> drivers/gpu/drm/panthor/panthor_drv.c | 4 ++-- > >> 1 file changed, 2 insertions(+), 2 deletions(-) > >> > >> diff --git a/drivers/gpu/drm/panthor/panthor_drv.c b/drivers/gpu/drm/panthor/panthor_drv.c > >> index 11b3ccd58f85..050b905b0453 100644 > >> --- a/drivers/gpu/drm/panthor/panthor_drv.c > >> +++ b/drivers/gpu/drm/panthor/panthor_drv.c > >> @@ -1090,8 +1090,8 @@ static int panthor_ioctl_tiler_heap_destroy(struct drm_device *ddev, void *data, > >> return -EINVAL; > >> > >> pool = panthor_vm_get_heap_pool(vm, false); > >> - if (!pool) { > >> - ret = -EINVAL; > >> + if (IS_ERR(pool)) { > >> + ret = PTR_ERR(pool); > > > > Actually, panthor_vm_get_heap_pool() will return NULL if there's no > > heap pool attached to this VM and create=false, so this was correct. > > This being said, I'm fine making that consistent by returning > > ERR_PTR(-ENOENT) instead of NULL in that case. This way we don't have > > two different semantics based on the 'create' value. > > > > Thanks for explaining. I missed the case where create is false and there > is no heap pool attached, so panthor_vm_get_heap_pool() can return NULL. > > 1878 * > 1879 * Return: A valid pointer on success, an ERR_PTR() otherwise. > 1880 */ > 1881 struct panthor_heap_pool *panthor_vm_get_heap_pool(struct > panthor_vm *vm, bool create) > > The documentation says it returns ERR_PTR() on failure, so is it worth > doing something like: > > diff --git a/drivers/gpu/drm/panthor/panthor_mmu.c > b/drivers/gpu/drm/panthor/panthor_mmu.c > index fdd35249169f..e1285cdb09ff 100644 > --- a/drivers/gpu/drm/panthor/panthor_mmu.c > +++ b/drivers/gpu/drm/panthor/panthor_mmu.c > @@ -1893,6 +1893,8 @@ struct panthor_heap_pool > *panthor_vm_get_heap_pool(struct panthor_vm *vm, bool c > vm->heaps.pool = panthor_heap_pool_get(pool); > } else { > pool = panthor_heap_pool_get(vm->heaps.pool); > + if (!pool) > + pool = ERR_PTR(-ENOENT); > } > mutex_unlock(&vm->heaps.lock); > > > and change all callers of panthor_vm_get_heap_pool() to only check for > IS_ERR() ? Yep, that's what I had in mind. > > > > Oh, and please merge everything into a single patch instead of one patch > > per call-site. > > > > Sure, I noticed one after the other. I will fix them together in v2. Great! Thanks, Boris ^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2024-04-02 13:25 UTC | newest] Thread overview: 4+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2024-04-02 10:33 [PATCH] drm/panthor: Fix NULL vs IS_ERR() bug in panthor_ioctl_tiler_heap_destroy() Harshit Mogalapalli 2024-04-02 12:33 ` Boris Brezillon 2024-04-02 13:22 ` Harshit Mogalapalli 2024-04-02 13:25 ` Boris Brezillon
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox