Hi,

I was attempting to run the firmware upload selftests in the linux
kernel source on a Fedora 43 system, and I discovered that the tests
were failing when comparing expected firmware data against the data
reported by sysfs.

Further, I discovered that the tests are only failed when using
"cmp -s" or when redirecting the output to /dev/null.

Using GDB, I found that it is failing in the code block that I have
pasted below. The comments indicate that special handling is required
for /proc files because they don't return that actual file size.
Similar handling may be required for sysfs files, which typically
returns 4096 for the page size:

$ ls -l /sys/devices/virtual/misc/test_firmware/upload_read
-r--r--r-- 1 root root 4096 Apr  8 13:45 
/sys/devices/virtual/misc/test_firmware/upload_read

The version of cmp is 3.12 (with a couple of fedora patches added)

Thanks,
- Russ Weight

342   /* If no output is needed,
343      and both input descriptors are associated with plain files,
344      and the file sizes are nonzero so they are not Linux /proc files,
345      conclude that the files differ if they have different sizes
346      and if more bytes will be compared than are in the smaller file.  */
347
348   if (type_no_stdout <= comparison_type
349       && 0 <= stat_buf[0].st_size && S_ISREG (stat_buf[0].st_mode)
350       && 0 <= stat_buf[1].st_size && S_ISREG (stat_buf[1].st_mode))
351     {
352       off_t pos0 = file_position (0);
353       if (0 <= pos0)
354         {
355           off_t pos1 = file_position (1);
356           if (0 <= pos1)
357             {
358               off_t s0 = stat_buf[0].st_size - pos0;
359               off_t s1 = stat_buf[1].st_size - pos1;
360               if (s0 < 0)
361                 s0 = 0;
362               if (s1 < 0)
363                 s1 = 0;
364               if (s0 != s1 && MIN (s0, s1) < bytes)
365                 exit (EXIT_FAILURE);
366             }
367         }
368     }



Reply via email to