From 474a97f84675849621cbfc1129ea5e2db487b50b Mon Sep 17 00:00:00 2001 From: Bartosz Golaszewski Date: Tue, 10 Jan 2017 16:16:15 +0100 Subject: [PATCH] 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 --- core.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) 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) -- 2.30.2