diff mbox

drm/radeon: check for allocation failure in radeon_ring_backup()

Message ID 20120720111700.GB22245@elgon.mountain (mailing list archive)
State New, archived
Headers show

Commit Message

Dan Carpenter July 20, 2012, 11:17 a.m. UTC
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 <dan.carpenter@oracle.com>

Comments

Dan Carpenter July 20, 2012, 2:35 p.m. UTC | #1
On Fri, Jul 20, 2012 at 03:45:28PM +0200, Christian König wrote:
> On 20.07.2012 13:17, Dan Carpenter wrote:
> >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 <dan.carpenter@oracle.com>
> What's the benefit of using kmalloc_array instead 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
diff mbox

Patch

diff --git a/drivers/gpu/drm/radeon/radeon_ring.c b/drivers/gpu/drm/radeon/radeon_ring.c
index 75cbe46..5a0ef24 100644
--- a/drivers/gpu/drm/radeon/radeon_ring.c
+++ b/drivers/gpu/drm/radeon/radeon_ring.c
@@ -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;