浏览代码

gpio: fix abi regression in sysfs

We started to assign the gpio_device as parent for the sysfs
but this changes the expected layout of sysfs. Restore the
previous behaviour.

Signed-off-by: Bamvor Jian Zhang <bamvor.zhangjian@linaro.org>
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
Bamvor Jian Zhang 9 年之前
父节点
当前提交
d27c17285e
共有 1 个文件被更改,包括 11 次插入1 次删除
  1. 11 1
      drivers/gpio/gpiolib-sysfs.c

+ 11 - 1
drivers/gpio/gpiolib-sysfs.c

@@ -721,6 +721,7 @@ EXPORT_SYMBOL_GPL(gpiod_unexport);
 int gpiochip_sysfs_register(struct gpio_device *gdev)
 int gpiochip_sysfs_register(struct gpio_device *gdev)
 {
 {
 	struct device	*dev;
 	struct device	*dev;
+	struct device	*parent;
 	struct gpio_chip *chip = gdev->chip;
 	struct gpio_chip *chip = gdev->chip;
 
 
 	/*
 	/*
@@ -732,8 +733,17 @@ int gpiochip_sysfs_register(struct gpio_device *gdev)
 	if (!gpio_class.p)
 	if (!gpio_class.p)
 		return 0;
 		return 0;
 
 
+	/*
+	 * For sysfs backward compatibility we need to preserve this
+	 * preferred parenting to the gpio_chip parent field, if set.
+	 */
+	if (chip->parent)
+		parent = chip->parent;
+	else
+		parent = &gdev->dev;
+
 	/* use chip->base for the ID; it's already known to be unique */
 	/* use chip->base for the ID; it's already known to be unique */
-	dev = device_create_with_groups(&gpio_class, &gdev->dev,
+	dev = device_create_with_groups(&gpio_class, parent,
 					MKDEV(0, 0),
 					MKDEV(0, 0),
 					chip, gpiochip_groups,
 					chip, gpiochip_groups,
 					"gpiochip%d", chip->base);
 					"gpiochip%d", chip->base);