Source-Changes-D archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: CVS commit: src/sys/dev



On Sat, 24 Apr 2021, Robert Elz wrote:

   Date:        Sat, 24 Apr 2021 00:15:37 +0000
   From:        "Michael Lorenz" <macallan%netbsd.org@localhost>
   Message-ID:  <20210424001537.C5C83FA95%cvs.NetBSD.org@localhost>

 | add an ioctl() to get a list of fonts currently available via wsfont

It seems to me it would be useful for that ioctl to copyout()
the fi_numentries field of the struct (if addr != NULL) from
wsdisplayio_listfonts() just before the ENOMEM check (so it is
updated, even if ENOMEM is returned).   (Does it make any sense
for addr to be NULL, or should that be an error?  EINVAL or something.)

Otherwise, there doesn't seem to be any easy way for the user of
the ioctl to know how many fonts were returned (checking which elements
of the array were modified is not "easy") or how big the buffer would
need to be to fetch all of them in the ENOMEM case.

In several other places, we return "total space needed" separately,
regardless of how much data was actually copied.  The general paradigm
is (more or less)

	buff = NULL;
	size = 0;
	err = func(..., buff, size, &need);
	while (err == 0) {
		if (need > size) {
			free(buff);
			buff = malloc(need);
			if (buff == NULL)
				err = ENOMEM;

		}
	}

For a real-life example look at the modctl(2) code for MODULE_STAT



+--------------------+--------------------------+-----------------------+
| Paul Goyette       | PGP Key fingerprint:     | E-mail addresses:     |
| (Retired)          | FA29 0E3B 35AF E8AE 6651 | paul%whooppee.com@localhost     |
| Software Developer | 0786 F758 55DE 53BA 7731 | pgoyette%netbsd.org@localhost   |
+--------------------+--------------------------+-----------------------+


Home | Main Index | Thread Index | Old Index