hc
2024-02-20 102a0743326a03cd1a1202ceda21e175b7d3575c
kernel/drivers/gpio/gpiolib-sysfs.c
....@@ -1,8 +1,8 @@
1
+// SPDX-License-Identifier: GPL-2.0
12 #include <linux/idr.h>
23 #include <linux/mutex.h>
34 #include <linux/device.h>
45 #include <linux/sysfs.h>
5
-#include <linux/gpio.h>
66 #include <linux/gpio/consumer.h>
77 #include <linux/gpio/driver.h>
88 #include <linux/interrupt.h>
....@@ -11,6 +11,7 @@
1111 #include <linux/ctype.h>
1212
1313 #include "gpiolib.h"
14
+#include "gpiolib-sysfs.h"
1415
1516 #define GPIO_IRQF_TRIGGER_FALLING BIT(0)
1617 #define GPIO_IRQF_TRIGGER_RISING BIT(1)
....@@ -365,7 +366,7 @@
365366 static umode_t gpio_is_visible(struct kobject *kobj, struct attribute *attr,
366367 int n)
367368 {
368
- struct device *dev = container_of(kobj, struct device, kobj);
369
+ struct device *dev = kobj_to_dev(kobj);
369370 struct gpiod_data *data = dev_get_drvdata(dev);
370371 struct gpio_desc *desc = data->desc;
371372 umode_t mode = attr->mode;
....@@ -444,11 +445,6 @@
444445 };
445446 ATTRIBUTE_GROUPS(gpiochip);
446447
447
-static struct gpio_desc *gpio_to_valid_desc(int gpio)
448
-{
449
- return gpio_is_valid(gpio) ? gpio_to_desc(gpio) : NULL;
450
-}
451
-
452448 /*
453449 * /sys/class/gpio/export ... write-only
454450 * integer N ... number of GPIO to export (full access)
....@@ -469,7 +465,7 @@
469465 if (status < 0)
470466 goto done;
471467
472
- desc = gpio_to_valid_desc(gpio);
468
+ desc = gpio_to_desc(gpio);
473469 /* reject invalid GPIOs */
474470 if (!desc) {
475471 pr_warn("%s: invalid GPIO %ld\n", __func__, gpio);
....@@ -522,7 +518,7 @@
522518 if (status < 0)
523519 goto done;
524520
525
- desc = gpio_to_valid_desc(gpio);
521
+ desc = gpio_to_desc(gpio);
526522 /* reject bogus commands (gpio_unexport ignores them) */
527523 if (!desc) {
528524 pr_warn("%s: invalid GPIO %ld\n", __func__, gpio);
....@@ -775,10 +771,9 @@
775771 parent = &gdev->dev;
776772
777773 /* use chip->base for the ID; it's already known to be unique */
778
- dev = device_create_with_groups(&gpio_class, parent,
779
- MKDEV(0, 0),
780
- chip, gpiochip_groups,
781
- "gpiochip%d", chip->base);
774
+ dev = device_create_with_groups(&gpio_class, parent, MKDEV(0, 0), chip,
775
+ gpiochip_groups, GPIOCHIP_NAME "%d",
776
+ chip->base);
782777 if (IS_ERR(dev))
783778 return PTR_ERR(dev);
784779