core: check for empty name & label of a gpiochip
authorBartosz Golaszewski <bartekgola@gmail.com>
Tue, 10 Jan 2017 15:16:15 +0000 (16:16 +0100)
committerBartosz Golaszewski <bartekgola@gmail.com>
Tue, 10 Jan 2017 15:16:15 +0000 (16:16 +0100)
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 <bartekgola@gmail.com>
core.c

diff --git a/core.c b/core.c
index 4fe2fa2d23b4b2e7171c73fed7cdb7152d5b58db..ea24288e1a21e2be6e009748caf8c59dfd86a5ff 100644 (file)
--- 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)