I see this would work by virtue of kfree(key) doing nothing
of key is NULL, the error case in question. And that otherwise key is
non-NULL if this path is hit.
However, the idiomatic approach to error handling is for the error path
to unwind resource allocations in the reverse order that they were made.
And for goto labels to control how far to unwind.
So I think the following would be more in keeping with the intention of the
code. Even if it is a somewhat more verbose change.
*compile tested only!*