Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1490311
| From | SF Markus Elfring <elfring@users.sourceforge.net> |
|---|---|
| Newsgroups | linux.kernel |
| Subject | [PATCH 1/3] drm/vmwgfx: Use kmalloc_array() in vmw_surface_define_ioctl() |
| Date | 2016-09-23 18:40 +0200 |
| Message-ID | <skBG2-6fB-13@gated-at.bofh.it> (permalink) |
| References | <skBG1-6fB-9@gated-at.bofh.it> |
| Organization | linux.* mail to news gateway |
From: Markus Elfring <elfring@users.sourceforge.net>
Date: Thu, 22 Sep 2016 21:54:33 +0200
Multiplications for the size determination of memory allocations
indicated that array data structures should be processed.
Thus use the corresponding function "kmalloc_array".
This issue was detected by using the Coccinelle software.
Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
drivers/gpu/drm/vmwgfx/vmwgfx_surface.c | 10 ++++++----
1 file changed, 6 insertions(+), 4 deletions(-)
diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_surface.c b/drivers/gpu/drm/vmwgfx/vmwgfx_surface.c
index c2a721a..f557549 100644
--- a/drivers/gpu/drm/vmwgfx/vmwgfx_surface.c
+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_surface.c
@@ -763,14 +763,16 @@ int vmw_surface_define_ioctl(struct drm_device *dev, void *data,
memcpy(srf->mip_levels, req->mip_levels, sizeof(srf->mip_levels));
srf->num_sizes = num_sizes;
user_srf->size = size;
-
- srf->sizes = kmalloc(srf->num_sizes * sizeof(*srf->sizes), GFP_KERNEL);
+ srf->sizes = kmalloc_array(srf->num_sizes,
+ sizeof(*srf->sizes),
+ GFP_KERNEL);
if (unlikely(srf->sizes == NULL)) {
ret = -ENOMEM;
goto out_no_sizes;
}
- srf->offsets = kmalloc(srf->num_sizes * sizeof(*srf->offsets),
- GFP_KERNEL);
+ srf->offsets = kmalloc_array(srf->num_sizes,
+ sizeof(*srf->offsets),
+ GFP_KERNEL);
if (unlikely(srf->offsets == NULL)) {
ret = -ENOMEM;
goto out_no_offsets;
--
2.10.0
Back to linux.kernel | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
[PATCH 0/3] drm/vmwgfx: Fine-tuning for 13 function implementations SF Markus Elfring <elfring@users.sourceforge.net> - 2016-09-23 18:40 +0200 [PATCH 1/3] drm/vmwgfx: Use kmalloc_array() in vmw_surface_define_ioctl() SF Markus Elfring <elfring@users.sourceforge.net> - 2016-09-23 18:40 +0200 [PATCH 2/3] drm/vmwgfx: Use memdup_user() rather than duplicating its implementation SF Markus Elfring <elfring@users.sourceforge.net> - 2016-09-23 18:40 +0200 [PATCH 3/3] drm/vmwgfx: Adjust checks for null pointers in 13 functions SF Markus Elfring <elfring@users.sourceforge.net> - 2016-09-23 18:50 +0200
csiph-web