libs/cbi: Moved typecasting to the appropriate place