Skip to contentSkip to conversation

drm: use size_t variables to iterate through pages

PATCH In review Jordan Crouse 2 participants 2 messages Oct 3, 2017 – Oct 4, 2017

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

PATCH 1/1 drm: use size_t variables to iterate through pages

drm_gem_get_pages() and drm_gem_put_pages() calculate the number of pages to operate on from obj->size which is a size_t. Use similarly sized variables to calculate and iterate through the pages to avoid possibly losing bits from the page calculation.

---
 drivers/gpu/drm/drm_gem.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/gpu/drm/drm_gem.c +2 -2
index af62017..a8c146d 100644
@@ -550,7 +550,7 @@ struct page **drm_gem_get_pages(struct drm_gem_object *obj)
 {
 	struct address_space *mapping;
 	struct page *p, **pages;
-	int i, npages;
+	size_t i, npages;
 
 	/* This is the shared memory object that backs the GEM resource */
 	mapping = obj->filp->f_mapping;
@@ -603,7 +603,7 @@ struct page **drm_gem_get_pages(struct drm_gem_object *obj)
 void drm_gem_put_pages(struct drm_gem_object *obj, struct page **pages,
 		bool dirty, bool accessed)
 {
-	int i, npages;
+	size_t i, npages;
 
 	/* We already BUG_ON() for non-page-aligned sizes in
 	 * drm_gem_object_init(), so we should never hit this unless
Signature · 1 line
1.9.1
#1 lore raw
Quoted 6 lines · Jordan Crouse

drm_gem_get_pages() and drm_gem_put_pages() calculate the number of pages to operate on from obj->size which is a size_t. Use similarly sized variables to calculate and iterate through the pages to avoid possibly losing bits from the page calculation.

Not sure it wouldn't be better to move over to u64? In theory you could have a gpu with huge amounts of vram on a 32bit kernel, like PAE.

There's also rough consensus that size_t is just an all-around evil type for anything :-)

Still an issue of course, just probably with a differen (and likely more invasive) fix.
-Daniel

Quoted 33 lines
---
 drivers/gpu/drm/drm_gem.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/gpu/drm/drm_gem.c +2 -2
index af62017..a8c146d 100644
@@ -550,7 +550,7 @@ struct page **drm_gem_get_pages(struct drm_gem_object *obj)
 {
 	struct address_space *mapping;
 	struct page *p, **pages;
-	int i, npages;
+	size_t i, npages;
 
 	/* This is the shared memory object that backs the GEM resource */
 	mapping = obj->filp->f_mapping;
@@ -603,7 +603,7 @@ struct page **drm_gem_get_pages(struct drm_gem_object *obj)
 void drm_gem_put_pages(struct drm_gem_object *obj, struct page **pages,
 		bool dirty, bool accessed)
 {
-	int i, npages;
+	size_t i, npages;
 
 	/* We already BUG_ON() for non-page-aligned sizes in
 	 * drm_gem_object_init(), so we should never hit this unless
Signature · 6 lines
1.9.1

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
Signature · 3 lines
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch