* [PATCH 1/4] ALSA: emux: Adjust one function call together with a variable assignment
2017-08-09 8:00 [PATCH 0/4] ALSA: emux: Adjustments for four function implementations SF Markus Elfring
@ 2017-08-09 8:01 ` SF Markus Elfring
2017-08-09 8:02 ` [PATCH 2/4] ALSA: emux: Improve a size determination in two functions SF Markus Elfring
` (3 subsequent siblings)
4 siblings, 0 replies; 6+ messages in thread
From: SF Markus Elfring @ 2017-08-09 8:01 UTC (permalink / raw)
To: alsa-devel, Jaroslav Kysela, Kees Cook, Takashi Iwai,
Takashi Sakamoto
Cc: kernel-janitors, LKML
From: Markus Elfring <elfring@users.sourceforge.net>
Date: Wed, 9 Aug 2017 08:40:14 +0200
The script "checkpatch.pl" pointed information out like the following.
ERROR: do not use assignment in if condition
Thus fix the affected source code place.
Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
sound/synth/emux/emux_seq.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/sound/synth/emux/emux_seq.c b/sound/synth/emux/emux_seq.c
index 55579f6b8cb2..53820f75ba3e 100644
--- a/sound/synth/emux/emux_seq.c
+++ b/sound/synth/emux/emux_seq.c
@@ -144,7 +144,8 @@ snd_emux_create_port(struct snd_emux *emu, char *name,
int i, type, cap;
/* Allocate structures for this channel */
- if ((p = kzalloc(sizeof(*p), GFP_KERNEL)) = NULL) {
+ p = kzalloc(sizeof(*p), GFP_KERNEL);
+ if (!p) {
snd_printk(KERN_ERR "no memory\n");
return NULL;
}
--
2.13.4
^ permalink raw reply related [flat|nested] 6+ messages in thread* [PATCH 2/4] ALSA: emux: Improve a size determination in two functions
2017-08-09 8:00 [PATCH 0/4] ALSA: emux: Adjustments for four function implementations SF Markus Elfring
2017-08-09 8:01 ` [PATCH 1/4] ALSA: emux: Adjust one function call together with a variable assignment SF Markus Elfring
@ 2017-08-09 8:02 ` SF Markus Elfring
2017-08-09 8:03 ` [PATCH 3/4] ALSA: emux: Adjust four checks for null pointers SF Markus Elfring
` (2 subsequent siblings)
4 siblings, 0 replies; 6+ messages in thread
From: SF Markus Elfring @ 2017-08-09 8:02 UTC (permalink / raw)
To: alsa-devel, Jaroslav Kysela, Kees Cook, Takashi Iwai,
Takashi Sakamoto
Cc: kernel-janitors, LKML
From: Markus Elfring <elfring@users.sourceforge.net>
Date: Wed, 9 Aug 2017 09:11:26 +0200
Replace the specification of data types 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.
Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
sound/synth/emux/emux_seq.c | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/sound/synth/emux/emux_seq.c b/sound/synth/emux/emux_seq.c
index 53820f75ba3e..12acf18c5be4 100644
--- a/sound/synth/emux/emux_seq.c
+++ b/sound/synth/emux/emux_seq.c
@@ -149,7 +149,8 @@ snd_emux_create_port(struct snd_emux *emu, char *name,
snd_printk(KERN_ERR "no memory\n");
return NULL;
}
- p->chset.channels = kcalloc(max_channels, sizeof(struct snd_midi_channel), GFP_KERNEL);
+ p->chset.channels = kcalloc(max_channels, sizeof(*p->chset.channels),
+ GFP_KERNEL);
if (p->chset.channels = NULL) {
snd_printk(KERN_ERR "no memory\n");
kfree(p);
@@ -371,7 +372,7 @@ int snd_emux_init_virmidi(struct snd_emux *emu, struct snd_card *card)
if (emu->midi_ports <= 0)
return 0;
- emu->vmidi = kcalloc(emu->midi_ports, sizeof(struct snd_rawmidi *), GFP_KERNEL);
+ emu->vmidi = kcalloc(emu->midi_ports, sizeof(*emu->vmidi), GFP_KERNEL);
if (emu->vmidi = NULL)
return -ENOMEM;
--
2.13.4
^ permalink raw reply related [flat|nested] 6+ messages in thread* [PATCH 3/4] ALSA: emux: Adjust four checks for null pointers
2017-08-09 8:00 [PATCH 0/4] ALSA: emux: Adjustments for four function implementations SF Markus Elfring
2017-08-09 8:01 ` [PATCH 1/4] ALSA: emux: Adjust one function call together with a variable assignment SF Markus Elfring
2017-08-09 8:02 ` [PATCH 2/4] ALSA: emux: Improve a size determination in two functions SF Markus Elfring
@ 2017-08-09 8:03 ` SF Markus Elfring
2017-08-09 8:04 ` [PATCH 4/4] ALSA: emux: Delete two error messages for a failed memory allocation in snd_emux_create_ SF Markus Elfring
2017-08-10 15:55 ` [PATCH 0/4] ALSA: emux: Adjustments for four function implementations Takashi Iwai
4 siblings, 0 replies; 6+ messages in thread
From: SF Markus Elfring @ 2017-08-09 8:03 UTC (permalink / raw)
To: alsa-devel, Jaroslav Kysela, Kees Cook, Takashi Iwai,
Takashi Sakamoto
Cc: kernel-janitors, LKML
From: Markus Elfring <elfring@users.sourceforge.net>
Date: Wed, 9 Aug 2017 09:22:42 +0200
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
The script “checkpatch.pl” pointed information out like the following.
Comparison to NULL could be written !…
Thus fix affected source code places.
Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
sound/synth/emux/emux_seq.c | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/sound/synth/emux/emux_seq.c b/sound/synth/emux/emux_seq.c
index 12acf18c5be4..fd6cbd439511 100644
--- a/sound/synth/emux/emux_seq.c
+++ b/sound/synth/emux/emux_seq.c
@@ -99,7 +99,7 @@ snd_emux_init_seq(struct snd_emux *emu, struct snd_card *card, int index)
sprintf(tmpname, "%s Port %d", emu->name, i);
p = snd_emux_create_port(emu, tmpname, MIDI_CHANNELS,
0, &pinfo);
- if (p = NULL) {
+ if (!p) {
snd_printk(KERN_ERR "can't create port\n");
return -ENOMEM;
}
@@ -151,7 +151,7 @@ snd_emux_create_port(struct snd_emux *emu, char *name,
}
p->chset.channels = kcalloc(max_channels, sizeof(*p->chset.channels),
GFP_KERNEL);
- if (p->chset.channels = NULL) {
+ if (!p->chset.channels) {
snd_printk(KERN_ERR "no memory\n");
kfree(p);
return NULL;
@@ -373,7 +373,7 @@ int snd_emux_init_virmidi(struct snd_emux *emu, struct snd_card *card)
return 0;
emu->vmidi = kcalloc(emu->midi_ports, sizeof(*emu->vmidi), GFP_KERNEL);
- if (emu->vmidi = NULL)
+ if (!emu->vmidi)
return -ENOMEM;
for (i = 0; i < emu->midi_ports; i++) {
@@ -405,7 +405,7 @@ int snd_emux_delete_virmidi(struct snd_emux *emu)
{
int i;
- if (emu->vmidi = NULL)
+ if (!emu->vmidi)
return 0;
for (i = 0; i < emu->midi_ports; i++) {
--
2.13.4
^ permalink raw reply related [flat|nested] 6+ messages in thread* [PATCH 4/4] ALSA: emux: Delete two error messages for a failed memory allocation in snd_emux_create_
2017-08-09 8:00 [PATCH 0/4] ALSA: emux: Adjustments for four function implementations SF Markus Elfring
` (2 preceding siblings ...)
2017-08-09 8:03 ` [PATCH 3/4] ALSA: emux: Adjust four checks for null pointers SF Markus Elfring
@ 2017-08-09 8:04 ` SF Markus Elfring
2017-08-10 15:55 ` [PATCH 0/4] ALSA: emux: Adjustments for four function implementations Takashi Iwai
4 siblings, 0 replies; 6+ messages in thread
From: SF Markus Elfring @ 2017-08-09 8:04 UTC (permalink / raw)
To: alsa-devel, Jaroslav Kysela, Kees Cook, Takashi Iwai,
Takashi Sakamoto
Cc: kernel-janitors, LKML
From: Markus Elfring <elfring@users.sourceforge.net>
Date: Wed, 9 Aug 2017 09:30:34 +0200
Omit extra messages for a memory allocation failure in this function.
This issue was detected by using the Coccinelle software.
Link: http://events.linuxfoundation.org/sites/events/files/slides/LCJ16-Refactor_Strings-WSang_0.pdf
Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
sound/synth/emux/emux_seq.c | 6 ++----
1 file changed, 2 insertions(+), 4 deletions(-)
diff --git a/sound/synth/emux/emux_seq.c b/sound/synth/emux/emux_seq.c
index fd6cbd439511..396c406d0f77 100644
--- a/sound/synth/emux/emux_seq.c
+++ b/sound/synth/emux/emux_seq.c
@@ -145,14 +145,12 @@ snd_emux_create_port(struct snd_emux *emu, char *name,
/* Allocate structures for this channel */
p = kzalloc(sizeof(*p), GFP_KERNEL);
- if (!p) {
- snd_printk(KERN_ERR "no memory\n");
+ if (!p)
return NULL;
- }
+
p->chset.channels = kcalloc(max_channels, sizeof(*p->chset.channels),
GFP_KERNEL);
if (!p->chset.channels) {
- snd_printk(KERN_ERR "no memory\n");
kfree(p);
return NULL;
}
--
2.13.4
^ permalink raw reply related [flat|nested] 6+ messages in thread* Re: [PATCH 0/4] ALSA: emux: Adjustments for four function implementations
2017-08-09 8:00 [PATCH 0/4] ALSA: emux: Adjustments for four function implementations SF Markus Elfring
` (3 preceding siblings ...)
2017-08-09 8:04 ` [PATCH 4/4] ALSA: emux: Delete two error messages for a failed memory allocation in snd_emux_create_ SF Markus Elfring
@ 2017-08-10 15:55 ` Takashi Iwai
4 siblings, 0 replies; 6+ messages in thread
From: Takashi Iwai @ 2017-08-10 15:55 UTC (permalink / raw)
To: SF Markus Elfring
Cc: alsa-devel, Kees Cook, kernel-janitors, LKML, Takashi Sakamoto
On Wed, 09 Aug 2017 10:00:23 +0200,
SF Markus Elfring wrote:
>
> From: Markus Elfring <elfring@users.sourceforge.net>
> Date: Wed, 9 Aug 2017 09:50:05 +0200
>
> A few update suggestions were taken into account
> from static source code analysis.
>
> Markus Elfring (4):
> Adjust one function call together with a variable assignment
> Improve a size determination in two functions
> Adjust four checks for null pointers
> Delete two error messages for a failed memory allocation in snd_emux_create_port()
Applied all four patches now. Thanks.
Takashi
^ permalink raw reply [flat|nested] 6+ messages in thread