All of lore.kernel.org
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH 1/2] char: Constify data pointed by few arguments and local variables
@ 2017-03-05 21:45 Krzysztof Kozlowski
  2017-03-05 21:45 ` [Qemu-devel] [PATCH 2/2] char: Remove confusing mix of assignment with " Krzysztof Kozlowski
  0 siblings, 1 reply; 2+ messages in thread
From: Krzysztof Kozlowski @ 2017-03-05 21:45 UTC (permalink / raw)
  To: Paolo Bonzini, Marc-André Lureau, Peter Maydell, qemu-devel
  Cc: Krzysztof Kozlowski

In few places the function arguments and local variables are not
modifying data passed through pointers so this can be made const for
code safeness.

Signed-off-by: Krzysztof Kozlowski <krzk@kernel.org>
---
 chardev/char.c        | 18 +++++++++---------
 include/sysemu/char.h |  2 +-
 2 files changed, 10 insertions(+), 10 deletions(-)

diff --git a/chardev/char.c b/chardev/char.c
index 54cd5f408150..a2571409bf65 100644
--- a/chardev/char.c
+++ b/chardev/char.c
@@ -102,7 +102,7 @@ static void qemu_chr_fe_write_log(Chardev *s,
 static int qemu_chr_fe_write_buffer(Chardev *s,
                                     const uint8_t *buf, int len, int *offset)
 {
-    ChardevClass *cc = CHARDEV_GET_CLASS(s);
+    const ChardevClass *cc = CHARDEV_GET_CLASS(s);
     int res = 0;
     *offset = 0;
 
@@ -129,7 +129,7 @@ static int qemu_chr_fe_write_buffer(Chardev *s,
     return res;
 }
 
-static bool qemu_chr_replay(Chardev *chr)
+static bool qemu_chr_replay(const Chardev *chr)
 {
     return qemu_chr_has_feature(chr, QEMU_CHAR_FEATURE_REPLAY);
 }
@@ -137,7 +137,7 @@ static bool qemu_chr_replay(Chardev *chr)
 int qemu_chr_fe_write(CharBackend *be, const uint8_t *buf, int len)
 {
     Chardev *s = be->chr;
-    ChardevClass *cc;
+    const ChardevClass *cc;
     int ret;
 
     if (!s) {
@@ -369,7 +369,7 @@ void qemu_chr_fe_printf(CharBackend *be, const char *fmt, ...)
 static void qemu_char_open(Chardev *chr, ChardevBackend *backend,
                            bool *be_opened, Error **errp)
 {
-    ChardevClass *cc = CHARDEV_GET_CLASS(chr);
+    const ChardevClass *cc = CHARDEV_GET_CLASS(chr);
     /* Any ChardevCommon member would work */
     ChardevCommon *common = backend ? backend->u.null.data : NULL;
 
@@ -513,10 +513,10 @@ unavailable:
     return false;
 }
 
-static bool qemu_chr_is_busy(Chardev *s)
+static bool qemu_chr_is_busy(const Chardev *s)
 {
     if (CHARDEV_IS_MUX(s)) {
-        MuxChardev *d = MUX_CHARDEV(s);
+        const MuxChardev *d = MUX_CHARDEV(s);
         return d->mux_cnt >= 0;
     } else {
         return s->be != NULL;
@@ -549,7 +549,7 @@ void qemu_chr_fe_set_handlers(CharBackend *b,
                               bool set_open)
 {
     Chardev *s;
-    ChardevClass *cc;
+    const ChardevClass *cc;
     int fe_open;
 
     s = b->chr;
@@ -603,7 +603,7 @@ void qemu_chr_fe_take_focus(CharBackend *b)
 
 int qemu_chr_wait_connected(Chardev *chr, Error **errp)
 {
-    ChardevClass *cc = CHARDEV_GET_CLASS(chr);
+    const ChardevClass *cc = CHARDEV_GET_CLASS(chr);
 
     if (cc->chr_wait_connected) {
         return cc->chr_wait_connected(chr, errp);
@@ -1223,7 +1223,7 @@ QemuOptsList qemu_chardev_opts = {
     },
 };
 
-bool qemu_chr_has_feature(Chardev *chr,
+bool qemu_chr_has_feature(const Chardev *chr,
                           ChardevFeature feature)
 {
     return test_bit(feature, chr->features);
diff --git a/include/sysemu/char.h b/include/sysemu/char.h
index 450881d42cb5..2b11bbc40692 100644
--- a/include/sysemu/char.h
+++ b/include/sysemu/char.h
@@ -432,7 +432,7 @@ void qemu_chr_fe_accept_input(CharBackend *be);
 int qemu_chr_add_client(Chardev *s, int fd);
 Chardev *qemu_chr_find(const char *name);
 
-bool qemu_chr_has_feature(Chardev *chr,
+bool qemu_chr_has_feature(const Chardev *chr,
                           ChardevFeature feature);
 void qemu_chr_set_feature(Chardev *chr,
                           ChardevFeature feature);
-- 
2.9.3

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* [Qemu-devel] [PATCH 2/2] char: Remove confusing mix of assignment with local variables
  2017-03-05 21:45 [Qemu-devel] [PATCH 1/2] char: Constify data pointed by few arguments and local variables Krzysztof Kozlowski
@ 2017-03-05 21:45 ` Krzysztof Kozlowski
  0 siblings, 0 replies; 2+ messages in thread
From: Krzysztof Kozlowski @ 2017-03-05 21:45 UTC (permalink / raw)
  To: Paolo Bonzini, Marc-André Lureau, Peter Maydell, qemu-devel
  Cc: Krzysztof Kozlowski

The assignment under pointed offset was put next to declaration of local
variables.  This might be quite confusing as the assignment looks like
duplicated declaration of offset variable.

Signed-off-by: Krzysztof Kozlowski <krzk@kernel.org>
---
 chardev/char.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/chardev/char.c b/chardev/char.c
index a2571409bf65..b9343e03b9ec 100644
--- a/chardev/char.c
+++ b/chardev/char.c
@@ -104,6 +104,7 @@ static int qemu_chr_fe_write_buffer(Chardev *s,
 {
     const ChardevClass *cc = CHARDEV_GET_CLASS(s);
     int res = 0;
+
     *offset = 0;
 
     qemu_mutex_lock(&s->chr_write_lock);
-- 
2.9.3

^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2017-03-05 21:45 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-03-05 21:45 [Qemu-devel] [PATCH 1/2] char: Constify data pointed by few arguments and local variables Krzysztof Kozlowski
2017-03-05 21:45 ` [Qemu-devel] [PATCH 2/2] char: Remove confusing mix of assignment with " Krzysztof Kozlowski

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.