Module: xenomai-forge
Branch: next
Commit: f8490220177c0c007ae98dac4a956ecd0de89120
URL:    
http://git.xenomai.org/?p=xenomai-forge.git;a=commit;h=f8490220177c0c007ae98dac4a956ecd0de89120

Author: Philippe Gerum <r...@xenomai.org>
Date:   Thu Apr 17 11:44:08 2014 +0200

cobalt/kernel: generalize use of safe *snprintf()

Make sure to have the destination string null-terminated on character
overflow.

---

 include/cobalt/kernel/Makefile.am       |    1 +
 include/cobalt/kernel/Makefile.in       |    1 +
 include/cobalt/kernel/ancillaries.h     |   42 +++++++++++++++++++++++++++++++
 include/cobalt/kernel/assert.h          |    1 +
 include/cobalt/kernel/rtdm/driver.h     |    1 +
 kernel/cobalt/assert.c                  |    2 +-
 kernel/cobalt/clock.c                   |    2 +-
 kernel/cobalt/heap.c                    |    4 +--
 kernel/cobalt/intr.c                    |    2 +-
 kernel/cobalt/posix/sem.c               |    2 +-
 kernel/cobalt/posix/thread.c            |    2 +-
 kernel/cobalt/rtdm/proc.c               |    2 +-
 kernel/cobalt/sched-quota.c             |    6 +++--
 kernel/cobalt/sched-rt.c                |    2 +-
 kernel/cobalt/sched-sporadic.c          |    4 +--
 kernel/cobalt/sched-tp.c                |    2 +-
 kernel/cobalt/sched-weak.c              |    2 +-
 kernel/cobalt/sched.c                   |    8 +++---
 kernel/cobalt/shadow.c                  |    2 +-
 kernel/cobalt/thread.c                  |    4 +--
 kernel/cobalt/timer.c                   |    8 +++---
 kernel/drivers/analogy/device.c         |   23 ++++++-----------
 kernel/drivers/analogy/rtdm_interface.c |    2 +-
 kernel/drivers/can/rtcan_dev.c          |    2 +-
 kernel/drivers/can/rtcan_module.c       |   10 ++++----
 kernel/drivers/ipc/bufp.c               |    2 +-
 kernel/drivers/ipc/iddp.c               |    2 +-
 kernel/drivers/ipc/xddp.c               |    2 +-
 kernel/drivers/serial/16550A.c          |    2 +-
 kernel/drivers/serial/mpc52xx_uart.c    |    2 +-
 kernel/drivers/serial/rt_imx_uart.c     |    2 +-
 kernel/drivers/testing/rtdmtest.c       |    2 +-
 kernel/drivers/testing/switchtest.c     |    4 +--
 kernel/drivers/testing/timerbench.c     |    2 +-
 34 files changed, 99 insertions(+), 58 deletions(-)

diff --git a/include/cobalt/kernel/Makefile.am 
b/include/cobalt/kernel/Makefile.am
index d2375dc..ad6c7f2 100644
--- a/include/cobalt/kernel/Makefile.am
+++ b/include/cobalt/kernel/Makefile.am
@@ -1,5 +1,6 @@
 
 noinst_HEADERS =       \
+       ancillaries.h   \
        apc.h           \
        arith.h         \
        assert.h        \
diff --git a/include/cobalt/kernel/Makefile.in 
b/include/cobalt/kernel/Makefile.in
index d3e7fb9..4b6e1da 100644
--- a/include/cobalt/kernel/Makefile.in
+++ b/include/cobalt/kernel/Makefile.in
@@ -351,6 +351,7 @@ top_build_prefix = @top_build_prefix@
 top_builddir = @top_builddir@
 top_srcdir = @top_srcdir@
 noinst_HEADERS = \
+       ancillaries.h   \
        apc.h           \
        arith.h         \
        assert.h        \
