From: Bartosz Golaszewski Date: Tue, 10 Jan 2017 15:16:15 +0000 (+0100) Subject: core: check for empty name & label of a gpiochip X-Git-Url: http://git.maquefel.me/?a=commitdiff_plain;h=474a97f84675849621cbfc1129ea5e2db487b50b;p=qemu-gpiodev%2Flibgpiod.git core: check for empty name & label of a gpiochip In case the kernel passes us an empty name or label field when reading the chip info: return NULL from gpiod_chip_name() & gpiod_chip_label() just like the line counterparts do. Signed-off-by: Bartosz Golaszewski --- diff --git a/core.c b/core.c index 4fe2fa2..ea24288 100644 --- a/core.c +++ b/core.c @@ -878,13 +878,12 @@ void gpiod_chip_close(struct gpiod_chip *chip) const char * gpiod_chip_name(struct gpiod_chip *chip) { - return chip->cinfo.name; + return chip->cinfo.name[0] == '\0' ? NULL : chip->cinfo.name; } const char * gpiod_chip_label(struct gpiod_chip *chip) { - /* REVISIT can a gpiochip not have a label? */ - return chip->cinfo.label; + return chip->cinfo.label[0] == '\0' ? NULL : chip->cinfo.label; } unsigned int gpiod_chip_num_lines(struct gpiod_chip *chip)