drm/radeon: check for allocation failure in radeon_ring_backup()
Subsystems (3)
PATCH 1/1 drm/radeon: check for allocation failure in radeon_ring_backup()
Static checkers complain if this we don't check for allocation failure. Also we can use the new kmalloc_array() function here as a cleanup.
drivers/gpu/drm/radeon/radeon_ring.c +5 -1
@@ -402,7 +402,11 @@ unsigned radeon_ring_backup(struct radeon_device *rdev, struct radeon_ring *ring }/* and then save the content of the ring */ - *data =kmalloc (size *4 ,GFP_KERNEL ); + *data =kmalloc_array (size,sizeof (uint32_t ),GFP_KERNEL ); +if (!*data) { +mutex_unlock (&rdev->ring_lock); +return 0 ; + }for (i =0 ; i < size; ++i) { (*data)[i] = ring->ring[ptr++]; ptr &= ring->ptr_mask;
Quoted 4 lines · Dan Carpenter
Static checkers complain if this we don't check for allocation failure. Also we can use the new
kmalloc_array()function here as a cleanup.Signed-off-by Dan Carpenter <[email protected]>
What's the benefit of using kmalloc_array instead of just kmalloc?
Anyway it's:
Quoted 9 lines
drivers/gpu/drm/radeon/radeon_ring.c +0
-0@@ -402,7 +402,11 @@ unsigned radeon_ring_backup(struct radeon_device *rdev, struct radeon_ring *ring }
drivers/gpu/drm/radeon/radeon_ring.c unsigned radeon_ring_backup(struct radeon_device *rdev, struct radeon_ring *ring · line 412
Quoted 10 lines
drivers/gpu/drm/radeon/radeon_ring.c +5
-1/* and then save the content of the ring */ - *data =kmalloc (size *4 ,GFP_KERNEL ); + *data =kmalloc_array (size,sizeof (uint32_t ),GFP_KERNEL ); +if (!*data) { +mutex_unlock (&rdev->ring_lock); +return 0 ; + }for (i =0 ; i < size; ++i) { (*data)[i] = ring->ring[ptr++]; ptr &= ring->ptr_mask;
--
To unsubscribe from this list: send the line "unsubscribe kernel-janitors" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Quoted 7 lines · Christian König
Quoted 4 lines · Dan Carpenter
Static checkers complain if this we don't check for allocation failure. Also we can use the new
kmalloc_array()function here as a cleanup.Signed-off-by Dan Carpenter <[email protected]>What's the benefit of using
kmalloc_arrayinstead of just kmalloc?
It has built in integer overflow protection. Whenever I see multiplication in kmalloc(), I automatically start to audit for overflows, but now, ha ha, just change it to kmalloc_array() and forget about it. (There weren't any integer overflow problems in the original code, btw).
regards,
dan carpenter
--
To unsubscribe from this list: send the line "unsubscribe kernel-janitors" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html