The function comedi_find_range() tries to locate the optimal (smallest) range for the channel chan belonging to a subdevice of the comedi device device, that includes both min and max in units. If a matching range is found, the index of the matching range is returned. If no matching range is available, the function returns -1.