* [PATCH] HID: hidraw: Improve a size determination in two functions
@ 2017-10-24 19:00 SF Markus Elfring
2017-10-25 7:37 ` Benjamin Tissoires
0 siblings, 1 reply; 2+ messages in thread
From: SF Markus Elfring @ 2017-10-24 19:00 UTC (permalink / raw)
To: linux-input, Benjamin Tissoires, Jiri Kosina; +Cc: LKML, kernel-janitors
From: Markus Elfring <elfring@users.sourceforge.net>
Date: Tue, 24 Oct 2017 20:52:19 +0200
* Replace the specification of data structures by pointer dereferences
as the parameter for the operator "sizeof" to make the corresponding size
determination a bit safer according to the Linux coding style convention.
This issue was detected by using the Coccinelle software.
* Return directly after a call of the function "kzalloc" failed
at the beginning of the function "hidraw_open".
* Delete the jump target "out" which became unnecessary
with this refactoring.
Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
drivers/hid/hidraw.c | 10 ++++------
1 file changed, 4 insertions(+), 6 deletions(-)
diff --git a/drivers/hid/hidraw.c b/drivers/hid/hidraw.c
index 5fbe0f81ab2e..26fbf9e82f84 100644
--- a/drivers/hid/hidraw.c
+++ b/drivers/hid/hidraw.c
@@ -269,10 +269,9 @@ static int hidraw_open(struct inode *inode, struct file *file)
unsigned long flags;
int err = 0;
- if (!(list = kzalloc(sizeof(struct hidraw_list), GFP_KERNEL))) {
- err = -ENOMEM;
- goto out;
- }
+ list = kzalloc(sizeof(*list), GFP_KERNEL);
+ if (!list)
+ return -ENOMEM;
mutex_lock(&minors_lock);
if (!hidraw_table[minor] || !hidraw_table[minor]->exist) {
@@ -304,7 +303,6 @@ static int hidraw_open(struct inode *inode, struct file *file)
file->private_data = list;
out_unlock:
mutex_unlock(&minors_lock);
-out:
if (err < 0)
kfree(list);
return err;
@@ -513,7 +511,7 @@ int hidraw_connect(struct hid_device *hid)
/* we accept any HID device, all applications */
- dev = kzalloc(sizeof(struct hidraw), GFP_KERNEL);
+ dev = kzalloc(sizeof(*dev), GFP_KERNEL);
if (!dev)
return -ENOMEM;
--
2.14.3
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] HID: hidraw: Improve a size determination in two functions
2017-10-24 19:00 [PATCH] HID: hidraw: Improve a size determination in two functions SF Markus Elfring
@ 2017-10-25 7:37 ` Benjamin Tissoires
0 siblings, 0 replies; 2+ messages in thread
From: Benjamin Tissoires @ 2017-10-25 7:37 UTC (permalink / raw)
To: SF Markus Elfring; +Cc: linux-input, Jiri Kosina, LKML, kernel-janitors
On Oct 24 2017 or thereabouts, SF Markus Elfring wrote:
> From: Markus Elfring <elfring@users.sourceforge.net>
> Date: Tue, 24 Oct 2017 20:52:19 +0200
>
> * Replace the specification of data structures by pointer dereferences
> as the parameter for the operator "sizeof" to make the corresponding size
> determination a bit safer according to the Linux coding style convention.
>
> This issue was detected by using the Coccinelle software.
>
> * Return directly after a call of the function "kzalloc" failed
> at the beginning of the function "hidraw_open".
>
> * Delete the jump target "out" which became unnecessary
> with this refactoring.
>
> Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
> ---
> drivers/hid/hidraw.c | 10 ++++------
> 1 file changed, 4 insertions(+), 6 deletions(-)
>
> diff --git a/drivers/hid/hidraw.c b/drivers/hid/hidraw.c
> index 5fbe0f81ab2e..26fbf9e82f84 100644
> --- a/drivers/hid/hidraw.c
> +++ b/drivers/hid/hidraw.c
> @@ -269,10 +269,9 @@ static int hidraw_open(struct inode *inode, struct file *file)
> unsigned long flags;
> int err = 0;
>
> - if (!(list = kzalloc(sizeof(struct hidraw_list), GFP_KERNEL))) {
> - err = -ENOMEM;
> - goto out;
> - }
> + list = kzalloc(sizeof(*list), GFP_KERNEL);
I am not sure the change from "if (!a = kzalloc())" to "a = kzalloc();
if (!a)" adds anything besides clearer code. I prefer the later, so:
Reviewed-by: Benjamin Tissoires <benjamin.tissoires@redhat.com>
Cheers,
Benjamin
> + if (!list)
> + return -ENOMEM;
>
> mutex_lock(&minors_lock);
> if (!hidraw_table[minor] || !hidraw_table[minor]->exist) {
> @@ -304,7 +303,6 @@ static int hidraw_open(struct inode *inode, struct file *file)
> file->private_data = list;
> out_unlock:
> mutex_unlock(&minors_lock);
> -out:
> if (err < 0)
> kfree(list);
> return err;
> @@ -513,7 +511,7 @@ int hidraw_connect(struct hid_device *hid)
>
> /* we accept any HID device, all applications */
>
> - dev = kzalloc(sizeof(struct hidraw), GFP_KERNEL);
> + dev = kzalloc(sizeof(*dev), GFP_KERNEL);
> if (!dev)
> return -ENOMEM;
>
> --
> 2.14.3
>
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2017-10-25 7:37 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-10-24 19:00 [PATCH] HID: hidraw: Improve a size determination in two functions SF Markus Elfring
2017-10-25 7:37 ` Benjamin Tissoires
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).