Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1490407
| From | SF Markus Elfring <elfring@users.sourceforge.net> |
|---|---|
| Newsgroups | linux.kernel |
| Subject | [PATCH 1/4] i2c-dev: Use kmalloc_array() in i2cdev_ioctl_rdwr() |
| Date | 2016-09-23 21:50 +0200 |
| Message-ID | <skEDU-80F-13@gated-at.bofh.it> (permalink) |
| References | <qEuGl-43C-5@gated-at.bofh.it> <skEDU-80F-5@gated-at.bofh.it> |
| Organization | linux.* mail to news gateway |
From: Markus Elfring <elfring@users.sourceforge.net>
Date: Fri, 23 Sep 2016 20:30:07 +0200
* A multiplication for the size determination of a memory allocation
indicated that an array data structure should be processed.
Thus use the corresponding function "kmalloc_array".
This issue was detected by using the Coccinelle software.
* Replace the specification of a data type by a pointer dereference
to make the corresponding size determination a bit safer according to
the Linux coding style convention.
Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
drivers/i2c/i2c-dev.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/drivers/i2c/i2c-dev.c b/drivers/i2c/i2c-dev.c
index 66f323f..6d8226d 100644
--- a/drivers/i2c/i2c-dev.c
+++ b/drivers/i2c/i2c-dev.c
@@ -260,7 +260,9 @@ static noinline int i2cdev_ioctl_rdwr(struct i2c_client *client,
if (IS_ERR(rdwr_pa))
return PTR_ERR(rdwr_pa);
- data_ptrs = kmalloc(rdwr_arg.nmsgs * sizeof(u8 __user *), GFP_KERNEL);
+ data_ptrs = kmalloc_array(rdwr_arg.nmsgs,
+ sizeof(*data_ptrs),
+ GFP_KERNEL);
if (data_ptrs == NULL) {
kfree(rdwr_pa);
return -ENOMEM;
--
2.10.0
Back to linux.kernel | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
[PATCH 0/4] i2c-dev: Fine-tuning for four function implementations SF Markus Elfring <elfring@users.sourceforge.net> - 2016-09-23 21:50 +0200 [PATCH 1/4] i2c-dev: Use kmalloc_array() in i2cdev_ioctl_rdwr() SF Markus Elfring <elfring@users.sourceforge.net> - 2016-09-23 21:50 +0200 [PATCH 3/4] i2c-dev: Rename jump labels in i2cdev_attach_adapter() SF Markus Elfring <elfring@users.sourceforge.net> - 2016-09-23 21:50 +0200 [PATCH 2/4] i2c-dev: Improve another size determination in i2cdev_ioctl_rdwr() SF Markus Elfring <elfring@users.sourceforge.net> - 2016-09-23 21:50 +0200
csiph-web