Skip to contentSkip to conversation

drm/gem: Fix a GEM leak in drm_gem_get_unmapped_area()

PATCH Applied Boris Brezillon 2 participants 12 messages Jan 6 – Jan 9

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

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.

Cc Loïc Molinari <[email protected]>
Fixes 99bda20d6d4c ("drm/gem: Introduce drm_gem_get_unmapped_area() fop")
---
 drivers/gpu/drm/drm_gem.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)
drivers/gpu/drm/drm_gem.c +6 -4
index 36c8af123877..f7cbf6e8d1e0 100644
@@ -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
#1 lore raw
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 or filp->f_op->get_unmapped_area set 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")
---
 drivers/gpu/drm/drm_gem.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)
drivers/gpu/drm/drm_gem.c +0 -0
index 36c8af123877..f7cbf6e8d1e0 100644
@@ -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 -4
 	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);

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);
 
#2 lore raw
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 or filp->f_op->get_unmapped_area set 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")
---
  drivers/gpu/drm/drm_gem.c | 10 ++++++----
  1 file changed, 6 insertions(+), 4 deletions(-)
drivers/gpu/drm/drm_gem.c +2 -2
index 36c8af123877..f7cbf6e8d1e0 100644
@@ -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);
 
#3 lore raw
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 or filp->f_op->get_unmapped_area set 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")
---
  drivers/gpu/drm/drm_gem.c | 10 ++++++----
  1 file changed, 6 insertions(+), 4 deletions(-)
drivers/gpu/drm/drm_gem.c +2 -2
index 36c8af123877..f7cbf6e8d1e0 100644
@@ -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_area isn't set then generic_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

#4 lore raw
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 or filp->f_op->get_unmapped_area set 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")
---
   drivers/gpu/drm/drm_gem.c | 10 ++++++----
   1 file changed, 6 insertions(+), 4 deletions(-)
drivers/gpu/drm/drm_gem.c +2 -2
index 36c8af123877..f7cbf6e8d1e0 100644
@@ -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_area isn't set then generic_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/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.

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

#5 lore raw
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 or filp->f_op->get_unmapped_area set 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")
---
   drivers/gpu/drm/drm_gem.c | 10 ++++++----
   1 file changed, 6 insertions(+), 4 deletions(-)
drivers/gpu/drm/drm_gem.c +2 -2
index 36c8af123877..f7cbf6e8d1e0 100644
@@ -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_area isn't set then generic_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/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.

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?

#6 lore raw

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 or filp->f_op->get_unmapped_area set 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")
---
    drivers/gpu/drm/drm_gem.c | 10 ++++++----
    1 file changed, 6 insertions(+), 4 deletions(-)
drivers/gpu/drm/drm_gem.c +2 -2
index 36c8af123877..f7cbf6e8d1e0 100644
@@ -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_area isn't set then generic_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.

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

#7 lore raw
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 or filp->f_op->get_unmapped_area set 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")
---
    drivers/gpu/drm/drm_gem.c | 10 ++++++----
    1 file changed, 6 insertions(+), 4 deletions(-)
drivers/gpu/drm/drm_gem.c +2 -2
index 36c8af123877..f7cbf6e8d1e0 100644
@@ -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_area isn't set then generic_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/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.

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.

Reviewed-by on v1 1/1
#8 lore raw
In reply to Boris Brezillon

Hi Boris,

Quoted 20 lines · Boris Brezillon

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.

Cc Loïc Molinari <[email protected]>
Fixes 99bda20d6d4c ("drm/gem: Introduce drm_gem_get_unmapped_area() fop")
---
  drivers/gpu/drm/drm_gem.c | 10 ++++++----
  1 file changed, 6 insertions(+), 4 deletions(-)
drivers/gpu/drm/drm_gem.c +0 -1
index 36c8af123877..f7cbf6e8d1e0 100644
@@ -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 -0
  	drm_gem_object_put(obj);
 
#9 lore raw
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 or filp->f_op->get_unmapped_area set 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")
---
  drivers/gpu/drm/drm_gem.c | 10 ++++++----
  1 file changed, 6 insertions(+), 4 deletions(-)
drivers/gpu/drm/drm_gem.c +2 -2
index 36c8af123877..f7cbf6e8d1e0 100644
@@ -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

Thanks!

#10 lore raw
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 or filp->f_op->get_unmapped_area set 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")
---
   drivers/gpu/drm/drm_gem.c | 10 ++++++----
   1 file changed, 6 insertions(+), 4 deletions(-)
drivers/gpu/drm/drm_gem.c +2 -2
index 36c8af123877..f7cbf6e8d1e0 100644
@@ -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

Thanks!

author Applied
#11 lore raw
In reply to Boris Brezillon
Quoted 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 or filp->f_op->get_unmapped_area set 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")

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
index 36c8af123877..f7cbf6e8d1e0 100644
@@ -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);