*
  * (C) 2000 Red Hat. GPL'd
  *
- * $Id: cfi_cmdset_0001.c,v 1.167 2005/02/08 17:11:15 nico Exp $
+ * $Id: cfi_cmdset_0001.c,v 1.168 2005/02/17 20:34:59 nico Exp $
  *
  * 
  * 10/10/2000  Nicolas Pitre <nico@cam.org>
        map_word datum;
 
        /* make sure area matches group boundaries */
-       if (offset != 0 || size != grpsz)
+       if (size != grpsz)
                return -EXDEV;
 
        datum = map_word_ff(map);
                                groupno = 0;
                        }
 
-                       while (groups > 0) {
+                       while (len > 0 && groups > 0) {
                                if (!action) {
                                        /*
                                         * Special case: if action is NULL
                                        *retlen += sizeof(*otpinfo);
                                } else if (from >= groupsize) {
                                        from -= groupsize;
+                                       data_offset += groupsize;
                                } else {
                                        int size = groupsize;
                                        data_offset += from;
                                        buf += size;
                                        len -= size;
                                        *retlen += size;
+                                       data_offset += size;
                                }
                                groupno++;
                                groups--;