* [PATCH 1/3] ALSA: rawmidi: Adjust seven function calls together with a variable assignment
2017-11-11 11:10 [PATCH 0/3] ALSA: rawmidi: Adjustments for some function implementations SF Markus Elfring
@ 2017-11-11 11:11 ` SF Markus Elfring
2017-11-11 11:12 ` [PATCH 2/3] ALSA: rawmidi: Use common error handling code in snd_rawmidi_new() SF Markus Elfring
2017-11-11 11:13 ` [PATCH 3/3] ALSA: rawmidi: Adjust 21 checks for null pointers SF Markus Elfring
2 siblings, 0 replies; 4+ messages in thread
From: SF Markus Elfring @ 2017-11-11 11:11 UTC (permalink / raw)
To: alsa-devel, Fabian Frederick, Ingo Molnar, Jaroslav Kysela,
Takashi Iwai, Takashi Sakamoto
Cc: LKML, kernel-janitors
From: Markus Elfring <elfring@users.sourceforge.net>
Date: Sat, 11 Nov 2017 11:22:28 +0100
The script "checkpatch.pl" pointed information out like the following.
ERROR: do not use assignment in if condition
Thus fix affected source code places.
Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
sound/core/rawmidi.c | 44 +++++++++++++++++++++++++++++---------------
1 file changed, 29 insertions(+), 15 deletions(-)
diff --git a/sound/core/rawmidi.c b/sound/core/rawmidi.c
index b3b353d72527..c17f173150e9 100644
--- a/sound/core/rawmidi.c
+++ b/sound/core/rawmidi.c
@@ -109,9 +109,10 @@ static void snd_rawmidi_input_event_work(struct work_struct *work)
static int snd_rawmidi_runtime_create(struct snd_rawmidi_substream *substream)
{
- struct snd_rawmidi_runtime *runtime;
+ struct snd_rawmidi_runtime *runtime = kzalloc(sizeof(*runtime),
+ GFP_KERNEL);
- if ((runtime = kzalloc(sizeof(*runtime), GFP_KERNEL)) == NULL)
+ if (!runtime)
return -ENOMEM;
runtime->substream = substream;
spin_lock_init(&runtime->lock);
@@ -124,7 +125,9 @@ static int snd_rawmidi_runtime_create(struct snd_rawmidi_substream *substream)
runtime->avail = 0;
else
runtime->avail = runtime->buffer_size;
- if ((runtime->buffer = kmalloc(runtime->buffer_size, GFP_KERNEL)) == NULL) {
+
+ runtime->buffer = kmalloc(runtime->buffer_size, GFP_KERNEL);
+ if (!runtime->buffer) {
kfree(runtime);
return -ENOMEM;
}
@@ -571,8 +574,9 @@ static int snd_rawmidi_info_user(struct snd_rawmidi_substream *substream,
struct snd_rawmidi_info __user * _info)
{
struct snd_rawmidi_info info;
- int err;
- if ((err = snd_rawmidi_info(substream, &info)) < 0)
+ int err = snd_rawmidi_info(substream, &info);
+
+ if (err < 0)
return err;
if (copy_to_user(_info, &info, sizeof(struct snd_rawmidi_info)))
return -EFAULT;
@@ -616,7 +620,8 @@ static int snd_rawmidi_info_select_user(struct snd_card *card,
return -EFAULT;
if (get_user(info.subdevice, &_info->subdevice))
return -EFAULT;
- if ((err = snd_rawmidi_info_select(card, &info)) < 0)
+ err = snd_rawmidi_info_select(card, &info);
+ if (err < 0)
return err;
if (copy_to_user(_info, &info, sizeof(struct snd_rawmidi_info)))
return -EFAULT;
@@ -1549,21 +1554,30 @@ int snd_rawmidi_new(struct snd_card *card, char *id, int device,
rmidi->dev.release = release_rawmidi_device;
dev_set_name(&rmidi->dev, "midiC%iD%i", card->number, device);
- if ((err = snd_rawmidi_alloc_substreams(rmidi,
- &rmidi->streams[SNDRV_RAWMIDI_STREAM_INPUT],
- SNDRV_RAWMIDI_STREAM_INPUT,
- input_count)) < 0) {
+ err =
+ snd_rawmidi_alloc_substreams(rmidi,
+ &rmidi
+ ->streams[SNDRV_RAWMIDI_STREAM_INPUT],
+ SNDRV_RAWMIDI_STREAM_INPUT,
+ input_count);
+ if (err < 0) {
snd_rawmidi_free(rmidi);
return err;
}
- if ((err = snd_rawmidi_alloc_substreams(rmidi,
- &rmidi->streams[SNDRV_RAWMIDI_STREAM_OUTPUT],
- SNDRV_RAWMIDI_STREAM_OUTPUT,
- output_count)) < 0) {
+
+ err =
+ snd_rawmidi_alloc_substreams(rmidi,
+ &rmidi
+ ->streams[SNDRV_RAWMIDI_STREAM_OUTPUT],
+ SNDRV_RAWMIDI_STREAM_OUTPUT,
+ output_count);
+ if (err < 0) {
snd_rawmidi_free(rmidi);
return err;
}
- if ((err = snd_device_new(card, SNDRV_DEV_RAWMIDI, rmidi, &ops)) < 0) {
+
+ err = snd_device_new(card, SNDRV_DEV_RAWMIDI, rmidi, &ops);
+ if (err < 0) {
snd_rawmidi_free(rmidi);
return err;
}
--
2.15.0
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [PATCH 2/3] ALSA: rawmidi: Use common error handling code in snd_rawmidi_new()
2017-11-11 11:10 [PATCH 0/3] ALSA: rawmidi: Adjustments for some function implementations SF Markus Elfring
2017-11-11 11:11 ` [PATCH 1/3] ALSA: rawmidi: Adjust seven function calls together with a variable assignment SF Markus Elfring
@ 2017-11-11 11:12 ` SF Markus Elfring
2017-11-11 11:13 ` [PATCH 3/3] ALSA: rawmidi: Adjust 21 checks for null pointers SF Markus Elfring
2 siblings, 0 replies; 4+ messages in thread
From: SF Markus Elfring @ 2017-11-11 11:12 UTC (permalink / raw)
To: alsa-devel, Fabian Frederick, Ingo Molnar, Jaroslav Kysela,
Takashi Iwai, Takashi Sakamoto
Cc: LKML, kernel-janitors
From: Markus Elfring <elfring@users.sourceforge.net>
Date: Sat, 11 Nov 2017 11:36:25 +0100
Add a jump target so that a bit of exception handling can be better reused
at the end of this function.
This issue was detected by using the Coccinelle software.
Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
sound/core/rawmidi.c | 23 +++++++++++------------
1 file changed, 11 insertions(+), 12 deletions(-)
diff --git a/sound/core/rawmidi.c b/sound/core/rawmidi.c
index c17f173150e9..34686000ecce 100644
--- a/sound/core/rawmidi.c
+++ b/sound/core/rawmidi.c
@@ -1560,10 +1560,8 @@ int snd_rawmidi_new(struct snd_card *card, char *id, int device,
->streams[SNDRV_RAWMIDI_STREAM_INPUT],
SNDRV_RAWMIDI_STREAM_INPUT,
input_count);
- if (err < 0) {
- snd_rawmidi_free(rmidi);
- return err;
- }
+ if (err < 0)
+ goto free_midi;
err =
snd_rawmidi_alloc_substreams(rmidi,
@@ -1571,19 +1569,20 @@ int snd_rawmidi_new(struct snd_card *card, char *id, int device,
->streams[SNDRV_RAWMIDI_STREAM_OUTPUT],
SNDRV_RAWMIDI_STREAM_OUTPUT,
output_count);
- if (err < 0) {
- snd_rawmidi_free(rmidi);
- return err;
- }
+ if (err < 0)
+ goto free_midi;
err = snd_device_new(card, SNDRV_DEV_RAWMIDI, rmidi, &ops);
- if (err < 0) {
- snd_rawmidi_free(rmidi);
- return err;
- }
+ if (err < 0)
+ goto free_midi;
+
if (rrawmidi)
*rrawmidi = rmidi;
return 0;
+
+free_midi:
+ snd_rawmidi_free(rmidi);
+ return err;
}
EXPORT_SYMBOL(snd_rawmidi_new);
--
2.15.0
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [PATCH 3/3] ALSA: rawmidi: Adjust 21 checks for null pointers
2017-11-11 11:10 [PATCH 0/3] ALSA: rawmidi: Adjustments for some function implementations SF Markus Elfring
2017-11-11 11:11 ` [PATCH 1/3] ALSA: rawmidi: Adjust seven function calls together with a variable assignment SF Markus Elfring
2017-11-11 11:12 ` [PATCH 2/3] ALSA: rawmidi: Use common error handling code in snd_rawmidi_new() SF Markus Elfring
@ 2017-11-11 11:13 ` SF Markus Elfring
2 siblings, 0 replies; 4+ messages in thread
From: SF Markus Elfring @ 2017-11-11 11:13 UTC (permalink / raw)
To: alsa-devel, Fabian Frederick, Ingo Molnar, Jaroslav Kysela,
Takashi Iwai, Takashi Sakamoto
Cc: LKML, kernel-janitors
From: Markus Elfring <elfring@users.sourceforge.net>
Date: Sat, 11 Nov 2017 11:48:25 +0100
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 the affected source code places.
Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
sound/core/rawmidi.c | 42 +++++++++++++++++++++---------------------
1 file changed, 21 insertions(+), 21 deletions(-)
diff --git a/sound/core/rawmidi.c b/sound/core/rawmidi.c
index 34686000ecce..1934de257a1e 100644
--- a/sound/core/rawmidi.c
+++ b/sound/core/rawmidi.c
@@ -343,7 +343,7 @@ int snd_rawmidi_kernel_open(struct snd_card *card, int device, int subdevice,
mutex_lock(®ister_mutex);
rmidi = snd_rawmidi_search(card, device);
- if (rmidi == NULL) {
+ if (!rmidi) {
mutex_unlock(®ister_mutex);
return -ENODEV;
}
@@ -391,7 +391,7 @@ static int snd_rawmidi_open(struct inode *inode, struct file *file)
} else
return -ENXIO;
- if (rmidi == NULL)
+ if (!rmidi)
return -ENODEV;
if (!try_module_get(rmidi->card->module)) {
@@ -408,7 +408,7 @@ static int snd_rawmidi_open(struct inode *inode, struct file *file)
if ((file->f_flags & O_APPEND) || maj == SOUND_MAJOR) /* OSS emul? */
fflags |= SNDRV_RAWMIDI_LFLG_APPEND;
rawmidi_file = kmalloc(sizeof(*rawmidi_file), GFP_KERNEL);
- if (rawmidi_file == NULL) {
+ if (!rawmidi_file) {
err = -ENOMEM;
goto __error;
}
@@ -552,7 +552,7 @@ static int snd_rawmidi_info(struct snd_rawmidi_substream *substream,
{
struct snd_rawmidi *rmidi;
- if (substream == NULL)
+ if (!substream)
return -ENODEV;
rmidi = substream->rmidi;
memset(info, 0, sizeof(*info));
@@ -745,11 +745,11 @@ static long snd_rawmidi_ioctl(struct file *file, unsigned int cmd, unsigned long
return -EFAULT;
switch (params.stream) {
case SNDRV_RAWMIDI_STREAM_OUTPUT:
- if (rfile->output == NULL)
+ if (!rfile->output)
return -EINVAL;
return snd_rawmidi_output_params(rfile->output, ¶ms);
case SNDRV_RAWMIDI_STREAM_INPUT:
- if (rfile->input == NULL)
+ if (!rfile->input)
return -EINVAL;
return snd_rawmidi_input_params(rfile->input, ¶ms);
default:
@@ -764,12 +764,12 @@ static long snd_rawmidi_ioctl(struct file *file, unsigned int cmd, unsigned long
return -EFAULT;
switch (status.stream) {
case SNDRV_RAWMIDI_STREAM_OUTPUT:
- if (rfile->output == NULL)
+ if (!rfile->output)
return -EINVAL;
err = snd_rawmidi_output_status(rfile->output, &status);
break;
case SNDRV_RAWMIDI_STREAM_INPUT:
- if (rfile->input == NULL)
+ if (!rfile->input)
return -EINVAL;
err = snd_rawmidi_input_status(rfile->input, &status);
break;
@@ -789,7 +789,7 @@ static long snd_rawmidi_ioctl(struct file *file, unsigned int cmd, unsigned long
return -EFAULT;
switch (val) {
case SNDRV_RAWMIDI_STREAM_OUTPUT:
- if (rfile->output == NULL)
+ if (!rfile->output)
return -EINVAL;
return snd_rawmidi_drop_output(rfile->output);
default:
@@ -803,11 +803,11 @@ static long snd_rawmidi_ioctl(struct file *file, unsigned int cmd, unsigned long
return -EFAULT;
switch (val) {
case SNDRV_RAWMIDI_STREAM_OUTPUT:
- if (rfile->output == NULL)
+ if (!rfile->output)
return -EINVAL;
return snd_rawmidi_drain_output(rfile->output);
case SNDRV_RAWMIDI_STREAM_INPUT:
- if (rfile->input == NULL)
+ if (!rfile->input)
return -EINVAL;
return snd_rawmidi_drain_input(rfile->input);
default:
@@ -885,7 +885,7 @@ int snd_rawmidi_receive(struct snd_rawmidi_substream *substream,
if (!substream->opened)
return -EBADFD;
- if (runtime->buffer == NULL) {
+ if (!runtime->buffer) {
rmidi_dbg(substream->rmidi,
"snd_rawmidi_receive: input is not active!!!\n");
return -EINVAL;
@@ -999,7 +999,7 @@ static ssize_t snd_rawmidi_read(struct file *file, char __user *buf, size_t coun
rfile = file->private_data;
substream = rfile->input;
- if (substream == NULL)
+ if (!substream)
return -EIO;
runtime = substream->runtime;
snd_rawmidi_input_trigger(substream, 1);
@@ -1052,7 +1052,7 @@ int snd_rawmidi_transmit_empty(struct snd_rawmidi_substream *substream)
int result;
unsigned long flags;
- if (runtime->buffer == NULL) {
+ if (!runtime->buffer) {
rmidi_dbg(substream->rmidi,
"snd_rawmidi_transmit_empty: output is not active!!!\n");
return 1;
@@ -1078,7 +1078,7 @@ int __snd_rawmidi_transmit_peek(struct snd_rawmidi_substream *substream,
int result, count1;
struct snd_rawmidi_runtime *runtime = substream->runtime;
- if (runtime->buffer == NULL) {
+ if (!runtime->buffer) {
rmidi_dbg(substream->rmidi,
"snd_rawmidi_transmit_peek: output is not active!!!\n");
return -EINVAL;
@@ -1151,7 +1151,7 @@ int __snd_rawmidi_transmit_ack(struct snd_rawmidi_substream *substream, int coun
{
struct snd_rawmidi_runtime *runtime = substream->runtime;
- if (runtime->buffer == NULL) {
+ if (!runtime->buffer) {
rmidi_dbg(substream->rmidi,
"snd_rawmidi_transmit_ack: output is not active!!!\n");
return -EINVAL;
@@ -1369,21 +1369,21 @@ static unsigned int snd_rawmidi_poll(struct file *file, poll_table * wait)
unsigned int mask;
rfile = file->private_data;
- if (rfile->input != NULL) {
+ if (rfile->input) {
runtime = rfile->input->runtime;
snd_rawmidi_input_trigger(rfile->input, 1);
poll_wait(file, &runtime->sleep, wait);
}
- if (rfile->output != NULL) {
+ if (rfile->output) {
runtime = rfile->output->runtime;
poll_wait(file, &runtime->sleep, wait);
}
mask = 0;
- if (rfile->input != NULL) {
+ if (rfile->input) {
if (snd_rawmidi_ready(rfile->input))
mask |= POLLIN | POLLRDNORM;
}
- if (rfile->output != NULL) {
+ if (rfile->output) {
if (snd_rawmidi_ready(rfile->output))
mask |= POLLOUT | POLLWRNORM;
}
@@ -1547,7 +1547,7 @@ int snd_rawmidi_new(struct snd_card *card, char *id, int device,
INIT_LIST_HEAD(&rmidi->streams[SNDRV_RAWMIDI_STREAM_INPUT].substreams);
INIT_LIST_HEAD(&rmidi->streams[SNDRV_RAWMIDI_STREAM_OUTPUT].substreams);
- if (id != NULL)
+ if (id)
strlcpy(rmidi->id, id, sizeof(rmidi->id));
snd_device_initialize(&rmidi->dev, card);
--
2.15.0
^ permalink raw reply related [flat|nested] 4+ messages in thread