diff mbox series

[RFT,v1,1/1] gpiolib: Get rid of not used of_node member

Message ID 20221004103027.47660-1-andriy.shevchenko@linux.intel.com
State New
Headers show
Series [RFT,v1,1/1] gpiolib: Get rid of not used of_node member | expand

Commit Message

Andy Shevchenko Oct. 4, 2022, 10:30 a.m. UTC
All new drivers should use fwnode and / or parent to provide the
necessary information to the GPIO library.

Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---

To test for now (using CIs and build bots) what is left uncoverted

Expected to fail in some configurations!

 drivers/gpio/gpiolib-acpi.c | 10 -------
 drivers/gpio/gpiolib-acpi.h |  4 ---
 drivers/gpio/gpiolib-of.c   | 59 +++++++++++++++----------------------
 drivers/gpio/gpiolib-of.h   |  5 ----
 drivers/gpio/gpiolib.c      | 15 +---------
 include/linux/gpio/driver.h |  7 -----
 6 files changed, 24 insertions(+), 76 deletions(-)

Comments

kernel test robot Oct. 4, 2022, 3:31 p.m. UTC | #1
Hi Andy,

I love your patch! Yet something to improve:

[auto build test ERROR on brgl/gpio/for-next]
[also build test ERROR on linus/master v6.0 next-20221004]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Andy-Shevchenko/gpiolib-Get-rid-of-not-used-of_node-member/20221004-183204
base:   https://git.kernel.org/pub/scm/linux/kernel/git/brgl/linux.git gpio/for-next
config: hexagon-randconfig-r024-20221003
compiler: clang version 16.0.0 (https://github.com/llvm/llvm-project 791a7ae1ba3efd6bca96338e10ffde557ba83920)
reproduce (this is a W=1 build):
        wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
        chmod +x ~/bin/make.cross
        # https://github.com/intel-lab-lkp/linux/commit/e0bc05e674d1be3d05351ec364768345f563b243
        git remote add linux-review https://github.com/intel-lab-lkp/linux
        git fetch --no-tags linux-review Andy-Shevchenko/gpiolib-Get-rid-of-not-used-of_node-member/20221004-183204
        git checkout e0bc05e674d1be3d05351ec364768345f563b243
        # save the config file
        mkdir build_dir && cp config build_dir/.config
        COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross W=1 O=build_dir ARCH=hexagon SHELL=/bin/bash drivers/pinctrl/actions/

If you fix the issue, kindly add following tag where applicable
| Reported-by: kernel test robot <lkp@intel.com>

All errors (new ones prefixed by >>):

>> drivers/pinctrl/actions/pinctrl-owl.c:878:31: error: no member named 'of_node' in 'struct gpio_chip'
           pctrl->irq_chip.name = chip->of_node->name;
                                  ~~~~  ^
   1 error generated.


vim +878 drivers/pinctrl/actions/pinctrl-owl.c

6c5d0736e9c09f Manivannan Sadhasivam 2018-06-23  864  
33257f860a13d8 Manivannan Sadhasivam 2018-05-20  865  static int owl_gpio_init(struct owl_pinctrl *pctrl)
33257f860a13d8 Manivannan Sadhasivam 2018-05-20  866  {
33257f860a13d8 Manivannan Sadhasivam 2018-05-20  867  	struct gpio_chip *chip;
6c5d0736e9c09f Manivannan Sadhasivam 2018-06-23  868  	struct gpio_irq_chip *gpio_irq;
6c5d0736e9c09f Manivannan Sadhasivam 2018-06-23  869  	int ret, i, j, offset;
33257f860a13d8 Manivannan Sadhasivam 2018-05-20  870  
33257f860a13d8 Manivannan Sadhasivam 2018-05-20  871  	chip = &pctrl->chip;
33257f860a13d8 Manivannan Sadhasivam 2018-05-20  872  	chip->base = -1;
33257f860a13d8 Manivannan Sadhasivam 2018-05-20  873  	chip->ngpio = pctrl->soc->ngpios;
33257f860a13d8 Manivannan Sadhasivam 2018-05-20  874  	chip->label = dev_name(pctrl->dev);
33257f860a13d8 Manivannan Sadhasivam 2018-05-20  875  	chip->parent = pctrl->dev;
33257f860a13d8 Manivannan Sadhasivam 2018-05-20  876  	chip->owner = THIS_MODULE;
33257f860a13d8 Manivannan Sadhasivam 2018-05-20  877  
6c5d0736e9c09f Manivannan Sadhasivam 2018-06-23 @878  	pctrl->irq_chip.name = chip->of_node->name;
6c5d0736e9c09f Manivannan Sadhasivam 2018-06-23  879  	pctrl->irq_chip.irq_ack = owl_gpio_irq_ack;
6c5d0736e9c09f Manivannan Sadhasivam 2018-06-23  880  	pctrl->irq_chip.irq_mask = owl_gpio_irq_mask;
6c5d0736e9c09f Manivannan Sadhasivam 2018-06-23  881  	pctrl->irq_chip.irq_unmask = owl_gpio_irq_unmask;
6c5d0736e9c09f Manivannan Sadhasivam 2018-06-23  882  	pctrl->irq_chip.irq_set_type = owl_gpio_irq_set_type;
6c5d0736e9c09f Manivannan Sadhasivam 2018-06-23  883  
6c5d0736e9c09f Manivannan Sadhasivam 2018-06-23  884  	gpio_irq = &chip->irq;
6c5d0736e9c09f Manivannan Sadhasivam 2018-06-23  885  	gpio_irq->chip = &pctrl->irq_chip;
6c5d0736e9c09f Manivannan Sadhasivam 2018-06-23  886  	gpio_irq->handler = handle_simple_irq;
6c5d0736e9c09f Manivannan Sadhasivam 2018-06-23  887  	gpio_irq->default_type = IRQ_TYPE_NONE;
6c5d0736e9c09f Manivannan Sadhasivam 2018-06-23  888  	gpio_irq->parent_handler = owl_gpio_irq_handler;
6c5d0736e9c09f Manivannan Sadhasivam 2018-06-23  889  	gpio_irq->parent_handler_data = pctrl;
6c5d0736e9c09f Manivannan Sadhasivam 2018-06-23  890  	gpio_irq->num_parents = pctrl->num_irq;
6c5d0736e9c09f Manivannan Sadhasivam 2018-06-23  891  	gpio_irq->parents = pctrl->irq;
6c5d0736e9c09f Manivannan Sadhasivam 2018-06-23  892  
6c5d0736e9c09f Manivannan Sadhasivam 2018-06-23  893  	gpio_irq->map = devm_kcalloc(pctrl->dev, chip->ngpio,
6c5d0736e9c09f Manivannan Sadhasivam 2018-06-23  894  				sizeof(*gpio_irq->map), GFP_KERNEL);
6c5d0736e9c09f Manivannan Sadhasivam 2018-06-23  895  	if (!gpio_irq->map)
6c5d0736e9c09f Manivannan Sadhasivam 2018-06-23  896  		return -ENOMEM;
6c5d0736e9c09f Manivannan Sadhasivam 2018-06-23  897  
6c5d0736e9c09f Manivannan Sadhasivam 2018-06-23  898  	for (i = 0, offset = 0; i < pctrl->soc->nports; i++) {
6c5d0736e9c09f Manivannan Sadhasivam 2018-06-23  899  		const struct owl_gpio_port *port = &pctrl->soc->ports[i];
6c5d0736e9c09f Manivannan Sadhasivam 2018-06-23  900  
6c5d0736e9c09f Manivannan Sadhasivam 2018-06-23  901  		for (j = 0; j < port->pins; j++)
6c5d0736e9c09f Manivannan Sadhasivam 2018-06-23  902  			gpio_irq->map[offset + j] = gpio_irq->parents[i];
6c5d0736e9c09f Manivannan Sadhasivam 2018-06-23  903  
6c5d0736e9c09f Manivannan Sadhasivam 2018-06-23  904  		offset += port->pins;
6c5d0736e9c09f Manivannan Sadhasivam 2018-06-23  905  	}
6c5d0736e9c09f Manivannan Sadhasivam 2018-06-23  906  
33257f860a13d8 Manivannan Sadhasivam 2018-05-20  907  	ret = gpiochip_add_data(&pctrl->chip, pctrl);
33257f860a13d8 Manivannan Sadhasivam 2018-05-20  908  	if (ret) {
33257f860a13d8 Manivannan Sadhasivam 2018-05-20  909  		dev_err(pctrl->dev, "failed to register gpiochip\n");
33257f860a13d8 Manivannan Sadhasivam 2018-05-20  910  		return ret;
33257f860a13d8 Manivannan Sadhasivam 2018-05-20  911  	}
33257f860a13d8 Manivannan Sadhasivam 2018-05-20  912  
33257f860a13d8 Manivannan Sadhasivam 2018-05-20  913  	return 0;
33257f860a13d8 Manivannan Sadhasivam 2018-05-20  914  }
33257f860a13d8 Manivannan Sadhasivam 2018-05-20  915
diff mbox series

Patch

diff --git a/drivers/gpio/gpiolib-acpi.c b/drivers/gpio/gpiolib-acpi.c
index 285ecbf107c9..4c56d97e073c 100644
--- a/drivers/gpio/gpiolib-acpi.c
+++ b/drivers/gpio/gpiolib-acpi.c
@@ -1354,16 +1354,6 @@  void acpi_gpiochip_remove(struct gpio_chip *chip)
 	kfree(acpi_gpio);
 }
 
