drm/gem: Fix a GEM leak in drm_gem_get_unmapped_area()
Subsystems (2)
PATCH 1/1 drm/gem: Fix a GEM leak in drm_gem_get_unmapped_area()
drm_gem_object_lookup_at_offset() can return a valid object with filp or filp->f_op->get_unmapped_area set to NULL. Make sure we still release the ref we acquired on such objects.
--- drivers/gpu/drm/drm_gem.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-)
drivers/gpu/drm/drm_gem.c +6 -4
@@ -1298,11 +1298,13 @@ unsigned long drm_gem_get_unmapped_area(struct file *filp, unsigned long uaddr,unsigned long ret; obj =drm_gem_object_lookup_at_offset (filp, pgoff, len >>PAGE_SHIFT ); -if (IS_ERR (obj) || !obj->filp || !obj->filp->f_op->get_unmapped_area) -return mm_get_unmapped_area (filp, uaddr, len,0 , flags); +if (IS_ERR (obj)) + obj =NULL ; - ret = obj->filp->f_op->get_unmapped_area (obj->filp, uaddr, len,0 , - flags); +if (!obj || !obj->filp || !obj->filp->f_op->get_unmapped_area) + ret =mm_get_unmapped_area (filp, uaddr, len,0 , flags); +else + ret = obj->filp->f_op->get_unmapped_area (obj->filp, uaddr, len,0 , flags);drm_gem_object_put (obj);
Signature · 1 line
2.52.0
Quoted 18 lines · On Tue, 6 Jan 2026 17:49:35 +0100 Boris Brezillon…
drm_gem_object_lookup_at_offset()can return a valid object with filp orfilp->f_op->get_unmapped_areaset to NULL. Make sure we still release the ref we acquired on such objects.Cc Loïc Molinari <[email protected]>Fixes 99bda20d6d4c ("drm/gem: Introduce drm_gem_get_unmapped_area() fop")Signed-off-by Boris Brezillon <[email protected]>--- drivers/gpu/drm/drm_gem.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-)drivers/gpu/drm/drm_gem.c +0
-0@@ -1298,11 +1298,13 @@ unsigned long drm_gem_get_unmapped_area(struct file *filp, unsigned long uaddr,unsigned long ret;
drivers/gpu/drm/drm_gem.c unsigned long drm_gem_get_unmapped_area(struct file *filp, unsigned long uaddr, · line 1305
Quoted 10 lines
drivers/gpu/drm/drm_gem.c +4
-4obj =drm_gem_object_lookup_at_offset (filp, pgoff, len >>PAGE_SHIFT ); -if (IS_ERR (obj) || !obj->filp || !obj->filp->f_op->get_unmapped_area) -return mm_get_unmapped_area (filp, uaddr, len,0 , flags); +if (IS_ERR (obj)) + obj =NULL ; - ret = obj->filp->f_op->get_unmapped_area (obj->filp, uaddr, len,0 , - flags); +if (!obj || !obj->filp || !obj->filp->f_op->get_unmapped_area) + ret =mm_get_unmapped_area (filp, uaddr, len,0 , flags);
Also, I'm wondering if we shouldn't pass pgoff instead of zero here to have the exact same behavior that existed before drm_gem_get_unmapped_area() was introduced.
Quoted 5 lines
drivers/gpu/drm/drm_gem.c +2
-0+else + ret = obj->filp->f_op->get_unmapped_area (obj->filp, uaddr, len,0 , flags);drm_gem_object_put (obj);
Quoted 27 lines · Boris Brezillon
Quoted 24 lines · On Tue, 6 Jan 2026 17:49:35 +0100 Boris Brezillon…
drm_gem_object_lookup_at_offset()can return a valid object with filp orfilp->f_op->get_unmapped_areaset to NULL. Make sure we still release the ref we acquired on such objects.Cc Loïc Molinari <[email protected]>Fixes 99bda20d6d4c ("drm/gem: Introduce drm_gem_get_unmapped_area() fop")Signed-off-by Boris Brezillon <[email protected]>--- drivers/gpu/drm/drm_gem.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-)drivers/gpu/drm/drm_gem.c +2
-2@@ -1298,11 +1298,13 @@ unsigned long drm_gem_get_unmapped_area(struct file *filp, unsigned long uaddr,unsigned long ret; obj =drm_gem_object_lookup_at_offset (filp, pgoff, len >>PAGE_SHIFT ); -if (IS_ERR (obj) || !obj->filp || !obj->filp->f_op->get_unmapped_area) -return mm_get_unmapped_area (filp, uaddr, len,0 , flags); +if (IS_ERR (obj)) + obj =NULL ;
Quoted 9 lines
drivers/gpu/drm/drm_gem.c unsigned long drm_gem_get_unmapped_area(struct file *filp, unsigned long uaddr, · line 1305
Quoted 4 lines
drivers/gpu/drm/drm_gem.c +2
-2- ret = obj->filp->f_op->get_unmapped_area (obj->filp, uaddr, len,0 , - flags); +if (!obj || !obj->filp || !obj->filp->f_op->get_unmapped_area) + ret =mm_get_unmapped_area (filp, uaddr, len,0 , flags);Also, I'm wondering if we shouldn't pass pgoff instead of zero here to have the exact same behavior that existed before
drm_gem_get_unmapped_area()was introduced.
For mappings with a file (the DRM file in our case), if filp->f_op->get_unmapped_area isn't set then generic_get_unmapped_area() is used and it ignores the pgoff argument. So it wasn't 0 before but was ignored anyway. I don't mind passing pgoff but I find it simpler like that.
Regards,
Loïc
Quoted 6 lines
Quoted 5 lines
drivers/gpu/drm/drm_gem.c +2
-0+else + ret = obj->filp->f_op->get_unmapped_area (obj->filp, uaddr, len,0 , flags);drm_gem_object_put (obj);
Quoted 38 lines · On Thu, 8 Jan 2026 14:25:01 +0100 Loïc Molinari <[email protected]>…
Quoted 27 lines · Boris Brezillon
Quoted 24 lines · On Tue, 6 Jan 2026 17:49:35 +0100 Boris Brezillon…
drm_gem_object_lookup_at_offset()can return a valid object with filp orfilp->f_op->get_unmapped_areaset to NULL. Make sure we still release the ref we acquired on such objects.Cc Loïc Molinari <[email protected]>Fixes 99bda20d6d4c ("drm/gem: Introduce drm_gem_get_unmapped_area() fop")Signed-off-by Boris Brezillon <[email protected]>--- drivers/gpu/drm/drm_gem.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-)drivers/gpu/drm/drm_gem.c +2
-2@@ -1298,11 +1298,13 @@ unsigned long drm_gem_get_unmapped_area(struct file *filp, unsigned long uaddr,unsigned long ret; obj =drm_gem_object_lookup_at_offset (filp, pgoff, len >>PAGE_SHIFT ); -if (IS_ERR (obj) || !obj->filp || !obj->filp->f_op->get_unmapped_area) -return mm_get_unmapped_area (filp, uaddr, len,0 , flags); +if (IS_ERR (obj)) + obj =NULL ;Quoted 9 lines
drivers/gpu/drm/drm_gem.c unsigned long drm_gem_get_unmapped_area(struct file *filp, unsigned long uaddr, · line 1305
Quoted 4 lines
drivers/gpu/drm/drm_gem.c +2
-2- ret = obj->filp->f_op->get_unmapped_area (obj->filp, uaddr, len,0 , - flags); +if (!obj || !obj->filp || !obj->filp->f_op->get_unmapped_area) + ret =mm_get_unmapped_area (filp, uaddr, len,0 , flags);Also, I'm wondering if we shouldn't pass pgoff instead of zero here to have the exact same behavior that existed before
drm_gem_get_unmapped_area()was introduced.
Quoted 3 lines
For mappings with a file (the DRM file in our case), if
filp->f_op->get_unmapped_areaisn't set thengeneric_get_unmapped_area()is used and it ignores the pgoff argument.
That's true for architectures that rely on the default implementation (Arm64 for instance), but other architectures might have their own implementation.
Quoted 2 lines
So it wasn't 0 before but was
ignored anyway.
Didn't check all of them but the Arm implementation does take this pgoff into account if I read the code correctly [1]. The fact this argument is passed around makes me think other architectures might take this into account too. I know this pgoff is just a fake offset into the /dev/dri pseudo-file, but if we want to err on the safe side, we'd rather do exactly what was done before drm_gem_get_unmapped_area() was introduced for the ->filp==NULL case. That's just my 2 cts, of course.
Regards,
Boris
[1]https://elixir.bootlin.com/linux/v6.18.3/source/arch/arm/mm/mmap.c#L30
Quoted 53 lines · Boris Brezillon
Quoted 38 lines · On Thu, 8 Jan 2026 14:25:01 +0100 Loïc Molinari <[email protected]>…
Quoted 27 lines · Boris Brezillon
Quoted 24 lines · On Tue, 6 Jan 2026 17:49:35 +0100 Boris Brezillon…
drm_gem_object_lookup_at_offset()can return a valid object with filp orfilp->f_op->get_unmapped_areaset to NULL. Make sure we still release the ref we acquired on such objects.Cc Loïc Molinari <[email protected]>Fixes 99bda20d6d4c ("drm/gem: Introduce drm_gem_get_unmapped_area() fop")Signed-off-by Boris Brezillon <[email protected]>--- drivers/gpu/drm/drm_gem.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-)drivers/gpu/drm/drm_gem.c +2
-2@@ -1298,11 +1298,13 @@ unsigned long drm_gem_get_unmapped_area(struct file *filp, unsigned long uaddr,unsigned long ret; obj =drm_gem_object_lookup_at_offset (filp, pgoff, len >>PAGE_SHIFT ); -if (IS_ERR (obj) || !obj->filp || !obj->filp->f_op->get_unmapped_area) -return mm_get_unmapped_area (filp, uaddr, len,0 , flags); +if (IS_ERR (obj)) + obj =NULL ;Quoted 9 lines
drivers/gpu/drm/drm_gem.c unsigned long drm_gem_get_unmapped_area(struct file *filp, unsigned long uaddr, · line 1305
Quoted 4 lines
drivers/gpu/drm/drm_gem.c +2
-2- ret = obj->filp->f_op->get_unmapped_area (obj->filp, uaddr, len,0 , - flags); +if (!obj || !obj->filp || !obj->filp->f_op->get_unmapped_area) + ret =mm_get_unmapped_area (filp, uaddr, len,0 , flags);Also, I'm wondering if we shouldn't pass pgoff instead of zero here to have the exact same behavior that existed before
drm_gem_get_unmapped_area()was introduced.Quoted 3 lines
For mappings with a file (the DRM file in our case), if
filp->f_op->get_unmapped_areaisn't set thengeneric_get_unmapped_area()is used and it ignores the pgoff argument.That's true for architectures that rely on the default implementation (Arm64 for instance), but other architectures might have their own implementation.
Quoted 2 lines
So it wasn't 0 before but was
ignored anyway.
Quoted 7 lines
Didn't check all of them but the Arm implementation does take this pgoff into account if I read the code correctly [1]. The fact this argument is passed around makes me think other architectures might take this into account too. I know this pgoff is just a fake offset into the
/dev/dripseudo-file, but if we want to err on the safe side, we'd rather do exactly what was done beforedrm_gem_get_unmapped_area()was introduced for the ->filp==NULL case. That's just my 2 cts, of course.
You're right, I focused on arm64 here and there's obviously other archs so we'd better pass pgoff for the fallback case.
Quoted 5 lines
Regards,
Boris
[1]https://elixir.bootlin.com/linux/v6.18.3/source/arch/arm/mm/mmap.c#L30
Quoted 62 lines · On Thu, 8 Jan 2026 15:04:33 +0100 Loïc Molinari <[email protected]>…
Quoted 53 lines · Boris Brezillon
Quoted 38 lines · On Thu, 8 Jan 2026 14:25:01 +0100 Loïc Molinari <[email protected]>…
Quoted 27 lines · Boris Brezillon
Quoted 24 lines · On Tue, 6 Jan 2026 17:49:35 +0100 Boris Brezillon…
drm_gem_object_lookup_at_offset()can return a valid object with filp orfilp->f_op->get_unmapped_areaset to NULL. Make sure we still release the ref we acquired on such objects.Cc Loïc Molinari <[email protected]>Fixes 99bda20d6d4c ("drm/gem: Introduce drm_gem_get_unmapped_area() fop")Signed-off-by Boris Brezillon <[email protected]>--- drivers/gpu/drm/drm_gem.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-)drivers/gpu/drm/drm_gem.c +2
-2@@ -1298,11 +1298,13 @@ unsigned long drm_gem_get_unmapped_area(struct file *filp, unsigned long uaddr,unsigned long ret; obj =drm_gem_object_lookup_at_offset (filp, pgoff, len >>PAGE_SHIFT ); -if (IS_ERR (obj) || !obj->filp || !obj->filp->f_op->get_unmapped_area) -return mm_get_unmapped_area (filp, uaddr, len,0 , flags); +if (IS_ERR (obj)) + obj =NULL ;Quoted 9 lines
drivers/gpu/drm/drm_gem.c unsigned long drm_gem_get_unmapped_area(struct file *filp, unsigned long uaddr, · line 1305
Quoted 4 lines
drivers/gpu/drm/drm_gem.c +2
-2- ret = obj->filp->f_op->get_unmapped_area (obj->filp, uaddr, len,0 , - flags); +if (!obj || !obj->filp || !obj->filp->f_op->get_unmapped_area) + ret =mm_get_unmapped_area (filp, uaddr, len,0 , flags);Also, I'm wondering if we shouldn't pass pgoff instead of zero here to have the exact same behavior that existed before
drm_gem_get_unmapped_area()was introduced.Quoted 3 lines
For mappings with a file (the DRM file in our case), if
filp->f_op->get_unmapped_areaisn't set thengeneric_get_unmapped_area()is used and it ignores the pgoff argument.That's true for architectures that rely on the default implementation (Arm64 for instance), but other architectures might have their own implementation.
Quoted 2 lines
So it wasn't 0 before but was
ignored anyway.Quoted 7 lines
Didn't check all of them but the Arm implementation does take this pgoff into account if I read the code correctly [1]. The fact this argument is passed around makes me think other architectures might take this into account too. I know this pgoff is just a fake offset into the
/dev/dripseudo-file, but if we want to err on the safe side, we'd rather do exactly what was done beforedrm_gem_get_unmapped_area()was introduced for the ->filp==NULL case. That's just my 2 cts, of course.
Quoted 2 lines
You're right, I focused on arm64 here and there's obviously other archs so we'd better pass pgoff for the fallback case.
Do you want me to send a patch doing that, or should I take care of it?
Hi Boris,
Quoted 65 lines · Boris Brezillon
Quoted 62 lines · On Thu, 8 Jan 2026 15:04:33 +0100 Loïc Molinari <[email protected]>…
Quoted 60 lines · Boris Brezillon
Quoted 38 lines · On Thu, 8 Jan 2026 14:25:01 +0100 Loïc Molinari <[email protected]>…
Quoted 27 lines · Boris Brezillon
Quoted 24 lines · On Tue, 6 Jan 2026 17:49:35 +0100 Boris Brezillon…
drm_gem_object_lookup_at_offset()can return a valid object with filp orfilp->f_op->get_unmapped_areaset to NULL. Make sure we still release the ref we acquired on such objects.Cc Loïc Molinari <[email protected]>Fixes 99bda20d6d4c ("drm/gem: Introduce drm_gem_get_unmapped_area() fop")Signed-off-by Boris Brezillon <[email protected]>--- drivers/gpu/drm/drm_gem.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-)drivers/gpu/drm/drm_gem.c +2
-2@@ -1298,11 +1298,13 @@ unsigned long drm_gem_get_unmapped_area(struct file *filp, unsigned long uaddr,unsigned long ret; obj =drm_gem_object_lookup_at_offset (filp, pgoff, len >>PAGE_SHIFT ); -if (IS_ERR (obj) || !obj->filp || !obj->filp->f_op->get_unmapped_area) -return mm_get_unmapped_area (filp, uaddr, len,0 , flags); +if (IS_ERR (obj)) + obj =NULL ;Quoted 9 lines
drivers/gpu/drm/drm_gem.c unsigned long drm_gem_get_unmapped_area(struct file *filp, unsigned long uaddr, · line 1305
Quoted 4 lines
drivers/gpu/drm/drm_gem.c +2
-2- ret = obj->filp->f_op->get_unmapped_area (obj->filp, uaddr, len,0 , - flags); +if (!obj || !obj->filp || !obj->filp->f_op->get_unmapped_area) + ret =mm_get_unmapped_area (filp, uaddr, len,0 , flags);Also, I'm wondering if we shouldn't pass pgoff instead of zero here to have the exact same behavior that existed before
drm_gem_get_unmapped_area()was introduced.Quoted 3 lines
For mappings with a file (the DRM file in our case), if
filp->f_op->get_unmapped_areaisn't set thengeneric_get_unmapped_area()is used and it ignores the pgoff argument.That's true for architectures that rely on the default implementation (Arm64 for instance), but other architectures might have their own implementation.
Quoted 2 lines
So it wasn't 0 before but was
ignored anyway.Didn't check all of them but the Arm implementation does take this pgoff into account if I read the code correctly [1]. The fact this argument is passed around makes me think other architectures might take this into account too. I know this pgoff is just a fake offset into the
/dev/dripseudo-file, but if we want to err on the safe side, we'd rather do exactly what was done beforedrm_gem_get_unmapped_area()was introduced for the ->filp==NULL case. That's just my 2 cts, of course.
Quoted 4 lines
Quoted 2 lines
You're right, I focused on arm64 here and there's obviously other archs so we'd better pass pgoff for the fallback case.
Do you want me to send a patch doing that, or should I take care of it?
I'll take care of it. I'd better wait for that GEM leak fix to be pulled first to avoid a conflict, right?
Regards,
Loïc
Quoted 72 lines · On Fri, 9 Jan 2026 10:42:21 +0100 Loïc Molinari <[email protected]>…
Hi Boris,
Quoted 69 lines · Boris Brezillon
Quoted 62 lines · On Thu, 8 Jan 2026 15:04:33 +0100 Loïc Molinari <[email protected]>…
Quoted 53 lines · Boris Brezillon
Quoted 38 lines · On Thu, 8 Jan 2026 14:25:01 +0100 Loïc Molinari <[email protected]>…
Quoted 27 lines · Boris Brezillon
Quoted 24 lines · On Tue, 6 Jan 2026 17:49:35 +0100 Boris Brezillon…
drm_gem_object_lookup_at_offset()can return a valid object with filp orfilp->f_op->get_unmapped_areaset to NULL. Make sure we still release the ref we acquired on such objects.Cc Loïc Molinari <[email protected]>Fixes 99bda20d6d4c ("drm/gem: Introduce drm_gem_get_unmapped_area() fop")Signed-off-by Boris Brezillon <[email protected]>--- drivers/gpu/drm/drm_gem.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-)drivers/gpu/drm/drm_gem.c +2
-2@@ -1298,11 +1298,13 @@ unsigned long drm_gem_get_unmapped_area(struct file *filp, unsigned long uaddr,unsigned long ret; obj =drm_gem_object_lookup_at_offset (filp, pgoff, len >>PAGE_SHIFT ); -if (IS_ERR (obj) || !obj->filp || !obj->filp->f_op->get_unmapped_area) -return mm_get_unmapped_area (filp, uaddr, len,0 , flags); +if (IS_ERR (obj)) + obj =NULL ;Quoted 9 lines
drivers/gpu/drm/drm_gem.c unsigned long drm_gem_get_unmapped_area(struct file *filp, unsigned long uaddr, · line 1305
Quoted 4 lines
drivers/gpu/drm/drm_gem.c +2
-2- ret = obj->filp->f_op->get_unmapped_area (obj->filp, uaddr, len,0 , - flags); +if (!obj || !obj->filp || !obj->filp->f_op->get_unmapped_area) + ret =mm_get_unmapped_area (filp, uaddr, len,0 , flags);Also, I'm wondering if we shouldn't pass pgoff instead of zero here to have the exact same behavior that existed before
drm_gem_get_unmapped_area()was introduced.Quoted 3 lines
For mappings with a file (the DRM file in our case), if
filp->f_op->get_unmapped_areaisn't set thengeneric_get_unmapped_area()is used and it ignores the pgoff argument.That's true for architectures that rely on the default implementation (Arm64 for instance), but other architectures might have their own implementation.
Quoted 2 lines
So it wasn't 0 before but was
ignored anyway.Quoted 7 lines
Didn't check all of them but the Arm implementation does take this pgoff into account if I read the code correctly [1]. The fact this argument is passed around makes me think other architectures might take this into account too. I know this pgoff is just a fake offset into the
/dev/dripseudo-file, but if we want to err on the safe side, we'd rather do exactly what was done beforedrm_gem_get_unmapped_area()was introduced for the ->filp==NULL case. That's just my 2 cts, of course.Quoted 2 lines
You're right, I focused on arm64 here and there's obviously other archs so we'd better pass pgoff for the fallback case.
Do you want me to send a patch doing that, or should I take care of it?
Was meant to be "should I let you take care of it?", but you got it right :D.
Quoted 3 lines
I'll take care of it. I'd better wait for that GEM leak fix to be pulled first to avoid a conflict, right?
Yep. I'll queue that one to drm-misc-next today.
Hi Boris,
Quoted 20 lines · Boris Brezillon
drm_gem_object_lookup_at_offset()can return a valid object with filp orfilp->f_op->get_unmapped_areaset to NULL. Make sure we still release the ref we acquired on such objects.Cc Loïc Molinari <[email protected]>Fixes 99bda20d6d4c ("drm/gem: Introduce drm_gem_get_unmapped_area() fop")Signed-off-by Boris Brezillon <[email protected]>--- drivers/gpu/drm/drm_gem.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-)drivers/gpu/drm/drm_gem.c +0
-1@@ -1298,11 +1298,13 @@ unsigned long drm_gem_get_unmapped_area(struct file *filp, unsigned long uaddr,unsigned long ret; obj =drm_gem_object_lookup_at_offset (filp, pgoff, len >>PAGE_SHIFT ); -if (IS_ERR (obj) || !obj->filp || !obj->filp->f_op->get_unmapped_area)
drivers/gpu/drm/drm_gem.c unsigned long drm_gem_get_unmapped_area(struct file *filp, unsigned long uaddr, · line 1307
Quoted 10 lines
drivers/gpu/drm/drm_gem.c +6
-3-return mm_get_unmapped_area (filp, uaddr, len,0 , flags); +if (IS_ERR (obj)) + obj =NULL ; - ret = obj->filp->f_op->get_unmapped_area (obj->filp, uaddr, len,0 , - flags); +if (!obj || !obj->filp || !obj->filp->f_op->get_unmapped_area) + ret =mm_get_unmapped_area (filp, uaddr, len,0 , flags); +else + ret = obj->filp->f_op->get_unmapped_area (obj->filp, uaddr, len,0 , flags);
Apart maybe for this line exceeding 80 chars:
Regards,
Loïc
Quoted 3 lines
drivers/gpu/drm/drm_gem.c +0
-0drm_gem_object_put (obj);
Quoted 27 lines · On Thu, 8 Jan 2026 14:18:26 +0100 Loïc Molinari <[email protected]>…
Hi Boris,
Quoted 24 lines · Boris Brezillon
drm_gem_object_lookup_at_offset()can return a valid object with filp orfilp->f_op->get_unmapped_areaset to NULL. Make sure we still release the ref we acquired on such objects.Cc Loïc Molinari <[email protected]>Fixes 99bda20d6d4c ("drm/gem: Introduce drm_gem_get_unmapped_area() fop")Signed-off-by Boris Brezillon <[email protected]>--- drivers/gpu/drm/drm_gem.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-)drivers/gpu/drm/drm_gem.c +2
-2@@ -1298,11 +1298,13 @@ unsigned long drm_gem_get_unmapped_area(struct file *filp, unsigned long uaddr,unsigned long ret; obj =drm_gem_object_lookup_at_offset (filp, pgoff, len >>PAGE_SHIFT ); -if (IS_ERR (obj) || !obj->filp || !obj->filp->f_op->get_unmapped_area) -return mm_get_unmapped_area (filp, uaddr, len,0 , flags); +if (IS_ERR (obj)) + obj =NULL ;
Quoted 8 lines
drivers/gpu/drm/drm_gem.c unsigned long drm_gem_get_unmapped_area(struct file *filp, unsigned long uaddr, · line 1307
Quoted 6 lines
drivers/gpu/drm/drm_gem.c +4
-2- ret = obj->filp->f_op->get_unmapped_area (obj->filp, uaddr, len,0 , - flags); +if (!obj || !obj->filp || !obj->filp->f_op->get_unmapped_area) + ret =mm_get_unmapped_area (filp, uaddr, len,0 , flags); +else + ret = obj->filp->f_op->get_unmapped_area (obj->filp, uaddr, len,0 , flags);Apart maybe for this line exceeding 80 chars:
The limit has been bumped to 100 chars a while ago (checkpatch --strict didn't complain), and for these single statements inside conditional blocks, I prefer to have them on a single line when I can because otherwise I tend to add curly braces to clearly flag the end of each conditional block.
Quoted 2 lines
Reviewed-by Loïc Molinari <[email protected]>
Thanks!
Quoted 39 lines · Boris Brezillon
Quoted 27 lines · On Thu, 8 Jan 2026 14:18:26 +0100 Loïc Molinari <[email protected]>…
Hi Boris,
Quoted 24 lines · Boris Brezillon
drm_gem_object_lookup_at_offset()can return a valid object with filp orfilp->f_op->get_unmapped_areaset to NULL. Make sure we still release the ref we acquired on such objects.Cc Loïc Molinari <[email protected]>Fixes 99bda20d6d4c ("drm/gem: Introduce drm_gem_get_unmapped_area() fop")Signed-off-by Boris Brezillon <[email protected]>--- drivers/gpu/drm/drm_gem.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-)drivers/gpu/drm/drm_gem.c +2
-2@@ -1298,11 +1298,13 @@ unsigned long drm_gem_get_unmapped_area(struct file *filp, unsigned long uaddr,unsigned long ret; obj =drm_gem_object_lookup_at_offset (filp, pgoff, len >>PAGE_SHIFT ); -if (IS_ERR (obj) || !obj->filp || !obj->filp->f_op->get_unmapped_area) -return mm_get_unmapped_area (filp, uaddr, len,0 , flags); +if (IS_ERR (obj)) + obj =NULL ;Quoted 8 lines
drivers/gpu/drm/drm_gem.c unsigned long drm_gem_get_unmapped_area(struct file *filp, unsigned long uaddr, · line 1307
Quoted 6 lines
drivers/gpu/drm/drm_gem.c +4
-2- ret = obj->filp->f_op->get_unmapped_area (obj->filp, uaddr, len,0 , - flags); +if (!obj || !obj->filp || !obj->filp->f_op->get_unmapped_area) + ret =mm_get_unmapped_area (filp, uaddr, len,0 , flags); +else + ret = obj->filp->f_op->get_unmapped_area (obj->filp, uaddr, len,0 , flags);Apart maybe for this line exceeding 80 chars:
Quoted 5 lines
The limit has been bumped to 100 chars a while ago (checkpatch --strict didn't complain), and for these single statements inside conditional blocks, I prefer to have them on a single line when I can because otherwise I tend to add curly braces to clearly flag the end of each conditional block.
Yeah, just mentioned it for consistency within the file.
Regards,
Loïc
Quoted 5 lines
Quoted 3 lines
Reviewed-by Loïc Molinari <[email protected]>Thanks!
Boris Brezillon
AppliedQuoted 7 lines · On Tue, 6 Jan 2026 17:49:35 +0100 Boris Brezillon…
drm_gem_object_lookup_at_offset()can return a valid object with filp orfilp->f_op->get_unmapped_areaset to NULL. Make sure we still release the ref we acquired on such objects.Cc Loïc Molinari <[email protected]>Fixes 99bda20d6d4c ("drm/gem: Introduce drm_gem_get_unmapped_area() fop")Signed-off-by Boris Brezillon <[email protected]>
Queued to drm-misc-next.
Quoted 26 lines
--- drivers/gpu/drm/drm_gem.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-)drivers/gpu/drm/drm_gem.c +6
-4@@ -1298,11 +1298,13 @@ unsigned long drm_gem_get_unmapped_area(struct file *filp, unsigned long uaddr,unsigned long ret; obj =drm_gem_object_lookup_at_offset (filp, pgoff, len >>PAGE_SHIFT ); -if (IS_ERR (obj) || !obj->filp || !obj->filp->f_op->get_unmapped_area) -return mm_get_unmapped_area (filp, uaddr, len,0 , flags); +if (IS_ERR (obj)) + obj =NULL ; - ret = obj->filp->f_op->get_unmapped_area (obj->filp, uaddr, len,0 , - flags); +if (!obj || !obj->filp || !obj->filp->f_op->get_unmapped_area) + ret =mm_get_unmapped_area (filp, uaddr, len,0 , flags); +else + ret = obj->filp->f_op->get_unmapped_area (obj->filp, uaddr, len,0 , flags);drm_gem_object_put (obj);