Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1483324 > unrolled thread
| Started by | SF Markus Elfring <elfring@users.sourceforge.net> |
|---|---|
| First post | 2016-09-14 16:00 +0200 |
| Last post | 2016-09-14 16:20 +0200 |
| Articles | 14 — 2 participants |
Back to article view | Back to linux.kernel
This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by
below is the oldest one visible, not the original post.
[PATCH 00/11] virtio-console: Fine-tuning for 14 function implementations SF Markus Elfring <elfring@users.sourceforge.net> - 2016-09-14 16:00 +0200
[PATCH 01/11] virtio_console: Use kmalloc_array() in init_vqs() SF Markus Elfring <elfring@users.sourceforge.net> - 2016-09-14 16:10 +0200
[PATCH 04/11] virtio_console: Rename jump labels in virtcons_probe() SF Markus Elfring <elfring@users.sourceforge.net> - 2016-09-14 16:10 +0200
[PATCH 09/11] virtio_console: Rename a jump label in __send_to_port() SF Markus Elfring <elfring@users.sourceforge.net> - 2016-09-14 16:10 +0200
[PATCH 03/11] virtio_console: Rename a jump label in init() SF Markus Elfring <elfring@users.sourceforge.net> - 2016-09-14 16:10 +0200
[PATCH 06/11] virtio_console: Rename a jump label in port_fops_open() SF Markus Elfring <elfring@users.sourceforge.net> - 2016-09-14 16:10 +0200
[PATCH 02/11] virtio_console: Less function calls in init_vqs() after error detection SF Markus Elfring <elfring@users.sourceforge.net> - 2016-09-14 16:10 +0200
Re: [PATCH 02/11] virtio_console: Less function calls in init_vqs() after error detection Amit Shah <amit.shah@redhat.com> - 2016-09-21 14:20 +0200
Re: virtio_console: Less function calls in init_vqs() after error detection SF Markus Elfring <elfring@users.sourceforge.net> - 2016-09-21 15:10 +0200
[PATCH 08/11] virtio_console: Rename jump labels in port_fops_write() SF Markus Elfring <elfring@users.sourceforge.net> - 2016-09-14 16:10 +0200
[PATCH 10/11] virtio_console: Rename jump labels in alloc_buf() SF Markus Elfring <elfring@users.sourceforge.net> - 2016-09-14 16:10 +0200
[PATCH 05/11] virtio_console: Rename jump labels in add_port() SF Markus Elfring <elfring@users.sourceforge.net> - 2016-09-14 16:10 +0200
[PATCH 07/11] virtio_console: Rename a jump label in port_fops_splice_write() SF Markus Elfring <elfring@users.sourceforge.net> - 2016-09-14 16:10 +0200
[PATCH 11/11] virtio_console: Rename a jump label in five functions SF Markus Elfring <elfring@users.sourceforge.net> - 2016-09-14 16:20 +0200
| From | SF Markus Elfring <elfring@users.sourceforge.net> |
|---|---|
| Date | 2016-09-14 16:00 +0200 |
| Subject | [PATCH 00/11] virtio-console: Fine-tuning for 14 function implementations |
| Message-ID | <shiTg-1yN-29@gated-at.bofh.it> |
From: Markus Elfring <elfring@users.sourceforge.net> Date: Wed, 14 Sep 2016 15:43:21 +0200 Several update suggestions were taken into account from static source code analysis. Markus Elfring (11): Use kmalloc_array() in init_vqs() Less function calls in init_vqs() after error detection Rename a jump label in init() Rename jump labels in virtcons_probe() Rename jump labels in add_port() Rename a jump label in port_fops_open() Rename a jump label in port_fops_splice_write() Rename jump labels in port_fops_write() Rename a jump label in __send_to_port() Rename jump labels in alloc_buf() Rename a jump label in five functions drivers/char/virtio_console.c | 155 ++++++++++++++++++++++++------------------ 1 file changed, 87 insertions(+), 68 deletions(-) -- 2.10.0
[toc] | [next] | [standalone]
| From | SF Markus Elfring <elfring@users.sourceforge.net> |
|---|---|
| Date | 2016-09-14 16:10 +0200 |
| Subject | [PATCH 01/11] virtio_console: Use kmalloc_array() in init_vqs() |
| Message-ID | <shj2W-1R7-3@gated-at.bofh.it> |
| In reply to | #1483324 |
From: Markus Elfring <elfring@users.sourceforge.net>
Date: Wed, 14 Sep 2016 11:23:59 +0200
* Multiplications for the size determination of memory allocations
indicated that array data structures should be processed.
Thus use the corresponding function "kmalloc_array".
This issue was detected by using the Coccinelle software.
* Replace the specifications of data types by pointer dereferences
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>
---
drivers/char/virtio_console.c | 18 +++++++++++-------
1 file changed, 11 insertions(+), 7 deletions(-)
diff --git a/drivers/char/virtio_console.c b/drivers/char/virtio_console.c
index d2406fe..325ebc6 100644
--- a/drivers/char/virtio_console.c
+++ b/drivers/char/virtio_console.c
@@ -1881,13 +1881,17 @@ static int init_vqs(struct ports_device *portdev)
nr_ports = portdev->config.max_nr_ports;
nr_queues = use_multiport(portdev) ? (nr_ports + 1) * 2 : 2;
- vqs = kmalloc(nr_queues * sizeof(struct virtqueue *), GFP_KERNEL);
- io_callbacks = kmalloc(nr_queues * sizeof(vq_callback_t *), GFP_KERNEL);
- io_names = kmalloc(nr_queues * sizeof(char *), GFP_KERNEL);
- portdev->in_vqs = kmalloc(nr_ports * sizeof(struct virtqueue *),
- GFP_KERNEL);
- portdev->out_vqs = kmalloc(nr_ports * sizeof(struct virtqueue *),
- GFP_KERNEL);
+ vqs = kmalloc_array(nr_queues, sizeof(*vqs), GFP_KERNEL);
+ io_callbacks = kmalloc_array(nr_queues,
+ sizeof(*io_callbacks),
+ GFP_KERNEL);
+ io_names = kmalloc_array(nr_queues, sizeof(*io_names), GFP_KERNEL);
+ portdev->in_vqs = kmalloc_array(nr_ports,
+ sizeof(*portdev->in_vqs),
+ GFP_KERNEL);
+ portdev->out_vqs = kmalloc_array(nr_ports,
+ sizeof(*portdev->out_vqs),
+ GFP_KERNEL);
if (!vqs || !io_callbacks || !io_names || !portdev->in_vqs ||
!portdev->out_vqs) {
err = -ENOMEM;
--
2.10.0
[toc] | [prev] | [next] | [standalone]
| From | SF Markus Elfring <elfring@users.sourceforge.net> |
|---|---|
| Date | 2016-09-14 16:10 +0200 |
| Subject | [PATCH 04/11] virtio_console: Rename jump labels in virtcons_probe() |
| Message-ID | <shj2W-1R7-5@gated-at.bofh.it> |
| In reply to | #1483324 |
From: Markus Elfring <elfring@users.sourceforge.net>
Date: Wed, 14 Sep 2016 14:24:05 +0200
Adjust jump labels according to the current Linux coding style convention.
Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
drivers/char/virtio_console.c | 17 ++++++++---------
1 file changed, 8 insertions(+), 9 deletions(-)
diff --git a/drivers/char/virtio_console.c b/drivers/char/virtio_console.c
index 004314e..768bbb7 100644
--- a/drivers/char/virtio_console.c
+++ b/drivers/char/virtio_console.c
@@ -2037,7 +2037,7 @@ static int virtcons_probe(struct virtio_device *vdev)
portdev = kmalloc(sizeof(*portdev), GFP_KERNEL);
if (!portdev) {
err = -ENOMEM;
- goto fail;
+ goto exit;
}
/* Attach this portdev to this virtio_device, and vice-versa. */
@@ -2051,7 +2051,7 @@ static int virtcons_probe(struct virtio_device *vdev)
"Error %d registering chrdev for device %u\n",
portdev->chr_major, vdev->index);
err = portdev->chr_major;
- goto free;
+ goto free_port;
}
multiport = false;
@@ -2068,7 +2068,7 @@ static int virtcons_probe(struct virtio_device *vdev)
err = init_vqs(portdev);
if (err < 0) {
dev_err(&vdev->dev, "Error %d initializing vqs\n", err);
- goto free_chrdev;
+ goto unregister;
}
spin_lock_init(&portdev->ports_lock);
@@ -2091,7 +2091,7 @@ static int virtcons_probe(struct virtio_device *vdev)
dev_err(&vdev->dev,
"Error allocating buffers for control queue\n");
err = -ENOMEM;
- goto free_vqs;
+ goto send_control_message;
}
} else {
/*
@@ -2121,17 +2121,16 @@ static int virtcons_probe(struct virtio_device *vdev)
wait_for_completion(&early_console_added);
return 0;
-
-free_vqs:
+ send_control_message:
/* The host might want to notify mgmt sw about device add failure */
__send_control_msg(portdev, VIRTIO_CONSOLE_BAD_ID,
VIRTIO_CONSOLE_DEVICE_READY, 0);
remove_vqs(portdev);
-free_chrdev:
+ unregister:
unregister_chrdev(portdev->chr_major, "virtio-portsdev");
-free:
+ free_port:
kfree(portdev);
-fail:
+ exit:
return err;
}
--
2.10.0
[toc] | [prev] | [next] | [standalone]
| From | SF Markus Elfring <elfring@users.sourceforge.net> |
|---|---|
| Date | 2016-09-14 16:10 +0200 |
| Subject | [PATCH 09/11] virtio_console: Rename a jump label in __send_to_port() |
| Message-ID | <shj2W-1R7-9@gated-at.bofh.it> |
| In reply to | #1483324 |
From: Markus Elfring <elfring@users.sourceforge.net>
Date: Wed, 14 Sep 2016 15:15:06 +0200
Adjust a jump label according to the current Linux coding style convention.
Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
drivers/char/virtio_console.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/drivers/char/virtio_console.c b/drivers/char/virtio_console.c
index babc812..69c6718 100644
--- a/drivers/char/virtio_console.c
+++ b/drivers/char/virtio_console.c
@@ -634,14 +634,14 @@ static ssize_t __send_to_port(struct port *port, struct scatterlist *sg,
if (err) {
in_count = 0;
- goto done;
+ goto unlock;
}
if (out_vq->num_free == 0)
port->outvq_full = true;
if (nonblock)
- goto done;
+ goto unlock;
/*
* Wait till the host acknowledges it pushed out the data we
@@ -655,7 +655,7 @@ static ssize_t __send_to_port(struct port *port, struct scatterlist *sg,
while (!virtqueue_get_buf(out_vq, &len)
&& !virtqueue_is_broken(out_vq))
cpu_relax();
-done:
+ unlock:
spin_unlock_irqrestore(&port->outvq_lock, flags);
port->stats.bytes_sent += in_count;
--
2.10.0
[toc] | [prev] | [next] | [standalone]
| From | SF Markus Elfring <elfring@users.sourceforge.net> |
|---|---|
| Date | 2016-09-14 16:10 +0200 |
| Subject | [PATCH 03/11] virtio_console: Rename a jump label in init() |
| Message-ID | <shj2W-1R7-11@gated-at.bofh.it> |
| In reply to | #1483324 |
From: Markus Elfring <elfring@users.sourceforge.net>
Date: Wed, 14 Sep 2016 14:10:24 +0200
Adjust jump labels according to the current Linux coding style convention.
Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
drivers/char/virtio_console.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/drivers/char/virtio_console.c b/drivers/char/virtio_console.c
index bf0ad57..004314e 100644
--- a/drivers/char/virtio_console.c
+++ b/drivers/char/virtio_console.c
@@ -2309,7 +2309,7 @@ static int __init init(void)
err = register_virtio_driver(&virtio_console);
if (err < 0) {
pr_err("Error %d registering virtio driver\n", err);
- goto free;
+ goto remove;
}
err = register_virtio_driver(&virtio_rproc_serial);
if (err < 0) {
@@ -2318,9 +2318,9 @@ static int __init init(void)
goto unregister;
}
return 0;
-unregister:
+ unregister:
unregister_virtio_driver(&virtio_console);
-free:
+ remove:
debugfs_remove_recursive(pdrvdata.debugfs_dir);
class_destroy(pdrvdata.class);
return err;
--
2.10.0
[toc] | [prev] | [next] | [standalone]
| From | SF Markus Elfring <elfring@users.sourceforge.net> |
|---|---|
| Date | 2016-09-14 16:10 +0200 |
| Subject | [PATCH 06/11] virtio_console: Rename a jump label in port_fops_open() |
| Message-ID | <shj2W-1R7-13@gated-at.bofh.it> |
| In reply to | #1483324 |
From: Markus Elfring <elfring@users.sourceforge.net>
Date: Wed, 14 Sep 2016 14:58:24 +0200
Adjust a jump label according to the current Linux coding style convention.
Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
drivers/char/virtio_console.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/drivers/char/virtio_console.c b/drivers/char/virtio_console.c
index 40b8775..99dc659 100644
--- a/drivers/char/virtio_console.c
+++ b/drivers/char/virtio_console.c
@@ -1058,7 +1058,7 @@ static int port_fops_open(struct inode *inode, struct file *filp)
*/
if (is_console_port(port)) {
ret = -ENXIO;
- goto out;
+ goto put_ref;
}
/* Allow only one process to open a particular port at a time */
@@ -1066,7 +1066,7 @@ static int port_fops_open(struct inode *inode, struct file *filp)
if (port->guest_connected) {
spin_unlock_irq(&port->inbuf_lock);
ret = -EBUSY;
- goto out;
+ goto put_ref;
}
port->guest_connected = true;
@@ -1087,7 +1087,7 @@ static int port_fops_open(struct inode *inode, struct file *filp)
send_control_msg(filp->private_data, VIRTIO_CONSOLE_PORT_OPEN, 1);
return 0;
-out:
+ put_ref:
kref_put(&port->kref, remove_port);
return ret;
}
--
2.10.0
[toc] | [prev] | [next] | [standalone]
| From | SF Markus Elfring <elfring@users.sourceforge.net> |
|---|---|
| Date | 2016-09-14 16:10 +0200 |
| Subject | [PATCH 02/11] virtio_console: Less function calls in init_vqs() after error detection |
| Message-ID | <shj2W-1R7-21@gated-at.bofh.it> |
| In reply to | #1483324 |
From: Markus Elfring <elfring@users.sourceforge.net>
Date: Wed, 14 Sep 2016 14:00:35 +0200
The kfree() function was called in up to five cases
by the init_vqs() function during error handling even if
the passed variable contained a null pointer.
* Return directly after a call of the function "kmalloc_array" failed
at the beginning.
* Split a condition check for memory allocation failures so that
each pointer from these function calls will be checked immediately.
See also background information:
Topic "CWE-754: Improper check for unusual or exceptional conditions"
Link: https://cwe.mitre.org/data/definitions/754.html
* Adjust jump targets according to the Linux coding style convention.
Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
drivers/char/virtio_console.c | 32 ++++++++++++++++++++++++++------
1 file changed, 26 insertions(+), 6 deletions(-)
diff --git a/drivers/char/virtio_console.c b/drivers/char/virtio_console.c
index 325ebc6..bf0ad57 100644
--- a/drivers/char/virtio_console.c
+++ b/drivers/char/virtio_console.c
@@ -1882,20 +1882,37 @@ static int init_vqs(struct ports_device *portdev)
nr_queues = use_multiport(portdev) ? (nr_ports + 1) * 2 : 2;
vqs = kmalloc_array(nr_queues, sizeof(*vqs), GFP_KERNEL);
+ if (!vqs)
+ return -ENOMEM;
+
io_callbacks = kmalloc_array(nr_queues,
sizeof(*io_callbacks),
GFP_KERNEL);
+ if (!io_callbacks) {
+ err = -ENOMEM;
+ goto free_vqs;
+ }
+
io_names = kmalloc_array(nr_queues, sizeof(*io_names), GFP_KERNEL);
+ if (!io_names) {
+ err = -ENOMEM;
+ goto free_callbacks;
+ }
+
portdev->in_vqs = kmalloc_array(nr_ports,
sizeof(*portdev->in_vqs),
GFP_KERNEL);
+ if (!portdev->in_vqs) {
+ err = -ENOMEM;
+ goto free_names;
+ }
+
portdev->out_vqs = kmalloc_array(nr_ports,
sizeof(*portdev->out_vqs),
GFP_KERNEL);
- if (!vqs || !io_callbacks || !io_names || !portdev->in_vqs ||
- !portdev->out_vqs) {
+ if (!portdev->out_vqs) {
err = -ENOMEM;
- goto free;
+ goto free_in_vqs;
}
/*
@@ -1929,7 +1946,7 @@ static int init_vqs(struct ports_device *portdev)
io_callbacks,
(const char **)io_names);
if (err)
- goto free;
+ goto free_out_vqs;
j = 0;
portdev->in_vqs[0] = vqs[0];
@@ -1950,12 +1967,15 @@ static int init_vqs(struct ports_device *portdev)
kfree(vqs);
return 0;
-
-free:
+ free_out_vqs:
kfree(portdev->out_vqs);
+ free_in_vqs:
kfree(portdev->in_vqs);
+ free_names:
kfree(io_names);
+ free_callbacks:
kfree(io_callbacks);
+ free_vqs:
kfree(vqs);
return err;
--
2.10.0
[toc] | [prev] | [next] | [standalone]
| From | Amit Shah <amit.shah@redhat.com> |
|---|---|
| Date | 2016-09-21 14:20 +0200 |
| Subject | Re: [PATCH 02/11] virtio_console: Less function calls in init_vqs() after error detection |
| Message-ID | <sjOFj-sk-5@gated-at.bofh.it> |
| In reply to | #1483341 |
Hi, On (Wed) 14 Sep 2016 [16:01:28], SF Markus Elfring wrote: > From: Markus Elfring <elfring@users.sourceforge.net> > Date: Wed, 14 Sep 2016 14:00:35 +0200 > > The kfree() function was called in up to five cases > by the init_vqs() function during error handling even if > the passed variable contained a null pointer. > > * Return directly after a call of the function "kmalloc_array" failed > at the beginning. > > * Split a condition check for memory allocation failures so that > each pointer from these function calls will be checked immediately. > > See also background information: > Topic "CWE-754: Improper check for unusual or exceptional conditions" > Link: https://cwe.mitre.org/data/definitions/754.html > > * Adjust jump targets according to the Linux coding style convention. So I've seen this series and I'm not yet sure how I feel about the patches - f.e. in this one, it adds more lines than it removes to achieve the same effect. I think the code is currently more readable than after these changes. And even if kfree is called multiple times, it isn't a huge bother -- it's error case anyway, very unlikely to trigger, but keeps everything very readble. Amit
[toc] | [prev] | [next] | [standalone]
| From | SF Markus Elfring <elfring@users.sourceforge.net> |
|---|---|
| Date | 2016-09-21 15:10 +0200 |
| Subject | Re: virtio_console: Less function calls in init_vqs() after error detection |
| Message-ID | <sjPrI-XD-11@gated-at.bofh.it> |
| In reply to | #1488069 |
>> The kfree() function was called in up to five cases >> by the init_vqs() function during error handling even if >> the passed variable contained a null pointer. >> >> * Return directly after a call of the function "kmalloc_array" failed >> at the beginning. >> >> * Split a condition check for memory allocation failures so that >> each pointer from these function calls will be checked immediately. >> >> See also background information: >> Topic "CWE-754: Improper check for unusual or exceptional conditions" >> Link: https://cwe.mitre.org/data/definitions/754.html >> >> * Adjust jump targets according to the Linux coding style convention. > > So I've seen this series and I'm not yet sure how I feel about the > patches - f.e. in this one, it adds more lines than it removes to > achieve the same effect. I find this consequence still debatable. > I think the code is currently more readable than after these changes. Thanks for your constructive feedback. Can it be that an other software development concern is eventually overlooked? > And even if kfree is called multiple times, it isn't a huge bother I know also that the implementation of this function tolerates the passing of null pointers. > -- it's error case anyway, very unlikely to trigger, but keeps everything very readble. I suggest to reconsider this design detail if it is really acceptable for the safe implementation of such a software module. * How much will it matter in general that four function call were performed in this use case without checking their return values immediately? * Should it usually be determined quicker if a required resource like memory could be acquired before trying the next allocation? Regards, Markus
[toc] | [prev] | [next] | [standalone]
| From | SF Markus Elfring <elfring@users.sourceforge.net> |
|---|---|
| Date | 2016-09-14 16:10 +0200 |
| Subject | [PATCH 08/11] virtio_console: Rename jump labels in port_fops_write() |
| Message-ID | <shj2W-1R7-23@gated-at.bofh.it> |
| In reply to | #1483324 |
From: Markus Elfring <elfring@users.sourceforge.net>
Date: Wed, 14 Sep 2016 15:07:42 +0200
Adjust jump labels according to the current Linux coding style convention.
Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
drivers/char/virtio_console.c | 9 ++++-----
1 file changed, 4 insertions(+), 5 deletions(-)
diff --git a/drivers/char/virtio_console.c b/drivers/char/virtio_console.c
index d8681d9..babc812 100644
--- a/drivers/char/virtio_console.c
+++ b/drivers/char/virtio_console.c
@@ -842,7 +842,7 @@ static ssize_t port_fops_write(struct file *filp, const char __user *ubuf,
ret = copy_from_user(buf->buf, ubuf, count);
if (ret) {
ret = -EFAULT;
- goto free_buf;
+ goto free_buffer;
}
/*
@@ -857,11 +857,10 @@ static ssize_t port_fops_write(struct file *filp, const char __user *ubuf,
ret = __send_to_port(port, sg, 1, count, buf, nonblock);
if (nonblock && ret > 0)
- goto out;
-
-free_buf:
+ goto exit;
+ free_buffer:
free_buf(buf, true);
-out:
+ exit:
return ret;
}
--
2.10.0
[toc] | [prev] | [next] | [standalone]
| From | SF Markus Elfring <elfring@users.sourceforge.net> |
|---|---|
| Date | 2016-09-14 16:10 +0200 |
| Subject | [PATCH 10/11] virtio_console: Rename jump labels in alloc_buf() |
| Message-ID | <shj2W-1R7-19@gated-at.bofh.it> |
| In reply to | #1483324 |
From: Markus Elfring <elfring@users.sourceforge.net>
Date: Wed, 14 Sep 2016 15:20:30 +0200
Adjust jump labels according to the current Linux coding style convention.
Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
drivers/char/virtio_console.c | 11 +++++------
1 file changed, 5 insertions(+), 6 deletions(-)
diff --git a/drivers/char/virtio_console.c b/drivers/char/virtio_console.c
index 69c6718..0c4d4e7 100644
--- a/drivers/char/virtio_console.c
+++ b/drivers/char/virtio_console.c
@@ -431,7 +431,7 @@ static struct port_buffer *alloc_buf(struct virtqueue *vq, size_t buf_size,
buf = kmalloc(sizeof(*buf) + sizeof(struct scatterlist) * pages,
GFP_KERNEL);
if (!buf)
- goto fail;
+ goto exit;
buf->sgpages = pages;
if (pages > 0) {
@@ -451,7 +451,7 @@ static struct port_buffer *alloc_buf(struct virtqueue *vq, size_t buf_size,
* in dma-coherent.c
*/
if (!vq->vdev->dev.parent || !vq->vdev->dev.parent->parent)
- goto free_buf;
+ goto free_buffer;
buf->dev = vq->vdev->dev.parent->parent;
/* Increase device refcnt to avoid freeing it */
@@ -464,15 +464,14 @@ static struct port_buffer *alloc_buf(struct virtqueue *vq, size_t buf_size,
}
if (!buf->buf)
- goto free_buf;
+ goto free_buffer;
buf->len = 0;
buf->offset = 0;
buf->size = buf_size;
return buf;
-
-free_buf:
+ free_buffer:
kfree(buf);
-fail:
+ exit:
return NULL;
}
--
2.10.0
[toc] | [prev] | [next] | [standalone]
| From | SF Markus Elfring <elfring@users.sourceforge.net> |
|---|---|
| Date | 2016-09-14 16:10 +0200 |
| Subject | [PATCH 05/11] virtio_console: Rename jump labels in add_port() |
| Message-ID | <shj2W-1R7-27@gated-at.bofh.it> |
| In reply to | #1483324 |
From: Markus Elfring <elfring@users.sourceforge.net>
Date: Wed, 14 Sep 2016 14:53:00 +0200
Adjust jump labels according to the current Linux coding style convention.
Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
drivers/char/virtio_console.c | 21 ++++++++++-----------
1 file changed, 10 insertions(+), 11 deletions(-)
diff --git a/drivers/char/virtio_console.c b/drivers/char/virtio_console.c
index 768bbb7..40b8775 100644
--- a/drivers/char/virtio_console.c
+++ b/drivers/char/virtio_console.c
@@ -1399,7 +1399,7 @@ static int add_port(struct ports_device *portdev, u32 id)
port = kmalloc(sizeof(*port), GFP_KERNEL);
if (!port) {
err = -ENOMEM;
- goto fail;
+ goto send_control_message;
}
kref_init(&port->kref);
@@ -1434,7 +1434,7 @@ static int add_port(struct ports_device *portdev, u32 id)
if (err < 0) {
dev_err(&port->portdev->vdev->dev,
"Error %d adding cdev for port %u\n", err, id);
- goto free_cdev;
+ goto delete_cdev;
}
port->dev = device_create(pdrvdata.class, &port->portdev->vdev->dev,
devt, port, "vport%up%u",
@@ -1444,7 +1444,7 @@ static int add_port(struct ports_device *portdev, u32 id)
dev_err(&port->portdev->vdev->dev,
"Error %d creating device for port %u\n",
err, id);
- goto free_cdev;
+ goto delete_cdev;
}
spin_lock_init(&port->inbuf_lock);
@@ -1456,7 +1456,7 @@ static int add_port(struct ports_device *portdev, u32 id)
if (!nr_added_bufs) {
dev_err(port->dev, "Error allocating inbufs\n");
err = -ENOMEM;
- goto free_device;
+ goto destroy_device;
}
if (is_rproc_serial(port->portdev->vdev))
@@ -1473,7 +1473,7 @@ static int add_port(struct ports_device *portdev, u32 id)
*/
err = init_port_console(port);
if (err)
- goto free_inbufs;
+ goto free_buffers;
}
spin_lock_irq(&portdev->ports_lock);
@@ -1500,17 +1500,16 @@ static int add_port(struct ports_device *portdev, u32 id)
&port_debugfs_ops);
}
return 0;
-
-free_inbufs:
+ free_buffers:
while ((buf = virtqueue_detach_unused_buf(port->in_vq)))
free_buf(buf, true);
-free_device:
+ destroy_device:
device_destroy(pdrvdata.class, port->dev->devt);
-free_cdev:
+ delete_cdev:
cdev_del(port->cdev);
-free_port:
+ free_port:
kfree(port);
-fail:
+ send_control_message:
/* The host might want to notify management sw about port add failure */
__send_control_msg(portdev, id, VIRTIO_CONSOLE_PORT_READY, 0);
return err;
--
2.10.0
[toc] | [prev] | [next] | [standalone]
| From | SF Markus Elfring <elfring@users.sourceforge.net> |
|---|---|
| Date | 2016-09-14 16:10 +0200 |
| Subject | [PATCH 07/11] virtio_console: Rename a jump label in port_fops_splice_write() |
| Message-ID | <shj2W-1R7-39@gated-at.bofh.it> |
| In reply to | #1483324 |
From: Markus Elfring <elfring@users.sourceforge.net>
Date: Wed, 14 Sep 2016 15:01:51 +0200
Adjust a jump label according to the current Linux coding style convention.
Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
drivers/char/virtio_console.c | 9 ++++-----
1 file changed, 4 insertions(+), 5 deletions(-)
diff --git a/drivers/char/virtio_console.c b/drivers/char/virtio_console.c
index 99dc659..d8681d9 100644
--- a/drivers/char/virtio_console.c
+++ b/drivers/char/virtio_console.c
@@ -947,17 +947,17 @@ static ssize_t port_fops_splice_write(struct pipe_inode_info *pipe,
pipe_lock(pipe);
if (!pipe->nrbufs) {
ret = 0;
- goto error_out;
+ goto unlock;
}
ret = wait_port_writable(port, filp->f_flags & O_NONBLOCK);
if (ret < 0)
- goto error_out;
+ goto unlock;
buf = alloc_buf(port->out_vq, 0, pipe->nrbufs);
if (!buf) {
ret = -ENOMEM;
- goto error_out;
+ goto unlock;
}
sgl.n = 0;
@@ -973,8 +973,7 @@ static ssize_t port_fops_splice_write(struct pipe_inode_info *pipe,
if (unlikely(ret <= 0))
free_buf(buf, true);
return ret;
-
-error_out:
+ unlock:
pipe_unlock(pipe);
return ret;
}
--
2.10.0
[toc] | [prev] | [next] | [standalone]
| From | SF Markus Elfring <elfring@users.sourceforge.net> |
|---|---|
| Date | 2016-09-14 16:20 +0200 |
| Subject | [PATCH 11/11] virtio_console: Rename a jump label in five functions |
| Message-ID | <shjcB-1Ui-1@gated-at.bofh.it> |
| In reply to | #1483324 |
From: Markus Elfring <elfring@users.sourceforge.net>
Date: Wed, 14 Sep 2016 15:37:52 +0200
Adjust a jump label according to the current Linux coding style convention.
Thus replace the identifier "out" by "unlock".
Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
drivers/char/virtio_console.c | 20 ++++++++++----------
1 file changed, 10 insertions(+), 10 deletions(-)
diff --git a/drivers/char/virtio_console.c b/drivers/char/virtio_console.c
index 0c4d4e7..6c90c9c 100644
--- a/drivers/char/virtio_console.c
+++ b/drivers/char/virtio_console.c
@@ -257,11 +257,11 @@ static struct port *find_port_by_vtermno(u32 vtermno)
list_for_each_entry(cons, &pdrvdata.consoles, list) {
if (cons->vtermno == vtermno) {
port = container_of(cons, struct port, cons);
- goto out;
+ goto unlock;
}
}
port = NULL;
-out:
+ unlock:
spin_unlock_irqrestore(&pdrvdata_lock, flags);
return port;
}
@@ -276,11 +276,11 @@ static struct port *find_port_by_devt_in_portdev(struct ports_device *portdev,
list_for_each_entry(port, &portdev->ports, list) {
if (port->cdev->dev == dev) {
kref_get(&port->kref);
- goto out;
+ goto unlock;
}
}
port = NULL;
-out:
+ unlock:
spin_unlock_irqrestore(&portdev->ports_lock, flags);
return port;
@@ -296,10 +296,10 @@ static struct port *find_port_by_devt(dev_t dev)
list_for_each_entry(portdev, &pdrvdata.portdevs, list) {
port = find_port_by_devt_in_portdev(portdev, dev);
if (port)
- goto out;
+ goto unlock;
}
port = NULL;
-out:
+ unlock:
spin_unlock_irqrestore(&pdrvdata_lock, flags);
return port;
}
@@ -312,9 +312,9 @@ static struct port *find_port_by_id(struct ports_device *portdev, u32 id)
spin_lock_irqsave(&portdev->ports_lock, flags);
list_for_each_entry(port, &portdev->ports, list)
if (port->id == id)
- goto out;
+ goto unlock;
port = NULL;
-out:
+ unlock:
spin_unlock_irqrestore(&portdev->ports_lock, flags);
return port;
@@ -329,9 +329,9 @@ static struct port *find_port_by_vq(struct ports_device *portdev,
spin_lock_irqsave(&portdev->ports_lock, flags);
list_for_each_entry(port, &portdev->ports, list)
if (port->in_vq == vq || port->out_vq == vq)
- goto out;
+ goto unlock;
port = NULL;
-out:
+ unlock:
spin_unlock_irqrestore(&portdev->ports_lock, flags);
return port;
}
--
2.10.0
[toc] | [prev] | [standalone]
Back to top | Article view | linux.kernel
csiph-web