pio: clean up memory and device management for i2c and spi transfers