Skip to content

Commit 8c27cc5

Browse files
sherllydaeinki
authored andcommitted
drm/exynos: Convert from atomic_t to refcount_t on g2d_cmdlist_userptr->refcount
refcount_t type and corresponding API can protect refcounters from accidental underflow and overflow and further use-after-free situations. Signed-off-by: Xiyu Yang <[email protected]> Signed-off-by: Xin Tan <[email protected]> Signed-off-by: Inki Dae <[email protected]>
1 parent b74a29f commit 8c27cc5

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

drivers/gpu/drm/exynos/exynos_drm_g2d.c

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
* Authors: Joonyoung Shim <[email protected]>
55
*/
66

7+
#include <linux/refcount.h>
78
#include <linux/clk.h>
89
#include <linux/component.h>
910
#include <linux/delay.h>
@@ -208,7 +209,7 @@ struct g2d_cmdlist_userptr {
208209
struct page **pages;
209210
unsigned int npages;
210211
struct sg_table *sgt;
211-
atomic_t refcount;
212+
refcount_t refcount;
212213
bool in_pool;
213214
bool out_of_list;
214215
};
@@ -386,9 +387,9 @@ static void g2d_userptr_put_dma_addr(struct g2d_data *g2d,
386387
if (force)
387388
goto out;
388389

389-
atomic_dec(&g2d_userptr->refcount);
390+
refcount_dec(&g2d_userptr->refcount);
390391

391-
if (atomic_read(&g2d_userptr->refcount) > 0)
392+
if (refcount_read(&g2d_userptr->refcount) > 0)
392393
return;
393394

394395
if (g2d_userptr->in_pool)
@@ -436,7 +437,7 @@ static dma_addr_t *g2d_userptr_get_dma_addr(struct g2d_data *g2d,
436437
* and different size.
437438
*/
438439
if (g2d_userptr->size == size) {
439-
atomic_inc(&g2d_userptr->refcount);
440+
refcount_inc(&g2d_userptr->refcount);
440441
*obj = g2d_userptr;
441442

442443
return &g2d_userptr->dma_addr;
@@ -461,7 +462,7 @@ static dma_addr_t *g2d_userptr_get_dma_addr(struct g2d_data *g2d,
461462
if (!g2d_userptr)
462463
return ERR_PTR(-ENOMEM);
463464

464-
atomic_set(&g2d_userptr->refcount, 1);
465+
refcount_set(&g2d_userptr->refcount, 1);
465466
g2d_userptr->size = size;
466467

467468
start = userptr & PAGE_MASK;

0 commit comments

Comments
 (0)