While this looks functionally correct, I think the structure in here is weird. In libxfs we usually check that magic number first and then branch out into helper that deal with the leaf vs node format. That is we don't do the xfs_attr3_leaf_hdr_from_disk call for node format attrs, and also check the forward/backward pointers based on the actual ichdr. Maybe this code should follow that structure?