gpio: mxc: Shift generic request/free after gpiochip registration
Subsystems (2)
PATCH v2 1/1 gpio: mxc: Shift generic request/free after gpiochip registration
generic gpio request/free should be added after gpiocip registration to validate mapping of gpiochip with pinctrl subsystem.
gpiochip->pin_ranges list contains the information used by pinctrl subsystem to configure corresponding pins for gpio usage. This list will be empty if gpiochip fails to map with pinctrl subsystem for any reason.
For Ex.:-
generic gpio request/free should not be used if IOMUX pin controller device node is disabled in device tree.
This commit checks above list and skips adding generic gpio request/free if list is found empty.
---
Changes from v1 to v2:
* Rebased on top of lwalleij/gpio/fixes.
drivers/gpio/gpio-mxc.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)
drivers/gpio/gpio-mxc.c +5 -5
@@ -458,11 +458,6 @@ static int mxc_gpio_probe(struct platform_device *pdev)if (err) goto out_bgio; -if (of_property_read_bool (np,"gpio-ranges" )) { - port->gc.request = gpiochip_generic_request; - port->gc.free = gpiochip_generic_free; - } - port->gc.to_irq = mxc_gpio_to_irq; port->gc.base = (pdev->id <0 ) ?of_alias_get_id (np,"gpio" ) *32 : pdev->id *32 ;
@@ -471,6 +466,11 @@ static int mxc_gpio_probe(struct platform_device *pdev)if (err) goto out_bgio; +if (!list_empty (&port->gc.pin_ranges)) { + port->gc.request = gpiochip_generic_request; + port->gc.free = gpiochip_generic_free; + } + irq_base =irq_alloc_descs (-1 ,0 ,32 ,numa_node_id ());if (irq_base <0 ) { err = irq_base;
Signature · 1 line
1.9.1
Quoted 11 lines · Deepak Das
generic gpio request/free should be added after gpiocip registration to validate mapping of gpiochip with pinctrl subsystem.
gpiochip->pin_rangeslist contains the information used by pinctrl subsystem to configure corresponding pins for gpio usage. This list will be empty if gpiochip fails to map with pinctrl subsystem for any reason.
For Ex.:-
generic gpio request/free should not be used if IOMUX pin controller device node is disabled in device tree.
Quoted 8 lines
This commit checks above list and skips adding generic gpio request/free if list is found empty.
Signed-off-by Deepak Das <[email protected]>Signed-off-by Vladimir Zapolskiy <[email protected]>---
Changes from v1 to v2:
* Rebased on top of lwalleij/gpio/fixes.
Patch applied.
Yours,
Linus Walleij
Quoted 11 lines · Deepak Das
generic gpio request/free should be added after gpiocip registration to validate mapping of gpiochip with pinctrl subsystem.
gpiochip->pin_rangeslist contains the information used by pinctrl subsystem to configure corresponding pins for gpio usage. This list will be empty if gpiochip fails to map with pinctrl subsystem for any reason.
For Ex.:-
generic gpio request/free should not be used if IOMUX pin controller device node is disabled in device tree.
Quoted 5 lines
This commit checks above list and skips adding generic gpio request/free if list is found empty.
Signed-off-by Deepak Das <[email protected]>Signed-off-by Vladimir Zapolskiy <[email protected]>
So we should not dereference gpiolib internals.
Quoted 9 lines
drivers/gpio/gpio-mxc.c +0
-5-if (of_property_read_bool (np,"gpio-ranges" )) { - port->gc.request = gpiochip_generic_request; - port->gc.free = gpiochip_generic_free; - } - port->gc.to_irq = mxc_gpio_to_irq; port->gc.base = (pdev->id <0 ) ?of_alias_get_id (np,"gpio" ) *32 : pdev->id *32 ;
drivers/gpio/gpio-mxc.c static int mxc_gpio_probe(struct platform_device *pdev) · line 472
Quoted 7 lines
drivers/gpio/gpio-mxc.c +4
-0@@ -471,6 +466,11 @@ static int mxc_gpio_probe(struct platform_device *pdev)if (err) goto out_bgio; +if (!list_empty (&port->gc.pin_ranges)) { + port->gc.request = gpiochip_generic_request; + port->gc.free = gpiochip_generic_free; + }
Can't you just check the "gpio-ranges" property later instead?
Yours,
Linus Walleij
Hi Linus, Deepak,
Quoted 33 lines · Linus Walleij
Quoted 11 lines · Deepak Das
generic gpio request/free should be added after gpiocip registration to validate mapping of gpiochip with pinctrl subsystem.
gpiochip->pin_rangeslist contains the information used by pinctrl subsystem to configure corresponding pins for gpio usage. This list will be empty if gpiochip fails to map with pinctrl subsystem for any reason.
For Ex.:-
generic gpio request/free should not be used if IOMUX pin controller device node is disabled in device tree.Quoted 5 lines
This commit checks above list and skips adding generic gpio request/free if list is found empty.
Signed-off-by Deepak Das <[email protected]>Signed-off-by Vladimir Zapolskiy <[email protected]>So we should not dereference gpiolib internals.
Quoted 12 lines
drivers/gpio/gpio-mxc.c +0
-5-if (of_property_read_bool (np,"gpio-ranges" )) { - port->gc.request = gpiochip_generic_request; - port->gc.free = gpiochip_generic_free; - } - port->gc.to_irq = mxc_gpio_to_irq; port->gc.base = (pdev->id <0 ) ?of_alias_get_id (np,"gpio" ) *32 : pdev->id *32 ;@@ -471,6 +466,11 @@ static int mxc_gpio_probe(struct platform_device *pdev)if (err) goto out_bgio;
Quoted 6 lines
drivers/gpio/gpio-mxc.c static int mxc_gpio_probe(struct platform_device *pdev) · line 472
Quoted 4 lines
drivers/gpio/gpio-mxc.c +4
-0+if (!list_empty (&port->gc.pin_ranges)) { + port->gc.request = gpiochip_generic_request; + port->gc.free = gpiochip_generic_free; + }Can't you just check the "gpio-ranges" property later instead?
The change was done for a kernel when of_gpiochip_add_pin_range() did not return an error code and the change is not applicable to the vanilla kernel.
Potentially of_gpiochip_add_pin_range() may fail due to some other reason than a missing pinctrl device from the supplied phandle (e.g. -ENOMEM), but in that case gpiochip_add_data() will also fail and the late check for empty pin_ranges becomes redundant.
Originally the change is needed exclusively to cover the case, when IOMUX device node is removed or disabled in a board DTB, while GPIOs still can be requested by other controller drivers. The disabled pinctrl device case (pinmux/pinctrl settings are done from a bootloader only) is inapplicable to any boards found in upstream, so I would propose *not* to include this change or any its derivative fix to the upstream.
If somebody wants to support the scenario described above on a board not found in vanilla, the best option is to remove gpio-ranges proporty from the board DTS file along with disabling IOMUX, then the GPIO driver in its currently existing state can be successfully reused without any runtime issues.
--
With best wishes,
Vladimir
Quoted 6 lines · Vladimir Zapolskiy
Originally the change is needed exclusively to cover the case, when IOMUX device node is removed or disabled in a board DTB, while GPIOs still can be requested by other controller drivers. The disabled pinctrl device case (pinmux/pinctrl settings are done from a bootloader only) is inapplicable to any boards found in upstream, so I would propose *not* to include this change or any its derivative fix to the upstream.
I backed it out already. It didn't even compile.
Yours,
Linus Walleij