Skip to contentSkip to conversation

Modify sysfs gpio export so that "value" displays as 0 or 1

PATCH New David Brownell 1 participant 1 message Oct 16, 2008 GPIO

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Modify sysfs gpio export so that "value" displays as 0 or 1

---------- Forwarded Message ----------

Subject: [PATCH] Modify sysfs gpio export so that "value" displays as 0 or 1
Date: Friday 10 October 2008
From: "Steven A. Falco" <[email protected]>
To: "[email protected]" <[email protected]>, [email protected]

gpiolib can export GPIOs to userspace via sysfs. This patch modifies the gpio_value_show() so that any non-zero value is explicitly printed as "1", rather than whatever numerical value the lower-level driver returns.

---

drivers/gpio/gpiolib.c +1 -1
index 8d29405..36bf72b 100644
@@ -237,7 +237,7 @@ static ssize_t gpio_value_show(struct device *dev,
 	if (!test_bit(FLAG_EXPORT, &desc->flags))
 		status = -EIO;
 	else
-		status = sprintf(buf, "%d\n", gpio_get_value_cansleep(gpio));
+		status = sprintf(buf, "%d\n", !!gpio_get_value_cansleep(gpio));
 
 	mutex_unlock(&sysfs_lock);
 	return status;

-------------------------------------------------------