HID-Prodikeys: Adjustments for two function implementations
Subsystems (2)
cover HID-Prodikeys: Adjustments for two function implementations
From: Markus Elfring <[email protected]>
Date: Sat, 3 Feb 2018 18:21:23 +0100
A few update suggestions were taken into account
from static source code analysis.
Markus Elfring (6):
Delete two error messages for a failed memory allocation in pk_probe() Delete an unnecessary variable initialisation in pk_probe() Move an assignment in pk_probe()
Delete an unnecessary return statement in pcmidi_send_note() Combine two condition checks into one statement in pcmidi_send_note() Rename a jump label in pcmidi_send_note()
drivers/hid/hid-prodikeys.c | 21 +++++++-------------- 1 file changed, 7 insertions(+), 14 deletions(-)
Signature · 1 line
2.16.1
PATCH 1/6 hid-prodikeys: Delete two error messages for a failed memory allocation in pk_probe()
From: Markus Elfring <[email protected]>
Date: Sat, 3 Feb 2018 14:36:20 +0100
Omit extra messages for a memory allocation failure in this function.
This issue was detected by using the Coccinelle software.
--- drivers/hid/hid-prodikeys.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-)
drivers/hid/hid-prodikeys.c +1 -4
@@ -802,15 +802,12 @@ static int pk_probe(struct hid_device *hdev, const struct hid_device_id *id) pk =kzalloc (sizeof (*pk),GFP_KERNEL ); -if (pk =NULL ) { -hid_err (hdev,"can't alloc descriptor\n" ); +if (!pk)return -ENOMEM ; - } pk->hdev = hdev; pm =kzalloc (sizeof (*pm),GFP_KERNEL );if (pm =NULL ) { -hid_err (hdev,"can't alloc descriptor\n" ); ret = -ENOMEM ; goto err_free_pk; }
Signature · 1 line
2.16.1
PATCH 2/6 hid-prodikeys: Delete an unnecessary variable initialisation in pk_probe()
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Sat, 3 Feb 2018 14:45:24 +0100
The local variable "pm" will eventually be set to an appropriate pointer a bit later. Thus omit the explicit initialisation at the beginning.
--- drivers/hid/hid-prodikeys.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/hid/hid-prodikeys.c +1 -1
@@ -798,6 +798,6 @@ static int pk_probe(struct hid_device *hdev, const struct hid_device_id *id)unsigned short ifnum = intf->cur_altsetting->desc.bInterfaceNumber;unsigned long quirks = id->driver_data;struct pk_device *pk; -struct pcmidi_snd *pm =NULL ; +struct pcmidi_snd *pm; pk =kzalloc (sizeof (*pk),GFP_KERNEL );
Signature · 1 line
2.16.1
PATCH 3/6 hid-prodikeys: Move an assignment in pk_probe()
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Sat, 3 Feb 2018 17:20:01 +0100
Move one assignment for a data structure member in one local variable so that its setting will only be performed after a corresponding memory allocation succeeded by this function.
--- drivers/hid/hid-prodikeys.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/hid/hid-prodikeys.c +1 -2
@@ -804,8 +804,6 @@ static int pk_probe(struct hid_device *hdev, const struct hid_device_id *id)if (!pk)return -ENOMEM ; - pk->hdev = hdev; - pm =kzalloc (sizeof (*pm),GFP_KERNEL );if (pm =NULL ) { ret = -ENOMEM ;
@@ -814,6 +812,7 @@ static int pk_probe(struct hid_device *hdev, const struct hid_device_id *id) pm->pk = pk; pk->pm = pm; + pk->hdev = hdev; pm->ifnum = ifnum;hid_set_drvdata (hdev, pk);
Signature · 1 line
2.16.1
PATCH 4/6 hid-prodikeys: Delete an unnecessary return statement in pcmidi_send_note()
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Sat, 3 Feb 2018 17:33:40 +0100
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 function.
--- drivers/hid/hid-prodikeys.c | 2 -- 1 file changed, 2 deletions(-)
drivers/hid/hid-prodikeys.c +0 -2
@@ -235,8 +235,6 @@ static void pcmidi_send_note(struct pcmidi_snd *pm, drop_note:spin_unlock_irqrestore (&pm->rawmidi_in_lock, flags); - -return ; }static void pcmidi_sustained_note_release (struct timer_list *t)
Signature · 1 line
2.16.1
PATCH 5/6 hid-prodikeys: Combine two condition checks into one statement in pcmidi_send_note()
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Sat, 3 Feb 2018 18:00:06 +0100
The same label was used by goto statements after two condition checks. Thus use a single statement instead.
--- drivers/hid/hid-prodikeys.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)
drivers/hid/hid-prodikeys.c +2 -3
@@ -226,9 +226,8 @@ static void pcmidi_send_note(struct pcmidi_snd *pm,spin_lock_irqsave (&pm->rawmidi_in_lock, flags); -if (!pm->in_substream) - goto drop_note; -if (!test_bit (pm->in_substream->number, &pm->in_triggered)) +if (!pm->in_substream || + !test_bit (pm->in_substream->number, &pm->in_triggered)) goto drop_note;snd_rawmidi_receive (pm->in_substream, buffer,3 );
Signature · 1 line
2.16.1
PATCH 6/6 hid-prodikeys: Rename a jump label in pcmidi_send_note()
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Sat, 3 Feb 2018 18:10:00 +0100
An other label fits better to the jump target. Thus rename it.
--- drivers/hid/hid-prodikeys.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/hid/hid-prodikeys.c +2 -2
@@ -228,11 +228,11 @@ static void pcmidi_send_note(struct pcmidi_snd *pm,if (!pm->in_substream || !test_bit (pm->in_substream->number, &pm->in_triggered)) - goto drop_note; + goto unlock;snd_rawmidi_receive (pm->in_substream, buffer,3 ); -drop_note: +unlock:spin_unlock_irqrestore (&pm->rawmidi_in_lock, flags); }
Signature · 1 line
2.16.1