devfs uses the device's usecount to determine how many times a device
has been opened. If it transitions 1->0, then we should invoke d_close
(assuming D_TRACKCLOSE isn't set).
But, we bump the usecount before calling d_open. Suppose a thread races
to open a device while a different thread is closing it. The first
thread may bump usecount 1->2, and then the closing thread decrements it
2->1. Then, if the open fails, we will decrement again 1->0 but d_close
is not invoked at all.
Fix the problem by incrementing usecount only after a succesful open. I
believe this does not introduce any new races: the usecount is only used
to decide whether to revoke or not, and the session holds an additional
ref via devfs_ctty_ref(). Note however that d_close(FLASTCLOSE) can
now race with d_open().