kernel-janitors.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [patch] drm/radeon: check for allocation failure in radeon_ring_backup()
@ 2012-07-20 11:17 Dan Carpenter
  2012-07-20 13:45 ` Christian König
  0 siblings, 1 reply; 3+ messages in thread
From: Dan Carpenter @ 2012-07-20 11:17 UTC (permalink / raw)
  To: David Airlie
  Cc: kernel-janitors, Michel Dänzer, Jerome Glisse, dri-devel,
	Alex Deucher, Dave Airlie

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>

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;

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [patch] drm/radeon: check for allocation failure in radeon_ring_backup()
  2012-07-20 11:17 [patch] drm/radeon: check for allocation failure in radeon_ring_backup() Dan Carpenter
@ 2012-07-20 13:45 ` Christian König
  2012-07-20 14:35   ` Dan Carpenter
  0 siblings, 1 reply; 3+ messages in thread
From: Christian König @ 2012-07-20 13:45 UTC (permalink / raw)
  To: Dan Carpenter
  Cc: kernel-janitors, Michel Dänzer, dri-devel, Jerome Glisse,
	Alex Deucher, Dave Airlie

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?

Anyway it's:

Reviewed-by: Christian König <christian.koenig@amd.com>

>
> 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;
>

--
To unsubscribe from this list: send the line "unsubscribe kernel-janitors" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [patch] drm/radeon: check for allocation failure in radeon_ring_backup()
  2012-07-20 13:45 ` Christian König
@ 2012-07-20 14:35   ` Dan Carpenter
  0 siblings, 0 replies; 3+ messages in thread
From: Dan Carpenter @ 2012-07-20 14:35 UTC (permalink / raw)
  To: Christian König
  Cc: kernel-janitors, Michel Dänzer, dri-devel, Jerome Glisse,
	Alex Deucher, Dave Airlie

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

--
To unsubscribe from this list: send the line "unsubscribe kernel-janitors" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2012-07-20 14:35 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-07-20 11:17 [patch] drm/radeon: check for allocation failure in radeon_ring_backup() Dan Carpenter
2012-07-20 13:45 ` Christian König
2012-07-20 14:35   ` Dan Carpenter

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).