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(-)
--
2.16.1
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.
Signed-off-by: Markus Elfring <[email protected]>
---
drivers/hid/hid-prodikeys.c | 5 +----
1 file changed, 1 insertion(+), 4 deletions(-)
diff --git a/drivers/hid/hid-prodikeys.c b/drivers/hid/hid-prodikeys.c
index 87eda34ea2f8..9cad4973a67b 100644
--- a/drivers/hid/hid-prodikeys.c
+++ b/drivers/hid/hid-prodikeys.c
@@ -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;
}
--
2.16.1
From: 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.
Signed-off-by: Markus Elfring <[email protected]>
---
drivers/hid/hid-prodikeys.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/hid/hid-prodikeys.c b/drivers/hid/hid-prodikeys.c
index 9cad4973a67b..2e79dfc92162 100644
--- a/drivers/hid/hid-prodikeys.c
+++ b/drivers/hid/hid-prodikeys.c
@@ -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);
--
2.16.1
From: 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.
Signed-off-by: Markus Elfring <[email protected]>
---
drivers/hid/hid-prodikeys.c | 5 ++---
1 file changed, 2 insertions(+), 3 deletions(-)
diff --git a/drivers/hid/hid-prodikeys.c b/drivers/hid/hid-prodikeys.c
index c9eae92ad429..1c62dddedd40 100644
--- a/drivers/hid/hid-prodikeys.c
+++ b/drivers/hid/hid-prodikeys.c
@@ -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);
--
2.16.1
From: 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.
Signed-off-by: Markus Elfring <[email protected]>
---
drivers/hid/hid-prodikeys.c | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/drivers/hid/hid-prodikeys.c b/drivers/hid/hid-prodikeys.c
index 2e79dfc92162..7672f723b268 100644
--- a/drivers/hid/hid-prodikeys.c
+++ b/drivers/hid/hid-prodikeys.c
@@ -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);
--
2.16.1
From: 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.
Signed-off-by: Markus Elfring <[email protected]>
---
drivers/hid/hid-prodikeys.c | 2 --
1 file changed, 2 deletions(-)
diff --git a/drivers/hid/hid-prodikeys.c b/drivers/hid/hid-prodikeys.c
index 7672f723b268..c9eae92ad429 100644
--- a/drivers/hid/hid-prodikeys.c
+++ b/drivers/hid/hid-prodikeys.c
@@ -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)
--
2.16.1
From: 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.
Signed-off-by: Markus Elfring <[email protected]>
---
drivers/hid/hid-prodikeys.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/drivers/hid/hid-prodikeys.c b/drivers/hid/hid-prodikeys.c
index 1c62dddedd40..4596d97b61eb 100644
--- a/drivers/hid/hid-prodikeys.c
+++ b/drivers/hid/hid-prodikeys.c
@@ -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);
}
--
2.16.1