casaroli commented on code in PR #21354:
URL: https://github.com/apache/nuttx/pull/21354#discussion_r4467817014


##########
drivers/misc/dev_mem.c:
##########
@@ -96,21 +97,20 @@ static ssize_t devmem_read(FAR struct file *filep, FAR char 
*buffer,
                            size_t buflen)
 {
   FAR struct memory_region_s *region = filep->f_inode->i_private;
-  uintptr_t src = filep->f_pos;
   uintptr_t start;
   uintptr_t end;
   ssize_t len;
   int i;
 
   for (i = 0; region[i].start != 0 && region[i].end != 0; i++)
     {
-      start = MAX(src, region[i].start);
+      start = region[i].start + filep->f_pos;

Review Comment:
   Run on qemu-armv8a:nsh with CONFIG_DEV_MEM=y. On master, lseek() to an 
address in .text, .data or .bss then read() returns that memory, and a 
sequential read returns all three regions (374328 bytes). With this PR each of 
those read() calls returns -EINVAL and the sequential read stops after .text 
(303104 bytes), so .data and .bss cannot be read. mmap() still uses absolute 
addresses. Correction to my earlier comment: write(0) then read(0) giving 
different memory is also in master.
   
   Fix: keep `f_pos` as the absolute address, as in master and in mmap(), and 
only add the SEEK_END case if you need it.



##########
drivers/misc/dev_mem.c:
##########
@@ -66,6 +66,7 @@ static ssize_t devmem_read(FAR struct file *filep, FAR char 
*buffer,
                            size_t buflen);
 static ssize_t devmem_write(FAR struct file *filep, FAR const char *buffer,
                             size_t buflen);
+static off_t   devmem_seek(FAR struct file *filep, off_t offset, int whence);

Review Comment:
   With CONFIG_DEV_MEM=y this file does not compile on qemu-armv8a:nsh, on this 
head or on master: `struct file` is an incomplete type because <nuttx/fs/fs.h> 
is not included. So the `dd` test in the PR body does not build on this tree.
   
   Fix: add <nuttx/fs/fs.h>, <nuttx/mm/map.h>, <errno.h> and <string.h> here; 
with these it builds and runs.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to