2017-04-25 15:18:37

by SF Markus Elfring

[permalink] [raw]
Subject: [PATCH 0/3] HID-Wacom: Fine-tuning for seven function implementations

From: Markus Elfring <[email protected]>
Date: Tue, 25 Apr 2017 17:07:07 +0200

Three update suggestions were taken into account
from static source code analysis.

Markus Elfring (3):
Use devm_kcalloc() in two functions
Improve size determinations in three functions
Delete two unnecessary return statements

drivers/hid/wacom_sys.c | 14 +++++---------
1 file changed, 5 insertions(+), 9 deletions(-)

--
2.12.2


2017-04-25 15:14:51

by SF Markus Elfring

[permalink] [raw]
Subject: [PATCH 1/3] HID: Wacom: Use devm_kcalloc() in two functions

From: Markus Elfring <[email protected]>
Date: Tue, 25 Apr 2017 16:06:08 +0200

* Multiplications for the size determination of memory allocations
indicated that array data structures should be processed.
Thus use the corresponding function "devm_kcalloc".

This issue was detected by using the Coccinelle software.

* Replace the specification of data structures by pointer dereferences
to make the corresponding size determination a bit safer according to
the Linux coding style convention.

Signed-off-by: Markus Elfring <[email protected]>
---
drivers/hid/wacom_sys.c | 5 ++---
1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/drivers/hid/wacom_sys.c b/drivers/hid/wacom_sys.c
index 0022c0dac88a..550faf8819ea 100644
--- a/drivers/hid/wacom_sys.c
+++ b/drivers/hid/wacom_sys.c
@@ -1245,7 +1245,7 @@ static int wacom_led_groups_alloc_and_register_one(struct device *dev,
if (!devres_open_group(dev, &wacom->led.groups[group_id], GFP_KERNEL))
return -ENOMEM;

- leds = devm_kzalloc(dev, sizeof(struct wacom_led) * count, GFP_KERNEL);
+ leds = devm_kcalloc(dev, count, sizeof(*leds), GFP_KERNEL);
if (!leds) {
error = -ENOMEM;
goto err;
@@ -1345,8 +1345,7 @@ static int wacom_led_groups_allocate(struct wacom *wacom, int count)
struct wacom_group_leds *groups;
int error;

- groups = devm_kzalloc(dev, sizeof(struct wacom_group_leds) * count,
- GFP_KERNEL);
+ groups = devm_kcalloc(dev, count, sizeof(*groups), GFP_KERNEL);
if (!groups)
return -ENOMEM;

--
2.12.2

2017-04-25 15:15:54

by SF Markus Elfring

[permalink] [raw]
Subject: [PATCH 2/3] HID: Wacom: Improve size determinations in three functions

From: Markus Elfring <[email protected]>
Date: Tue, 25 Apr 2017 16:38:59 +0200

Replace the specification of three data structures by pointer dereferences
as the parameter for the operator "sizeof" to make the corresponding size
determinations a bit safer according to the Linux coding style convention.

Signed-off-by: Markus Elfring <[email protected]>
---
drivers/hid/wacom_sys.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/hid/wacom_sys.c b/drivers/hid/wacom_sys.c
index 550faf8819ea..7517da5300fd 100644
--- a/drivers/hid/wacom_sys.c
+++ b/drivers/hid/wacom_sys.c
@@ -726,7 +726,7 @@ static int wacom_add_shared_data(struct hid_device *hdev)

data = wacom_get_hdev_data(hdev);
if (!data) {
- data = kzalloc(sizeof(struct wacom_hdev_data), GFP_KERNEL);
+ data = kzalloc(sizeof(*data), GFP_KERNEL);
if (!data) {
retval = -ENOMEM;
goto out;
@@ -1088,7 +1088,7 @@ static int __wacom_devm_sysfs_create_group(struct wacom *wacom,
int error;

devres = devres_alloc(wacom_devm_sysfs_group_release,
- sizeof(struct wacom_sysfs_group_devres),
+ sizeof(*devres),
GFP_KERNEL);
if (!devres)
return -ENOMEM;
@@ -2556,7 +2556,7 @@ static int wacom_probe(struct hid_device *hdev,
/* hid-core sets this quirk for the boot interface */
hdev->quirks &= ~HID_QUIRK_NOGET;

- wacom = devm_kzalloc(&hdev->dev, sizeof(struct wacom), GFP_KERNEL);
+ wacom = devm_kzalloc(&hdev->dev, sizeof(*wacom), GFP_KERNEL);
if (!wacom)
return -ENOMEM;

--
2.12.2

2017-04-25 15:16:19

by SF Markus Elfring

[permalink] [raw]
Subject: [PATCH 3/3] HID: Wacom: Delete two unnecessary return statements

From: Markus Elfring <[email protected]>
Date: Tue, 25 Apr 2017 16:50:02 +0200

The script "checkpatch.pl" pointed information out like the following.

WARNING: void function return statements are not generally useful

Thus remove such a statement in the affected functions.

Signed-off-by: Markus Elfring <[email protected]>
---
drivers/hid/wacom_sys.c | 3 ---
1 file changed, 3 deletions(-)

diff --git a/drivers/hid/wacom_sys.c b/drivers/hid/wacom_sys.c
index 7517da5300fd..f70e7d7351c7 100644
--- a/drivers/hid/wacom_sys.c
+++ b/drivers/hid/wacom_sys.c
@@ -2329,7 +2329,6 @@ static void wacom_wireless_work(struct work_struct *work)
fail:
wacom_release_resources(wacom1);
wacom_release_resources(wacom2);
- return;
}

static void wacom_remote_destroy_one(struct wacom *wacom, unsigned int index)
@@ -2534,8 +2533,6 @@ static void wacom_mode_change_work(struct work_struct *work)
if (error)
return;
}
-
- return;
}

static int wacom_probe(struct hid_device *hdev,
--
2.12.2

2017-06-05 15:30:01

by Jason Gerecke

[permalink] [raw]
Subject: Re: [PATCH 1/3] HID: Wacom: Use devm_kcalloc() in two functions

Going through old mail and noticed that these three patches seem to
have been overlooked (at least, I don't see them in Jiri's
branches...). For the set:

Reviewed-by: Jason Gerecke <[email protected]>

Jason
---
Now instead of four in the eights place /
you’ve got three, ‘Cause you added one /
(That is to say, eight) to the two, /
But you can’t take seven from three, /
So you look at the sixty-fours....



On Tue, Apr 25, 2017 at 8:13 AM, SF Markus Elfring
<[email protected]> wrote:
> From: Markus Elfring <[email protected]>
> Date: Tue, 25 Apr 2017 16:06:08 +0200
>
> * Multiplications for the size determination of memory allocations
> indicated that array data structures should be processed.
> Thus use the corresponding function "devm_kcalloc".
>
> This issue was detected by using the Coccinelle software.
>
> * Replace the specification of data structures by pointer dereferences
> to make the corresponding size determination a bit safer according to
> the Linux coding style convention.
>
> Signed-off-by: Markus Elfring <[email protected]>
> ---
> drivers/hid/wacom_sys.c | 5 ++---
> 1 file changed, 2 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/hid/wacom_sys.c b/drivers/hid/wacom_sys.c
> index 0022c0dac88a..550faf8819ea 100644
> --- a/drivers/hid/wacom_sys.c
> +++ b/drivers/hid/wacom_sys.c
> @@ -1245,7 +1245,7 @@ static int wacom_led_groups_alloc_and_register_one(struct device *dev,
> if (!devres_open_group(dev, &wacom->led.groups[group_id], GFP_KERNEL))
> return -ENOMEM;
>
> - leds = devm_kzalloc(dev, sizeof(struct wacom_led) * count, GFP_KERNEL);
> + leds = devm_kcalloc(dev, count, sizeof(*leds), GFP_KERNEL);
> if (!leds) {
> error = -ENOMEM;
> goto err;
> @@ -1345,8 +1345,7 @@ static int wacom_led_groups_allocate(struct wacom *wacom, int count)
> struct wacom_group_leds *groups;
> int error;
>
> - groups = devm_kzalloc(dev, sizeof(struct wacom_group_leds) * count,
> - GFP_KERNEL);
> + groups = devm_kcalloc(dev, count, sizeof(*groups), GFP_KERNEL);
> if (!groups)
> return -ENOMEM;
>
> --
> 2.12.2
>
> --
> To unsubscribe from this list: send the line "unsubscribe linux-input" in
> the body of a message to [email protected]
> More majordomo info at http://vger.kernel.org/majordomo-info.html