Re: [libgpiod][PATCH 04/16] treewide: unify gpiod_line_config/request_get_offsets() functions

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 16-01-23, 22:39, Bartosz Golaszewski wrote:
> On Mon, Jan 16, 2023 at 6:52 AM Viresh Kumar <viresh.kumar@xxxxxxxxxx> wrote:
> > > +        let mut offsets = vec![0; num_lines as usize];
> > > +
> > > +        // SAFETY: gpiod_line_config is guaranteed to be valid here.
> > > +        unsafe { gpiod::gpiod_line_config_get_configured_offsets(self.config,
> > > +                                                                 offsets.as_mut_ptr(),
> > > +                                                                 num_lines) };
> >
> > Can the returned value be < num_lines here ?
> >
> 
> Ah, of course it can. Need to add a test case for that. How do I set
> the size of offsets to whatever this function returns?

Instead of any heavy operation, you can rather do something like this:

let num = unsafe { gpiod::gpiod_line_config_get_configured_offsets(self.config,
                                        offsets.as_mut_ptr(), num_lines) };
for offset in offsets[0..num] {
        ...
}

-- 
viresh



[Index of Archives]     [Linux SPI]     [Linux Kernel]     [Linux ARM (vger)]     [Linux ARM MSM]     [Linux Omap]     [Linux Arm]     [Linux Tegra]     [Fedora ARM]     [Linux for Samsung SOC]     [eCos]     [Linux Fastboot]     [Gcc Help]     [Git]     [DCCP]     [IETF Announce]     [Security]     [Linux MIPS]     [Yosemite Campsites]

  Powered by Linux