Hi Denis,
On 05/06/2019 18.04, Denis Kenzior wrote:
> +LIB_EXPORT char **l_gpio_chips_with_line_label(const char
*line_label)
> +{
> + struct dirent *entry;
> + DIR *dp;
> + char **chips = NULL;
> +
> + dp = opendir("/sys/bus/gpio/devices");
> + if (dp == NULL)
> + return NULL;
> +
> + while ((entry = readdir(dp))) {
May want to skip directories. e.g. something like:
if (entry->d_type != DT_REG)
continue;
The files in /sys/bus/gpio/devices are links, so I've added a check for
DT_LNK.
<snip>
> +LIB_EXPORT char *l_gpio_chip_get_line_label(struct l_gpio_chip
*chip,
> + uint32_t offset)
Is there a particular reason to return char * here? Why not const char
* and have the caller l_strdup as needed?
The info object is allocated on the stack, so we cannot return the .name
member to the caller.
> +{
> + struct gpioline_info info;
> +
> + if (!chip)
> + return NULL;
> +
> + if (offset >= chip->n_lines)
> + return NULL;
> +
> + memset(&info, 0, sizeof(info));
> + info.line_offset = offset;
> +
> + if (ioctl(chip->fd, GPIO_GET_LINEINFO_IOCTL, &info) < 0)
> + return NULL;
> +
> + return l_strdup(info.name);
> +}
> +
> +LIB_EXPORT char *l_gpio_chip_get_line_consumer(struct l_gpio_chip *chip,
> + uint32_t offset)
Is there a particular reason to return char * here? Why not const char
* and have the caller l_strdup as needed?
Same here.
// Martin