Module: xenomai-head
Branch: master
Commit: 4cc1e7727d2144098e2f512be71dfe7199d0f7cd
URL:    
http://git.xenomai.org/?p=xenomai-head.git;a=commit;h=4cc1e7727d2144098e2f512be71dfe7199d0f7cd

Author: Philippe Gerum <r...@xenomai.org>
Date:   Fri Sep 24 09:43:48 2010 +0200

vfile: sanitize next method handling

---

 include/nucleus/vfile.h |    6 ------
 ksrc/nucleus/vfile.c    |   24 ++++++++++++++----------
 2 files changed, 14 insertions(+), 16 deletions(-)

diff --git a/include/nucleus/vfile.h b/include/nucleus/vfile.h
index 601b4f5..3f42016 100644
--- a/include/nucleus/vfile.h
+++ b/include/nucleus/vfile.h
@@ -157,10 +157,6 @@ struct xnvfile_regular_ops {
         * - NULL in case no record is available, in which case the
         * read operation will terminate immediately with no output.
         *
-        * - VFILE_SEQ_START, a special value indicating that @ref
-        * regular_show "the show() handler" should receive a NULL
-        * data pointer first, in order to output a header.
-        *
         * - ERR_PTR(errno), where errno is a negative error code;
         * upon error, the current operation will be aborted
         * immediately.
@@ -261,8 +257,6 @@ struct xnvfile_regular_template {
 struct xnvfile_regular_iterator {
        /** Current record position while iterating. */
        loff_t pos;
-       /** Highest record position found. */
-       loff_t maxpos;
        /** Backlink to the host sequential file supporting the vfile. */
        struct seq_file *seq;
        /** Backlink to the vfile being read. */
diff --git a/ksrc/nucleus/vfile.c b/ksrc/nucleus/vfile.c
index 3e14633..b7a0774 100644
--- a/ksrc/nucleus/vfile.c
+++ b/ksrc/nucleus/vfile.c
@@ -107,12 +107,14 @@ static void *vfile_snapshot_start(struct seq_file *seq, 
loff_t *offp)
 static void *vfile_snapshot_next(struct seq_file *seq, void *v, loff_t *offp)
 {
        struct xnvfile_snapshot_iterator *it = seq->private;
-       loff_t pos = ++*offp;
+       loff_t pos = *offp;
 
-       if (pos > it->nrdata)
+       if (pos >= it->nrdata)
                return NULL;
 
-       return it->databuf + (pos - 1) * it->vfile->datasz;
+       ++*offp;
+
+       return it->databuf + pos * it->vfile->datasz;
 }
 
 static void vfile_snapshot_stop(struct seq_file *seq, void *v)
@@ -419,9 +421,6 @@ static void *vfile_regular_start(struct seq_file *seq, 
loff_t *offp)
        struct xnvfile_regular *vfile = it->vfile;
        int ret;
 
-       if (it->pos >= it->maxpos)
-               return NULL;
-
        it->pos = *offp;
 
        if (vfile->entry.lockops) {
@@ -445,15 +444,20 @@ static void *vfile_regular_next(struct seq_file *seq, 
void *v, loff_t *offp)
 {
        struct xnvfile_regular_iterator *it = seq->private;
        struct xnvfile_regular *vfile = it->vfile;
-       loff_t pos = ++*offp;
+       void *data;
 
        if (vfile->ops->next == NULL)
                return NULL;
 
-       it->pos = pos;
-       it->maxpos = pos;
+       it->pos = *offp + 1;
+
+       data = vfile->ops->next(it);
+       if (data == NULL)
+               return NULL;
+
+       *offp = it->pos;
 
-       return vfile->ops->next(it);
+       return data;
 }
 
 static void vfile_regular_stop(struct seq_file *seq, void *v)


_______________________________________________
Xenomai-git mailing list
Xenomai-git@gna.org
https://mail.gna.org/listinfo/xenomai-git

Reply via email to