Skip to contentSkip to conversation

char: Constify data pointed by few arguments and local variables

PATCH New Krzysztof Kozlowski 1 participant 2 messages Mar 5, 2017

lore
Share & tools
lore
#0 lore raw

PATCH 1/2 char: Constify data pointed by few arguments and local variables

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.

---
 chardev/char.c        | 18 +++++++++---------
 include/sysemu/char.h |  2 +-
 2 files changed, 10 insertions(+), 10 deletions(-)
chardev/char.c +9 -9
index 54cd5f408150..a2571409bf65 100644
@@ -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);
include/sysemu/char.h +1 -1
index 450881d42cb5..2b11bbc40692 100644
@@ -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);
Signature · 1 line
2.9.3
#1 lore raw

PATCH 2/2 char: Remove confusing mix of assignment with local variables

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.

---
 chardev/char.c | 1 +
 1 file changed, 1 insertion(+)
chardev/char.c +1 -0
index a2571409bf65..b9343e03b9ec 100644
@@ -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);
Signature · 1 line
2.9.3