What about getting the number of gpios from platform_data and/or device
tree?

Actually I am thinking about just setting it to 20 unconditionally.
Anything requesting a non-present GPIO pin is buggy to begin with.

Since it is exposed by the sysfs entry ngpio, you can consider it being
part of the ABI, and it can be used by an user to query the number of
gpios available, and will also serve as the maximum number of gpios for
gpiolib internally, it is certainly best to make it match what the
hardware can actually do.