diff options
author | Damien Zammit <damien@zamaudio.com> | 2021-03-09 00:04:54 +1100 |
---|---|---|
committer | Samuel Thibault <samuel.thibault@ens-lyon.org> | 2021-03-08 20:41:59 +0100 |
commit | a5fc9f2e767f034830ee5b179123b093180bf259 (patch) | |
tree | 7371c1857f7219ef58ddd9421083c1ed550d4aa3 /acpi | |
parent | 6cae63b470876cc3c5bf9fbe2ff5287d6b2f72ca (diff) | |
download | hurd-a5fc9f2e767f034830ee5b179123b093180bf259.tar.gz hurd-a5fc9f2e767f034830ee5b179123b093180bf259.tar.bz2 hurd-a5fc9f2e767f034830ee5b179123b093180bf259.zip |
acpi, pci-arbiter: Fix get_dirents
* acpi/netfs_impl.c (get_dirents): Fix computing number of
elements to be returned. Simplify computing the data size.
* pci-arbiter/netfs_impl.c (get_dirents): Likewise.
(netfs_get_dirents): Fix passing max_data_len rather than max_entries a
second time.
Diffstat (limited to 'acpi')
-rw-r--r-- | acpi/netfs_impl.c | 19 |
1 files changed, 8 insertions, 11 deletions
diff --git a/acpi/netfs_impl.c b/acpi/netfs_impl.c index 84f52c89..38ff5e17 100644 --- a/acpi/netfs_impl.c +++ b/acpi/netfs_impl.c @@ -58,25 +58,22 @@ get_dirents (struct acpifs_dirent *dir, int i, count; size_t size; char *p; + int nentries = (int)dir->dir->num_entries; - if (first_entry >= dir->dir->num_entries) + if (first_entry >= nentries) { *data_len = 0; *data_entries = 0; return 0; } - if (max_entries < 0) - count = dir->dir->num_entries; - else - { - count = ((first_entry + max_entries) >= dir->dir->num_entries ? - dir->dir->num_entries : max_entries) - first_entry; - } + count = nentries - first_entry; + if (max_entries >= 0 && count > max_entries) + count = max_entries; - size = - (count * DIRENTS_CHUNK_SIZE) > - max_data_len ? max_data_len : count * DIRENTS_CHUNK_SIZE; + size = count * DIRENTS_CHUNK_SIZE; + if (max_data_len && size > max_data_len) + size = max_data_len; *data = mmap (0, size, PROT_READ | PROT_WRITE, MAP_ANON, 0, 0); err = ((void *) *data == (void *) -1) ? errno : 0; |