Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1590584 > unrolled thread
| Started by | Joe Perches <joe@perches.com> |
|---|---|
| First post | 2017-03-01 20:30 +0100 |
| Last post | 2017-03-01 20:50 +0100 |
| Articles | 2 — 1 participant |
Back to article view | Back to linux.kernel
[PATCH 0/2] HID: allocation neatening and code size reduction Joe Perches <joe@perches.com> - 2017-03-01 20:30 +0100
[PATCH 1/2] HID: Use krealloc Joe Perches <joe@perches.com> - 2017-03-01 20:50 +0100
| From | Joe Perches <joe@perches.com> |
|---|---|
| Date | 2017-03-01 20:30 +0100 |
| Subject | [PATCH 0/2] HID: allocation neatening and code size reduction |
| Message-ID | <tgi6K-7yC-7@gated-at.bofh.it> |
Joe Perches (2): HID: Use krealloc HID: Remove unnecessary OOM messages drivers/hid/hid-a4tech.c | 4 +--- drivers/hid/hid-apple.c | 4 +--- drivers/hid/hid-asus.c | 5 +---- drivers/hid/hid-core.c | 24 +++++++++++------------- drivers/hid/hid-lenovo.c | 7 ++----- drivers/hid/hid-lg.c | 5 ++--- drivers/hid/hid-lg4ff.c | 4 +--- drivers/hid/hid-logitech-dj.c | 12 +++--------- drivers/hid/hid-magicmouse.c | 4 +--- drivers/hid/hid-multitouch.c | 9 +++------ drivers/hid/hid-ntrig.c | 4 +--- drivers/hid/hid-picolcd_core.c | 1 - drivers/hid/hid-picolcd_leds.c | 1 - drivers/hid/hid-prodikeys.c | 5 +---- drivers/hid/hid-rmi.c | 4 +--- drivers/hid/hid-roccat-arvo.c | 5 ++--- drivers/hid/hid-roccat-isku.c | 5 ++--- drivers/hid/hid-roccat-koneplus.c | 5 ++--- drivers/hid/hid-roccat-konepure.c | 5 ++--- drivers/hid/hid-roccat-kovaplus.c | 5 ++--- drivers/hid/hid-roccat-lua.c | 5 ++--- drivers/hid/hid-roccat-pyra.c | 5 ++--- drivers/hid/hid-roccat-ryos.c | 5 ++--- drivers/hid/hid-roccat-savu.c | 5 ++--- drivers/hid/hid-saitek.c | 4 +--- drivers/hid/hid-sensor-hub.c | 6 +----- drivers/hid/hid-sony.c | 1 - 27 files changed, 49 insertions(+), 100 deletions(-) -- 2.10.0.rc2.1.g053435c
[toc] | [next] | [standalone]
| From | Joe Perches <joe@perches.com> |
|---|---|
| Date | 2017-03-01 20:50 +0100 |
| Subject | [PATCH 1/2] HID: Use krealloc |
| Message-ID | <tgiq5-7Fz-13@gated-at.bofh.it> |
| In reply to | #1590584 |
This kmalloc/memcpy is equivalent to krealloc, so use krealloc
to avoid a possibly unnecessary memcpy.
Miscellanea:
o Add temporary variables osize and nsize to improve readability
o krealloc has a defect and does not support GFP_ZERO
so the memset must be kept
Signed-off-by: Joe Perches <joe@perches.com>
---
drivers/hid/hid-core.c | 24 +++++++++++-------------
1 file changed, 11 insertions(+), 13 deletions(-)
diff --git a/drivers/hid/hid-core.c b/drivers/hid/hid-core.c
index e9e87d337446..b1ebf53ca879 100644
--- a/drivers/hid/hid-core.c
+++ b/drivers/hid/hid-core.c
@@ -131,21 +131,19 @@ static int open_collection(struct hid_parser *parser, unsigned type)
}
if (parser->device->maxcollection == parser->device->collection_size) {
- collection = kmalloc(sizeof(struct hid_collection) *
- parser->device->collection_size * 2, GFP_KERNEL);
- if (collection == NULL) {
- hid_err(parser->device, "failed to reallocate collection array\n");
+ unsigned int osize = parser->device->collection_size;
+ unsigned int nsize = osize * 2;
+
+ collection = krealloc(parser->device->collection,
+ nsize * sizeof(struct hid_collection),
+ GFP_KERNEL);
+ if (!collection)
return -ENOMEM;
- }
- memcpy(collection, parser->device->collection,
- sizeof(struct hid_collection) *
- parser->device->collection_size);
- memset(collection + parser->device->collection_size, 0,
- sizeof(struct hid_collection) *
- parser->device->collection_size);
- kfree(parser->device->collection);
+
+ memset(collection + osize, 0,
+ sizeof(struct hid_collection) * osize);
parser->device->collection = collection;
- parser->device->collection_size *= 2;
+ parser->device->collection_size = nsize;
}
parser->collection_stack[parser->collection_stack_ptr++] =
--
2.10.0.rc2.1.g053435c
[toc] | [prev] | [standalone]
Back to top | Article view | linux.kernel
csiph-web