|
@@ -20,6 +20,7 @@
|
|
|
#include <linux/cdev.h>
|
|
|
#include <linux/fs.h>
|
|
|
#include <linux/uaccess.h>
|
|
|
+#include <linux/compat.h>
|
|
|
#include <uapi/linux/gpio.h>
|
|
|
|
|
|
#include "gpiolib.h"
|
|
@@ -316,7 +317,7 @@ static long gpio_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
|
|
|
{
|
|
|
struct gpio_device *gdev = filp->private_data;
|
|
|
struct gpio_chip *chip = gdev->chip;
|
|
|
- int __user *ip = (int __user *)arg;
|
|
|
+ void __user *ip = (void __user *)arg;
|
|
|
|
|
|
/* We fail any subsequent ioctl():s when the chip is gone */
|
|
|
if (!chip)
|
|
@@ -388,6 +389,14 @@ static long gpio_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
|
|
|
return -EINVAL;
|
|
|
}
|
|
|
|
|
|
+#ifdef CONFIG_COMPAT
|
|
|
+static long gpio_ioctl_compat(struct file *filp, unsigned int cmd,
|
|
|
+ unsigned long arg)
|
|
|
+{
|
|
|
+ return gpio_ioctl(filp, cmd, (unsigned long)compat_ptr(arg));
|
|
|
+}
|
|
|
+#endif
|
|
|
+
|
|
|
/**
|
|
|
* gpio_chrdev_open() - open the chardev for ioctl operations
|
|
|
* @inode: inode for this chardev
|
|
@@ -431,7 +440,9 @@ static const struct file_operations gpio_fileops = {
|
|
|
.owner = THIS_MODULE,
|
|
|
.llseek = noop_llseek,
|
|
|
.unlocked_ioctl = gpio_ioctl,
|
|
|
- .compat_ioctl = gpio_ioctl,
|
|
|
+#ifdef CONFIG_COMPAT
|
|
|
+ .compat_ioctl = gpio_ioctl_compat,
|
|
|
+#endif
|
|
|
};
|
|
|
|
|
|
static void gpiodevice_release(struct device *dev)
|
|
@@ -618,6 +629,8 @@ int gpiochip_add_data(struct gpio_chip *chip, void *data)
|
|
|
goto err_free_label;
|
|
|
}
|
|
|
|
|
|
+ spin_unlock_irqrestore(&gpio_lock, flags);
|
|
|
+
|
|
|
for (i = 0; i < chip->ngpio; i++) {
|
|
|
struct gpio_desc *desc = &gdev->descs[i];
|
|
|
|
|
@@ -649,8 +662,6 @@ int gpiochip_add_data(struct gpio_chip *chip, void *data)
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- spin_unlock_irqrestore(&gpio_lock, flags);
|
|
|
-
|
|
|
#ifdef CONFIG_PINCTRL
|
|
|
INIT_LIST_HEAD(&gdev->pin_ranges);
|
|
|
#endif
|
|
@@ -1356,10 +1367,13 @@ done:
|
|
|
/*
|
|
|
* This descriptor validation needs to be inserted verbatim into each
|
|
|
* function taking a descriptor, so we need to use a preprocessor
|
|
|
- * macro to avoid endless duplication.
|
|
|
+ * macro to avoid endless duplication. If the desc is NULL it is an
|
|
|
+ * optional GPIO and calls should just bail out.
|
|
|
*/
|
|
|
#define VALIDATE_DESC(desc) do { \
|
|
|
- if (!desc || !desc->gdev) { \
|
|
|
+ if (!desc) \
|
|
|
+ return 0; \
|
|
|
+ if (!desc->gdev) { \
|
|
|
pr_warn("%s: invalid GPIO\n", __func__); \
|
|
|
return -EINVAL; \
|
|
|
} \
|
|
@@ -1370,7 +1384,9 @@ done:
|
|
|
} } while (0)
|
|
|
|
|
|
#define VALIDATE_DESC_VOID(desc) do { \
|
|
|
- if (!desc || !desc->gdev) { \
|
|
|
+ if (!desc) \
|
|
|
+ return; \
|
|
|
+ if (!desc->gdev) { \
|
|
|
pr_warn("%s: invalid GPIO\n", __func__); \
|
|
|
return; \
|
|
|
} \
|
|
@@ -2066,17 +2082,30 @@ EXPORT_SYMBOL_GPL(gpiod_to_irq);
|
|
|
*/
|
|
|
int gpiochip_lock_as_irq(struct gpio_chip *chip, unsigned int offset)
|
|
|
{
|
|
|
- if (offset >= chip->ngpio)
|
|
|
- return -EINVAL;
|
|
|
+ struct gpio_desc *desc;
|
|
|
+
|
|
|
+ desc = gpiochip_get_desc(chip, offset);
|
|
|
+ if (IS_ERR(desc))
|
|
|
+ return PTR_ERR(desc);
|
|
|
+
|
|
|
+ /* Flush direction if something changed behind our back */
|
|
|
+ if (chip->get_direction) {
|
|
|
+ int dir = chip->get_direction(chip, offset);
|
|
|
+
|
|
|
+ if (dir)
|
|
|
+ clear_bit(FLAG_IS_OUT, &desc->flags);
|
|
|
+ else
|
|
|
+ set_bit(FLAG_IS_OUT, &desc->flags);
|
|
|
+ }
|
|
|
|
|
|
- if (test_bit(FLAG_IS_OUT, &chip->gpiodev->descs[offset].flags)) {
|
|
|
+ if (test_bit(FLAG_IS_OUT, &desc->flags)) {
|
|
|
chip_err(chip,
|
|
|
"%s: tried to flag a GPIO set as output for IRQ\n",
|
|
|
__func__);
|
|
|
return -EIO;
|
|
|
}
|
|
|
|
|
|
- set_bit(FLAG_USED_AS_IRQ, &chip->gpiodev->descs[offset].flags);
|
|
|
+ set_bit(FLAG_USED_AS_IRQ, &desc->flags);
|
|
|
return 0;
|
|
|
}
|
|
|
EXPORT_SYMBOL_GPL(gpiochip_lock_as_irq);
|