Hi Matti,
It might be better but I am not pretty sure whether have to have both gains and times, so I modified 'ret' in places where issues might arise, rather than adding a restriction in iio_gts_sanity_check().
In the corner case, there is a restriction that both num_hwgain and num_itime cannot be 0 simultaneously in the iio_gts_sanity_check().
However, in the gain_to_scaletables() , if num_itime is 1 and num_hwgain is 0, the 'gain_bytes' becomes 0 and 'all_gains' is not null after the 'for' loop, which causes the subsequent 'while' or 'for' to become ineffective, leading to an undefined 'ret' being returned in the 'free_out'.