diff --git a/include/cobalt/kernel/ancillaries.h 
b/include/cobalt/kernel/ancillaries.h
new file mode 100644
index 0000000..e1e59f2
--- /dev/null
+++ b/include/cobalt/kernel/ancillaries.h
@@ -0,0 +1,42 @@
+/**
+ * @note Copyright (C) 2014 Philippe Gerum <r...@xenomai.org>.
+ *
+ * Xenomai is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published
+ * by the Free Software Foundation; either version 2 of the License,
+ * or (at your option) any later version.
+ *
+ * Xenomai is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Xenomai; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
+ * 02111-1307, USA.
+ */
+#ifndef _COBALT_KERNEL_ANCILLARIES_H
+#define _COBALT_KERNEL_ANCILLARIES_H
+
+#include <linux/kernel.h>
+
+#define ksformat(__dst, __len, __fmt, __args...)                       \
+       ({                                                              \
+               size_t __ret;                                           \
+               __ret = snprintf(__dst, __len, __fmt, ##__args);        \
+               if (__ret >= __len)                                     \
+                       __dst[__len-1] = '\0';                          \
+               __ret;                                                  \
+       })
+
+#define kvsformat(__dst, __len, __fmt, __ap)                           \
+       ({                                                              \
+               size_t __ret;                                           \
+               __ret = vsnprintf(__dst, __len, __fmt, __ap);           \
+               if (__ret >= __len)                                     \
+                       __dst[__len-1] = '\0';                          \
+               __ret;                                                  \
+       })
+
+#endif /* !_COBALT_KERNEL_ANCILLARIES_H */
diff --git a/include/cobalt/kernel/assert.h b/include/cobalt/kernel/assert.h
index 76eb06b..bf9be27 100644
--- a/include/cobalt/kernel/assert.h
+++ b/include/cobalt/kernel/assert.h
@@ -20,6 +20,7 @@
 #define _COBALT_KERNEL_ASSERT_H
 
 #include <cobalt/kernel/trace.h>
+#include <cobalt/kernel/ancillaries.h>
 
 #define XENO_INFO KERN_INFO    "[Xenomai] "
 #define XENO_WARN KERN_WARNING "[Xenomai] "
diff --git a/include/cobalt/kernel/rtdm/driver.h 
b/include/cobalt/kernel/rtdm/driver.h
index bfd3fab..50d6e02 100644
--- a/include/cobalt/kernel/rtdm/driver.h
+++ b/include/cobalt/kernel/rtdm/driver.h
@@ -39,6 +39,7 @@
 #include <cobalt/kernel/apc.h>
 #include <cobalt/kernel/shadow.h>
 #include <cobalt/kernel/init.h>
+#include <cobalt/kernel/ancillaries.h>
 #include <rtdm/rtdm.h>
 
 /* debug support */
diff --git a/kernel/cobalt/assert.c b/kernel/cobalt/assert.c
index 71240d1..bc0d87e 100644
--- a/kernel/cobalt/assert.c
+++ b/kernel/cobalt/assert.c
@@ -66,7 +66,7 @@ void __xnsys_fatal(const char *format, ...)
                        if (thread->sched != sched)
                                continue;
                        cprio = xnthread_current_priority(thread);
-                       snprintf(pbuf, sizeof(pbuf), "%3d", cprio);
+                       ksformat(pbuf, sizeof(pbuf), "%3d", cprio);
                        printk(KERN_ERR "%c%3u  %-6d %-8s %-8Lu %.8lx  %s\n",
                               thread == sched->curr ? '>' : ' ',
                               cpu,
diff --git a/kernel/cobalt/clock.c b/kernel/cobalt/clock.c
index 0a327dd..479b7b2 100644
--- a/kernel/cobalt/clock.c
+++ b/kernel/cobalt/clock.c
@@ -412,7 +412,7 @@ static int clock_vfile_show(struct 
xnvfile_snapshot_iterator *it, void *data)
                if (p->status & XNTIMER_PERIODIC)
                        xntimer_format_time(p->interval, interval_buf,
                                            sizeof(interval_buf));
-               snprintf(hit_buf, sizeof(hit_buf), "%u/%u",
+               ksformat(hit_buf, sizeof(hit_buf), "%u/%u",
                         p->scheduled, p->fired);
                xnvfile_printf(it,
                               "%-3u  %-20s  %-10s  %-10s  %-16s  %s\n",
diff --git a/kernel/cobalt/heap.c b/kernel/cobalt/heap.c
index 29f9cd8..dcc7129 100644
--- a/kernel/cobalt/heap.c
+++ b/kernel/cobalt/heap.c
@@ -329,7 +329,7 @@ int xnheap_init(struct xnheap *heap,
        init_extent(heap, extent);
        list_add_tail(&extent->link, &heap->extents);
 
-       snprintf(heap->label, sizeof(heap->label), "unlabeled @0x%p", heap);
+       ksformat(heap->label, sizeof(heap->label), "unlabeled @0x%p", heap);
 
        xnlock_get_irqsave(&nklock, s);
        list_add_tail(&heap->stat_link, &heapq);
@@ -364,7 +364,7 @@ void xnheap_set_label(struct xnheap *heap, const char 
*label, ...)
        va_start(args, label);
 
        xnlock_get_irqsave(&nklock, s);
-       vsnprintf(heap->label, sizeof(heap->label), label, args);
+       kvsformat(heap->label, sizeof(heap->label), label, args);
        xnlock_put_irqrestore(&nklock, s);
 
        va_end(args);
diff --git a/kernel/cobalt/intr.c b/kernel/cobalt/intr.c
index 0b82bd6..1ba8db4 100644
--- a/kernel/cobalt/intr.c
+++ b/kernel/cobalt/intr.c
@@ -908,7 +908,7 @@ int xnintr_query_next(int irq, struct xnintr_iterator 
*iterator,
                return -ENODEV;
        }
 
-       snprintf(name_buf, XNOBJECT_NAME_LEN, "IRQ%d: %s", irq, intr->name);
+       ksformat(name_buf, XNOBJECT_NAME_LEN, "IRQ%d: %s", irq, intr->name);
 
        statp = per_cpu_ptr(intr->stats, cpu);
        iterator->hits = xnstat_counter_get(&statp->hits);
diff --git a/kernel/cobalt/posix/sem.c b/kernel/cobalt/posix/sem.c
index 2e3e1f4..9bca743 100644
--- a/kernel/cobalt/posix/sem.c
+++ b/kernel/cobalt/posix/sem.c
@@ -101,7 +101,7 @@ cobalt_sem_init_inner(const char *name, struct 
cobalt_sem_shadow *sm,
        if (sem == NULL)
                return ERR_PTR(-ENOSPC);
 
-       snprintf(sem->name, sizeof(sem->name), "%s", name);
+       ksformat(sem->name, sizeof(sem->name), "%s", name);
 
        sys_ppd = xnsys_ppd_get(!!(flags & SEM_PSHARED));
        datp = xnheap_alloc(&sys_ppd->sem_heap, sizeof(*datp));
diff --git a/kernel/cobalt/posix/thread.c b/kernel/cobalt/posix/thread.c
index 2123be9..950e154 100644
--- a/kernel/cobalt/posix/thread.c
+++ b/kernel/cobalt/posix/thread.c
@@ -1049,7 +1049,7 @@ int cobalt_thread_set_name_np(unsigned long pth, const 
char __user *u_name)
                return -ESRCH;
        }
 
-       snprintf(xnthread_name(&thread->threadbase),
+       ksformat(xnthread_name(&thread->threadbase),
                 XNOBJECT_NAME_LEN - 1, "%s", name);
        p = xnthread_host_task(&thread->threadbase);
        get_task_struct(p);
diff --git a/kernel/cobalt/rtdm/proc.c b/kernel/cobalt/rtdm/proc.c
index ccbbf90..930e50e 100644
--- a/kernel/cobalt/rtdm/proc.c
+++ b/kernel/cobalt/rtdm/proc.c
@@ -182,7 +182,7 @@ static int proto_show(struct xnvfile_regular_iterator *it, 
void *data)
 
        device = list_entry(curr, struct rtdm_device, reserved.entry);
 
-       snprintf(pnum, sizeof(pnum), "%u:%u",
+       ksformat(pnum, sizeof(pnum), "%u:%u",
                 device->protocol_family, device->socket_type);
 
        xnvfile_printf(it, "%02X\t%-31s\t%-15s\t%s\n",
diff --git a/kernel/cobalt/sched-quota.c b/kernel/cobalt/sched-quota.c
index fd56003..5cddd67 100644
--- a/kernel/cobalt/sched-quota.c
+++ b/kernel/cobalt/sched-quota.c
@@ -229,8 +229,10 @@ static void xnsched_quota_init(struct xnsched *sched)
        INIT_LIST_HEAD(&qs->groups);
 
 #ifdef CONFIG_SMP
-       sprintf(refiller_name, "[quota-refill/%u]", sched->cpu);
-       sprintf(limiter_name, "[quota-limit/%u]", sched->cpu);
+       ksformat(refiller_name, sizeof(refiller_name),
+                "[quota-refill/%u]", sched->cpu);
+       ksformat(limiter_name, sizeof(limiter_name),
+                "[quota-limit/%u]", sched->cpu);
 #else
        strcpy(refiller_name, "[quota-refill]");
        strcpy(limiter_name, "[quota-limit]");
diff --git a/kernel/cobalt/sched-rt.c b/kernel/cobalt/sched-rt.c
index 9afa900..5e01063 100644
--- a/kernel/cobalt/sched-rt.c
+++ b/kernel/cobalt/sched-rt.c
@@ -194,7 +194,7 @@ static int vfile_sched_rt_show(struct 
xnvfile_snapshot_iterator *it,
                xnvfile_printf(it, "%-3s  %-6s %-8s %-10s %s\n",
                               "CPU", "PID", "PRI", "PERIOD", "NAME");
        else {
-               snprintf(pribuf, sizeof(pribuf), "%3d", p->cprio);
+               ksformat(pribuf, sizeof(pribuf), "%3d", p->cprio);
                xntimer_format_time(p->period, ptbuf, sizeof(ptbuf));
                xnvfile_printf(it, "%3u  %-6d %-8s %-10s %s\n",
                               p->cpu,
diff --git a/kernel/cobalt/sched-sporadic.c b/kernel/cobalt/sched-sporadic.c
index a523391..cae950e 100644
--- a/kernel/cobalt/sched-sporadic.c
+++ b/kernel/cobalt/sched-sporadic.c
@@ -471,10 +471,10 @@ static int vfile_sched_sporadic_show(struct 
xnvfile_snapshot_iterator *it,
                               "CPU", "PID", "LPRI", "NPRI", "BUDGET",
                               "PERIOD", "NAME");
        else {
-               snprintf(lpbuf, sizeof(lpbuf), "%3d%c",
+               ksformat(lpbuf, sizeof(lpbuf), "%3d%c",
                         p->low_prio, p->current_prio == p->low_prio ? '*' : ' 
');
 
-               snprintf(npbuf, sizeof(npbuf), "%3d%c",
+               ksformat(npbuf, sizeof(npbuf), "%3d%c",
                         p->normal_prio, p->current_prio == p->normal_prio ? 
'*' : ' ');
 
                xntimer_format_time(p->period, ptbuf, sizeof(ptbuf));
diff --git a/kernel/cobalt/sched-tp.c b/kernel/cobalt/sched-tp.c
index 676b96a..794f4c9 100644
--- a/kernel/cobalt/sched-tp.c
+++ b/kernel/cobalt/sched-tp.c
@@ -100,7 +100,7 @@ static void xnsched_tp_init(struct xnsched *sched)
        xnsched_initq(&tp->idle.runnable);
 
 #ifdef CONFIG_SMP
-       sprintf(timer_name, "[tp-tick/%u]", sched->cpu);
+       ksformat(timer_name, sizeof(timer_name), "[tp-tick/%u]", sched->cpu);
 #else
        strcpy(timer_name, "[tp-tick]");
 #endif
diff --git a/kernel/cobalt/sched-weak.c b/kernel/cobalt/sched-weak.c
index fc4c0b8..687789f 100644
--- a/kernel/cobalt/sched-weak.c
+++ b/kernel/cobalt/sched-weak.c
@@ -140,7 +140,7 @@ static int vfile_sched_weak_show(struct 
xnvfile_snapshot_iterator *it,
                xnvfile_printf(it, "%-3s  %-6s %-4s %s\n",
                               "CPU", "PID", "PRI", "NAME");
        else {
-               snprintf(pribuf, sizeof(pribuf), "%3d", p->cprio);
+               ksformat(pribuf, sizeof(pribuf), "%3d", p->cprio);
                xnvfile_printf(it, "%3u  %-6d %-4s %s\n",
                               p->cpu,
                               p->pid,
diff --git a/kernel/cobalt/sched.c b/kernel/cobalt/sched.c
index f2aef48..7f05052 100644
--- a/kernel/cobalt/sched.c
+++ b/kernel/cobalt/sched.c
@@ -153,9 +153,9 @@ void xnsched_init(struct xnsched *sched, int cpu)
 
 #ifdef CONFIG_SMP
        sched->cpu = cpu;
-       sprintf(htimer_name, "[host-timer/%u]", cpu);
-       sprintf(rrbtimer_name, "[rrb-timer/%u]", cpu);
-       sprintf(root_name, "ROOT/%u", cpu);
+       ksformat(htimer_name, sizeof(htimer_name), "[host-timer/%u]", cpu);
+       ksformat(rrbtimer_name, sizeof(rrbtimer_name), "[rrb-timer/%u]", cpu);
+       ksformat(root_name, sizeof(root_name), "ROOT/%u", cpu);
        cpus_clear(sched->resched);
 #else
        strcpy(htimer_name, "[host-timer]");
@@ -946,7 +946,7 @@ static int vfile_schedlist_show(struct 
xnvfile_snapshot_iterator *it,
                               "CPU", "PID", "CLASS", "PRI", "TIMEOUT",
                               "STAT", "NAME");
        else {
-               snprintf(pbuf, sizeof(pbuf), "%3d", p->cprio);
+               ksformat(pbuf, sizeof(pbuf), "%3d", p->cprio);
                xntimer_format_time(p->timeout, tbuf, sizeof(tbuf));
                xnthread_format_status(p->state, sbuf, sizeof(sbuf));
 
diff --git a/kernel/cobalt/shadow.c b/kernel/cobalt/shadow.c
index eacf68b..7108645 100644
--- a/kernel/cobalt/shadow.c
+++ b/kernel/cobalt/shadow.c
@@ -1159,7 +1159,7 @@ static void stringify_feature_set(unsigned long fset, 
char *buf, int size)
 
        for (feature = 1, nc = nfeat = 0; fset != 0 && size > 0; feature <<= 1) 
{
                if (fset & feature) {
-                       nc = snprintf(buf, size, "%s%s",
+                       nc = ksformat(buf, size, "%s%s",
                                      nfeat > 0 ? " " : "",
                                      get_feature_label(feature));
                        nfeat++;
diff --git a/kernel/cobalt/thread.c b/kernel/cobalt/thread.c
index fa5f0b4..e97ea9c 100644
--- a/kernel/cobalt/thread.c
+++ b/kernel/cobalt/thread.c
@@ -158,11 +158,11 @@ int __xnthread_init(struct xnthread *thread,
        }
 
        if (attr->name)
-               snprintf(thread->name,
+               ksformat(thread->name,
                         sizeof(thread->name), flags & XNUSER ?
                         "%s" : "[%s]", attr->name);
        else
-               snprintf(thread->name,
+               ksformat(thread->name,
                         sizeof(thread->name), "[%p]", thread);
 
        thread->personality = attr->personality;
diff --git a/kernel/cobalt/timer.c b/kernel/cobalt/timer.c
index f51d13f..5a46c36 100644
--- a/kernel/cobalt/timer.c
+++ b/kernel/cobalt/timer.c
@@ -349,7 +349,7 @@ void __xntimer_init(struct xntimer *timer,
        timer->tracker = clock;
 #endif
        if (!xnsched_current_thread() || !xnsched_root_p())
-               snprintf(timer->name, XNOBJECT_NAME_LEN, "%d/%s",
+               ksformat(timer->name, XNOBJECT_NAME_LEN, "%d/%s",
                         current->pid, current->comm);
        else
                xnobject_copy_name(timer->name,
@@ -525,17 +525,17 @@ char *xntimer_format_time(xnticks_t ns, char *buf, size_t 
bufsz)
        us %= 1000;
 
        if (sec) {
-               p += snprintf(p, bufsz, "%Lus", sec);
+               p += ksformat(p, bufsz, "%Lus", sec);
                len = bufsz - (p - buf);
        }
 
        if (len > 0 && (ms || (sec && us))) {
-               p += snprintf(p, bufsz - (p - buf), "%lums", ms);
+               p += ksformat(p, bufsz - (p - buf), "%lums", ms);
                len = bufsz - (p - buf);
        }
 
        if (len > 0 && us)
-               p += snprintf(p, bufsz - (p - buf), "%luus", us);
+               p += ksformat(p, bufsz - (p - buf), "%luus", us);
 
        return buf;
 }
diff --git a/kernel/drivers/analogy/device.c b/kernel/drivers/analogy/device.c
index 60b2977..724a931 100644
--- a/kernel/drivers/analogy/device.c
+++ b/kernel/drivers/analogy/device.c
@@ -113,18 +113,18 @@ int a4l_proc_attach(a4l_cxt_t * cxt)
        int ret = 0;
        a4l_dev_t *dev = a4l_get_dev(cxt);
        struct proc_dir_entry *entry;
-       char *entry_name, *p;
+       char *entry_name;
 
        /* Allocate the buffer for the file name */
        entry_name = rtdm_malloc(A4L_NAMELEN + 4);
-       if ((p = entry_name) == NULL) {
+       if (entry_name == NULL) {
                __a4l_err("a4l_proc_attach: failed to allocate buffer\n");
                return -ENOMEM;
        }
 
        /* Create the proc file name */
-       p += sprintf(p, "%02d-", a4l_get_minor(cxt));
-       strncpy(p, dev->driver->board_name, A4L_NAMELEN);
+       ksformat(entry_name, A4L_NAMELEN + 4, "%02d-%s",
+                a4l_get_minor(cxt), dev->driver->board_name);
 
        /* Create the proc entry */
        entry = proc_create_data(entry_name, 0444, a4l_proc_root,
@@ -134,11 +134,8 @@ int a4l_proc_attach(a4l_cxt_t * cxt)
                          "failed to create /proc/analogy/%s\n",
                          entry_name);
                ret = -ENOMEM;
-               goto out_setup_proc_transfer;
        }
 
-      out_setup_proc_transfer:
-       /* Free the file name buffer */
        rtdm_free(entry_name);
 
        return ret;
@@ -146,25 +143,21 @@ int a4l_proc_attach(a4l_cxt_t * cxt)
 
 void a4l_proc_detach(a4l_cxt_t * cxt)
 {
-       char *entry_name, *p;
        a4l_dev_t *dev = a4l_get_dev(cxt);
+       char *entry_name;
 
-       /* Allocate the buffer for the file name */
        entry_name = rtdm_malloc(A4L_NAMELEN + 4);
-       if ((p = entry_name) == NULL) {
+       if (entry_name == NULL) {
                __a4l_err("a4l_proc_detach: "
                          "failed to allocate filename buffer\n");
                return;
        }
 
-       /* Build the name */
-       p += sprintf(p, "%02d-", a4l_get_minor(cxt));
-       strncpy(p, dev->driver->board_name, A4L_NAMELEN);
+       ksformat(entry_name, A4L_NAMELEN + 4, "%02d-%s",
+                a4l_get_minor(cxt), dev->driver->board_name);
 
-       /* Remove the proc file */
        remove_proc_entry(entry_name, a4l_proc_root);
 
-       /* Free the temporary buffer */
        rtdm_free(entry_name);
 }
 
diff --git a/kernel/drivers/analogy/rtdm_interface.c 
b/kernel/drivers/analogy/rtdm_interface.c
index f74d7a2..b553dfc 100644
--- a/kernel/drivers/analogy/rtdm_interface.c
+++ b/kernel/drivers/analogy/rtdm_interface.c
@@ -276,7 +276,7 @@ int a4l_register(void)
 
                /* Sets the device name through which
                   user process can access the Analogy layer */
-               snprintf(rtdm_devs[i].device_name,
+               ksformat(rtdm_devs[i].device_name,
                         RTDM_MAX_DEVNAME_LEN, "analogy%d", i);
                rtdm_devs[i].proc_name = rtdm_devs[i].device_name;
 
diff --git a/kernel/drivers/can/rtcan_dev.c b/kernel/drivers/can/rtcan_dev.c
index c3e9e5e..3280587 100644
--- a/kernel/drivers/can/rtcan_dev.c
+++ b/kernel/drivers/can/rtcan_dev.c
@@ -140,7 +140,7 @@ void rtcan_dev_alloc_name(struct rtcan_device *dev, const 
char *mask)
 
 
     for (i = 0; i < RTCAN_MAX_DEVICES; i++) {
-       snprintf(buf, IFNAMSIZ, mask, i);
+       ksformat(buf, IFNAMSIZ, mask, i);
        if ((tmp = rtcan_dev_get_by_name(buf)) == NULL) {
            strncpy(dev->name, buf, IFNAMSIZ);
            break;
diff --git a/kernel/drivers/can/rtcan_module.c 
b/kernel/drivers/can/rtcan_module.c
index 18abc3e..4e5b837 100644
--- a/kernel/drivers/can/rtcan_module.c
+++ b/kernel/drivers/can/rtcan_module.c
@@ -80,7 +80,7 @@ static void rtcan_dev_get_baudrate_name(can_baudrate_t 
baudrate,
        strncpy(name, "unknown", max_len);
        break;
     default:
-       snprintf(name, max_len, "%d", baudrate);
+       ksformat(name, max_len, "%d", baudrate);
        break;
     }
 }
@@ -90,7 +90,7 @@ static void rtcan_dev_get_bittime_name(struct can_bittime 
*bit_time,
 {
     switch (bit_time->type) {
     case CAN_BITTIME_STD:
-       snprintf(name, max_len,
+       ksformat(name, max_len,
                 "brp=%d prop_seg=%d phase_seg1=%d "
                 "phase_seg2=%d sjw=%d sam=%d",
                 bit_time->std.brp,
@@ -101,7 +101,7 @@ static void rtcan_dev_get_bittime_name(struct can_bittime 
*bit_time,
                 bit_time->std.sam);
        break;
     case CAN_BITTIME_BTR:
-       snprintf(name, max_len, "btr0=0x%02x btr1=0x%02x",
+       ksformat(name, max_len, "btr0=0x%02x btr1=0x%02x",
                 bit_time->btr.btr0, bit_time->btr.btr1);
        break;
     default:
@@ -116,7 +116,7 @@ static void rtcan_get_timeout_name(nanosecs_rel_t timeout,
     if (timeout == RTDM_TIMEOUT_INFINITE)
        strncpy(name, "infinite", max_len);
     else
-       snprintf(name, max_len, "%lld", (long long)timeout);
+       ksformat(name, max_len, "%lld", (long long)timeout);
 }
 
 static int rtcan_read_proc_devices(struct seq_file *p, void *data)
@@ -198,7 +198,7 @@ static int rtcan_read_proc_sockets(struct seq_file *p, void 
*data)
                    rtcan_dev_dereference(dev);
                }
            } else
-               sprintf(name, "%d", ifindex);
+               ksformat(name, sizeof(name), "%d", ifindex);
        }
        rtcan_get_timeout_name(sock->tx_timeout,
                               tx_timeout, sizeof(tx_timeout));
diff --git a/kernel/drivers/ipc/bufp.c b/kernel/drivers/ipc/bufp.c
index b54ecb8..7204fdf 100644
--- a/kernel/drivers/ipc/bufp.c
+++ b/kernel/drivers/ipc/bufp.c
@@ -86,7 +86,7 @@ static char *__bufp_link_target(void *obj)
        if (buf == NULL)
                return buf;
 
-       snprintf(buf, 32, "%d", sk->name.sipc_port);
+       ksformat(buf, 32, "%d", sk->name.sipc_port);
 
        return buf;
 }
diff --git a/kernel/drivers/ipc/iddp.c b/kernel/drivers/ipc/iddp.c
index cd2d7c8..1f0e44e 100644
--- a/kernel/drivers/ipc/iddp.c
+++ b/kernel/drivers/ipc/iddp.c
@@ -91,7 +91,7 @@ static char *__iddp_link_target(void *obj)
        if (buf == NULL)
                return buf;
 
-       snprintf(buf, 32, "%d", sk->name.sipc_port);
+       ksformat(buf, 32, "%d", sk->name.sipc_port);
 
        return buf;
 }
diff --git a/kernel/drivers/ipc/xddp.c b/kernel/drivers/ipc/xddp.c
index 728a6ed..54f1e35 100644
--- a/kernel/drivers/ipc/xddp.c
+++ b/kernel/drivers/ipc/xddp.c
@@ -84,7 +84,7 @@ static char *__xddp_link_target(void *obj)
        if (buf == NULL)
                return buf;
 
-       snprintf(buf, 32, "/dev/rtp%d", sk->minor);
+       ksformat(buf, 32, "/dev/rtp%d", sk->minor);
 
        return buf;
 }
diff --git a/kernel/drivers/serial/16550A.c b/kernel/drivers/serial/16550A.c
index ca92c4d..8ee1c21 100644
--- a/kernel/drivers/serial/16550A.c
+++ b/kernel/drivers/serial/16550A.c
@@ -1137,7 +1137,7 @@ int __init rt_16550_init(void)
                        goto cleanup_out;
 
                memcpy(dev, &device_tmpl, sizeof(struct rtdm_device));
-               snprintf(dev->device_name, RTDM_MAX_DEVNAME_LEN, "rtser%d",
+               ksformat(dev->device_name, RTDM_MAX_DEVNAME_LEN, "rtser%d",
                         start_index + i);
                dev->device_id = i;
 
diff --git a/kernel/drivers/serial/mpc52xx_uart.c 
b/kernel/drivers/serial/mpc52xx_uart.c
index 10cd3b4..9d2bdfe 100644
--- a/kernel/drivers/serial/mpc52xx_uart.c
+++ b/kernel/drivers/serial/mpc52xx_uart.c
@@ -1342,7 +1342,7 @@ static int rt_mpc52xx_uart_of_probe(struct 
platform_device *op)
        }
 
        memcpy(dev, &device_tmpl, sizeof(struct rtdm_device));
-       snprintf(dev->device_name, RTDM_MAX_DEVNAME_LEN, "rtserPSC%d",
+       ksformat(dev->device_name, RTDM_MAX_DEVNAME_LEN, "rtserPSC%d",
                 idx);
        dev->device_id = idx;
        dev->proc_name = dev->device_name;
diff --git a/kernel/drivers/serial/rt_imx_uart.c 
b/kernel/drivers/serial/rt_imx_uart.c
index 3831225..d4e453a 100644
--- a/kernel/drivers/serial/rt_imx_uart.c
+++ b/kernel/drivers/serial/rt_imx_uart.c
@@ -1435,7 +1435,7 @@ static int rt_imx_uart_probe(struct platform_device *pdev)
 
        dev = &port->rtdm_dev;
        memcpy(dev, &device_tmpl, sizeof(struct rtdm_device));
-       snprintf(dev->device_name, RTDM_MAX_DEVNAME_LEN, "rtser%d",
+       ksformat(dev->device_name, RTDM_MAX_DEVNAME_LEN, "rtser%d",
                 start_index + pdev->id);
        dev->device_id = pdev->id;
        dev->device_data = port;
diff --git a/kernel/drivers/testing/rtdmtest.c 
b/kernel/drivers/testing/rtdmtest.c
index c107d07..900a2dc 100644
--- a/kernel/drivers/testing/rtdmtest.c
+++ b/kernel/drivers/testing/rtdmtest.c
@@ -161,7 +161,7 @@ static int __init __rtdm_test_init(void)
        while (1) {
                device[dev].proc_name = device[dev].device_name;
 
-               snprintf(device[dev].device_name, RTDM_MAX_DEVNAME_LEN,
+               ksformat(device[dev].device_name, RTDM_MAX_DEVNAME_LEN,
                         "rttest-rtdm%d",
                         start_index);
                err = rtdm_dev_register(&device[dev]);
diff --git a/kernel/drivers/testing/switchtest.c 
b/kernel/drivers/testing/switchtest.c
index 0090c5f..067457c 100644
--- a/kernel/drivers/testing/switchtest.c
+++ b/kernel/drivers/testing/switchtest.c
@@ -465,7 +465,7 @@ static int rtswitch_create_ktask(rtswitch_context_t *ctx,
        if (err)
                return err;
 
-       snprintf(name, sizeof(name), "rtk%d/%u", ptask->index, ctx->cpu);
+       ksformat(name, sizeof(name), "rtk%d/%u", ptask->index, ctx->cpu);
 
        task = &ctx->tasks[ptask->index];
 
@@ -764,7 +764,7 @@ int __init __switchtest_init(void)
        fp_features = fp_detect();
 
        do {
-               snprintf(device.device_name, RTDM_MAX_DEVNAME_LEN,
+               ksformat(device.device_name, RTDM_MAX_DEVNAME_LEN,
                         "rttest-switchtest%d",
                         start_index);
                err = rtdm_dev_register(&device);
diff --git a/kernel/drivers/testing/timerbench.c 
b/kernel/drivers/testing/timerbench.c
index efb5ca2..7d056d4 100644
--- a/kernel/drivers/testing/timerbench.c
+++ b/kernel/drivers/testing/timerbench.c
@@ -510,7 +510,7 @@ static int __init __timerbench_init(void)
                return 0;
 
        do {
-               snprintf(device.device_name, RTDM_MAX_DEVNAME_LEN,
+               ksformat(device.device_name, RTDM_MAX_DEVNAME_LEN,
                         "rttest-timerbench%d",
                         start_index);
                err = rtdm_dev_register(&device);


_______________________________________________
Xenomai-git mailing list
Xenomai-git@xenomai.org
http://www.xenomai.org/mailman/listinfo/xenomai-git

Reply via email to