-void acpi_gpio_dev_init(struct gpio_chip *gc, struct gpio_device *gdev)
-{
-	/* Set default fwnode to parent's one if present */
-	if (gc->parent)
-		ACPI_COMPANION_SET(&gdev->dev, ACPI_COMPANION(gc->parent));
-
-	if (gc->fwnode)
-		device_set_node(&gdev->dev, gc->fwnode);
-}
-
 static int acpi_gpio_package_count(const union acpi_object *obj)
 {
 	const union acpi_object *element = obj->package.elements;
diff --git a/drivers/gpio/gpiolib-acpi.h b/drivers/gpio/gpiolib-acpi.h
index e476558d9471..e2edb632b2cc 100644
--- a/drivers/gpio/gpiolib-acpi.h
+++ b/drivers/gpio/gpiolib-acpi.h
@@ -36,8 +36,6 @@  struct acpi_gpio_info {
 void acpi_gpiochip_add(struct gpio_chip *chip);
 void acpi_gpiochip_remove(struct gpio_chip *chip);
 
-void acpi_gpio_dev_init(struct gpio_chip *gc, struct gpio_device *gdev);
-
 void acpi_gpiochip_request_interrupts(struct gpio_chip *chip);
 void acpi_gpiochip_free_interrupts(struct gpio_chip *chip);
 
@@ -60,8 +58,6 @@  int acpi_gpio_count(struct device *dev, const char *con_id);
 static inline void acpi_gpiochip_add(struct gpio_chip *chip) { }
 static inline void acpi_gpiochip_remove(struct gpio_chip *chip) { }
 
-static inline void acpi_gpio_dev_init(struct gpio_chip *gc, struct gpio_device *gdev) { }
-
 static inline void
 acpi_gpiochip_request_interrupts(struct gpio_chip *chip) { }
 
diff --git a/drivers/gpio/gpiolib-of.c b/drivers/gpio/gpiolib-of.c
index 0e4e1291604d..123b24f1ea5d 100644
--- a/drivers/gpio/gpiolib-of.c
+++ b/drivers/gpio/gpiolib-of.c
@@ -85,7 +85,7 @@  static int of_gpiochip_match_node_and_xlate(struct gpio_chip *chip, void *data)
 {
 	struct of_phandle_args *gpiospec = data;
 
-	return chip->gpiodev->dev.of_node == gpiospec->np &&
+	return device_match_of_node(&chip->gpiodev->dev, gpiospec->np) &&
 				chip->of_xlate &&
 				chip->of_xlate(chip, gpiospec, NULL) >= 0;
 }
@@ -122,9 +122,8 @@  static struct gpio_desc *of_xlate_and_get_gpiod_flags(struct gpio_chip *chip,
 bool of_gpio_need_valid_mask(const struct gpio_chip *gc)
 {
 	int size;
-	const struct device_node *np = gc->of_node;
 
-	size = of_property_count_u32_elems(np,  "gpio-reserved-ranges");
+	size = fwnode_property_count_u32(gc->fwnode, "gpio-reserved-ranges");
 	if (size > 0 && size % 2 == 0)
 		return true;
 	return false;
@@ -565,7 +564,7 @@  static struct gpio_desc *of_parse_own_gpio(struct device_node *np,
 	u32 tmp;
 	int ret;
 
-	chip_np = chip->of_node;
+	chip_np = to_of_node(chip->fwnode);
 	if (!chip_np)
 		return ERR_PTR(-EINVAL);
 
@@ -654,16 +653,18 @@  static int of_gpiochip_add_hog(struct gpio_chip *chip, struct device_node *hog)
  */
 static int of_gpiochip_scan_gpios(struct gpio_chip *chip)
 {
-	struct device_node *np;
+	struct fwnode_handle *child;
 	int ret;
 
-	for_each_available_child_of_node(chip->of_node, np) {
-		if (!of_property_read_bool(np, "gpio-hog"))
+	fwnode_for_each_available_child_node(chip->fwnode, child) {
+		struct device_node *np = to_of_node(child);
+
+		if (!fwnode_property_read_bool(child, "gpio-hog"))
 			continue;
 
 		ret = of_gpiochip_add_hog(chip, np);
 		if (ret < 0) {
-			of_node_put(np);
+			fwnode_handle_put(child);
 			return ret;
 		}
 
@@ -815,14 +816,15 @@  int of_mm_gpiochip_add_data(struct device_node *np,
 			    struct of_mm_gpio_chip *mm_gc,
 			    void *data)
 {
+	struct fwnode_handle *fwnode = of_fwnode_handle(np);
 	int ret = -ENOMEM;
 	struct gpio_chip *gc = &mm_gc->gc;
 
-	gc->label = kasprintf(GFP_KERNEL, "%pOF", np);
+	gc->label = kasprintf(GFP_KERNEL, "%pfw", fwnode);
 	if (!gc->label)
 		goto err0;
 
-	mm_gc->regs = of_iomap(np, 0);
+	mm_gc->regs = fwnode_iomap(fwnode, 0);
 	if (!mm_gc->regs)
 		goto err1;
 
@@ -831,8 +833,8 @@  int of_mm_gpiochip_add_data(struct device_node *np,
 	if (mm_gc->save_regs)
 		mm_gc->save_regs(mm_gc);
 
-	of_node_put(mm_gc->gc.of_node);
-	mm_gc->gc.of_node = of_node_get(np);
+	fwnode_handle_put(mm_gc->gc.fwnode);
+	mm_gc->gc.fwnode = fwnode_handle_get(fwnode);
 
 	ret = gpiochip_add_data(gc, data);
 	if (ret)
@@ -840,12 +842,12 @@  int of_mm_gpiochip_add_data(struct device_node *np,
 
 	return 0;
 err2:
-	of_node_put(np);
+	fwnode_handle_put(fwnode);
 	iounmap(mm_gc->regs);
 err1:
 	kfree(gc->label);
 err0:
-	pr_err("%pOF: GPIO chip registration failed with status %d\n", np, ret);
+	pr_err("%pfw: GPIO chip registration failed with status %d\n", fwnode, ret);
 	return ret;
 }
 EXPORT_SYMBOL_GPL(of_mm_gpiochip_add_data);
@@ -869,9 +871,9 @@  EXPORT_SYMBOL_GPL(of_mm_gpiochip_remove);
 
 static void of_gpiochip_init_valid_mask(struct gpio_chip *chip)
 {
+	struct device_node *np = to_of_node(chip->fwnode);
 	int len, i;
 	u32 start, count;
-	struct device_node *np = chip->of_node;
 
 	len = of_property_count_u32_elems(np,  "gpio-reserved-ranges");
 	if (len < 0 || len % 2 != 0)
@@ -892,7 +894,7 @@  static void of_gpiochip_init_valid_mask(struct gpio_chip *chip)
 #ifdef CONFIG_PINCTRL
 static int of_gpiochip_add_pin_range(struct gpio_chip *chip)
 {
-	struct device_node *np = chip->of_node;
+	struct device_node *np = to_of_node(chip->fwnode);
 	struct of_phandle_args pinspec;
 	struct pinctrl_dev *pctldev;
 	int index = 0, ret;
@@ -982,9 +984,10 @@  static int of_gpiochip_add_pin_range(struct gpio_chip *chip) { return 0; }
 
 int of_gpiochip_add(struct gpio_chip *chip)
 {
+	struct device_node *np = to_of_node(chip->fwnode);
 	int ret;
 
-	if (!chip->of_node)
+	if (!np)
 		return 0;
 
 	if (!chip->of_xlate) {
@@ -1001,32 +1004,16 @@  int of_gpiochip_add(struct gpio_chip *chip)
 	if (ret)
 		return ret;
 
-	of_node_get(chip->of_node);
+	fwnode_handle_get(chip->fwnode);
 
 	ret = of_gpiochip_scan_gpios(chip);
 	if (ret)
-		of_node_put(chip->of_node);
+		fwnode_handle_put(chip->fwnode);
 
 	return ret;
 }
 
 void of_gpiochip_remove(struct gpio_chip *chip)
 {
-	of_node_put(chip->of_node);
-}
-
-void of_gpio_dev_init(struct gpio_chip *gc, struct gpio_device *gdev)
-{
-	/* Set default OF node to parent's one if present */
-	if (gc->parent)
-		gdev->dev.of_node = gc->parent->of_node;
-
-	if (gc->fwnode)
-		gc->of_node = to_of_node(gc->fwnode);
-
-	/* If the gpiochip has an assigned OF node this takes precedence */
-	if (gc->of_node)
-		gdev->dev.of_node = gc->of_node;
-	else
-		gc->of_node = gdev->dev.of_node;
+	fwnode_handle_put(chip->fwnode);
 }
diff --git a/drivers/gpio/gpiolib-of.h b/drivers/gpio/gpiolib-of.h
index 8af2bc899aab..ed26664f1537 100644
--- a/drivers/gpio/gpiolib-of.h
+++ b/drivers/gpio/gpiolib-of.h
@@ -15,7 +15,6 @@  int of_gpiochip_add(struct gpio_chip *gc);
 void of_gpiochip_remove(struct gpio_chip *gc);
 int of_gpio_get_count(struct device *dev, const char *con_id);
 bool of_gpio_need_valid_mask(const struct gpio_chip *gc);
-void of_gpio_dev_init(struct gpio_chip *gc, struct gpio_device *gdev);
 #else
 static inline struct gpio_desc *of_find_gpio(struct device *dev,
 					     const char *con_id,
@@ -34,10 +33,6 @@  static inline bool of_gpio_need_valid_mask(const struct gpio_chip *gc)
 {
 	return false;
 }
-static inline void of_gpio_dev_init(struct gpio_chip *gc,
-				    struct gpio_device *gdev)
-{
-}
 #endif /* CONFIG_OF_GPIO */
 
 extern struct notifier_block gpio_of_notifier;
diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c
index 4756ea08894f..d2f1b3c027d1 100644
--- a/drivers/gpio/gpiolib.c
+++ b/drivers/gpio/gpiolib.c
@@ -594,7 +594,6 @@  int gpiochip_add_data_with_key(struct gpio_chip *gc, void *data,
 			       struct lock_class_key *lock_key,
 			       struct lock_class_key *request_key)
 {
-	struct fwnode_handle *fwnode = NULL;
 	struct gpio_device *gdev;
 	unsigned long flags;
 	int base = gc->base;
@@ -602,11 +601,6 @@  int gpiochip_add_data_with_key(struct gpio_chip *gc, void *data,
 	int ret = 0;
 	u32 ngpios;
 
-	if (gc->fwnode)
-		fwnode = gc->fwnode;
-	else if (gc->parent)
-		fwnode = dev_fwnode(gc->parent);
-
 	/*
 	 * First: allocate and populate the internal stat container, and
 	 * set up the struct device.
@@ -619,14 +613,7 @@  int gpiochip_add_data_with_key(struct gpio_chip *gc, void *data,
 	gdev->chip = gc;
 	gc->gpiodev = gdev;
 
-	of_gpio_dev_init(gc, gdev);
-	acpi_gpio_dev_init(gc, gdev);
-
-	/*
-	 * Assign fwnode depending on the result of the previous calls,
-	 * if none of them succeed, assign it to the parent's one.
-	 */
-	gdev->dev.fwnode = dev_fwnode(&gdev->dev) ?: fwnode;
+	device_set_node(&gdev->dev, gc->fwnode ?: dev_fwnode(gc->parent));
 
 	gdev->id = ida_alloc(&gpio_ida, GFP_KERNEL);
 	if (gdev->id < 0) {
diff --git a/include/linux/gpio/driver.h b/include/linux/gpio/driver.h
index 60b7896e14b9..17144bc6240f 100644
--- a/include/linux/gpio/driver.h
+++ b/include/linux/gpio/driver.h
@@ -506,13 +506,6 @@  struct gpio_chip {
 	 * the device tree automatically may have an OF translation
 	 */
 
-	/**
-	 * @of_node:
-	 *
-	 * Pointer to a device tree node representing this GPIO controller.
-	 */
-	struct device_node *of_node;
-
 	/**
 	 * @of_gpio_n_cells:
 	 *