gpio-langwell: bugfix and amendments
v3 cover gpio-langwell: bugfix and amendments
There is locking bug fix and few amendments. Each commit message verbose enoough I think.
Since v2:
- apply ACKs
- addressed Mika's comment for patch 3/4
- append patch 5/5
Since v1:
- patch 2/4 ("amend error messages") moved to 4/4
- minor fix in patch 3/4 ("use managed ...")
- fix patch 4/4 ("amend error messages") to be real amendment
Andy Shevchenko (5):
gpio-langwell: initialize lock before usage
gpio-langwell: do not use direct access to iomapped memory
gpio-langwell: use managed functions pcim_* and devm_*
gpio-langwell: amend error messages
gpio-langwell: drop away explicit casting
drivers/gpio/gpio-langwell.c | 117 ++++++++++++++----------------------------- 1 file changed, 38 insertions(+), 79 deletions(-)
Signature · 1 line
1.8.2.rc0.22.gb3600c3
PATCH v3 1/5 gpio-langwell: initialize lock before usage
Otherwise we will end up with traceback from LOCKDEP:
INFO: trying to register non-static key.
the code is fine but needs lockdep annotation.
turning off the locking correctness validator.
CPU: 0 PID: 1 Comm: swapper/0 Not tainted 3.10.0-rc2-next-20130521-00028-g09aa9fc #487 00000000 00000000 f6c55c54 c1541fe4 f6040bf8 f6c55c8c c1069ef1 c1726bc1 c1726cc8 c1726c9e 00000000 f6c584e0 f6c58000 f6c55ce8 00000000 f6040bf8 f6040bf8 00000046 f6c58000 f6c55d00 c106a18d 00000a2b 00000003 00004f02 Call Trace: [<c1541fe4>] dump_stack+0x49/0x77 [<c1069ef1>] register_lock_class+0x58/0x260 [<c106a18d>] __lock_acquire+0x94/0xcff [<c106adc8>] ? __lock_acquire+0xccf/0xcff [<c106b2ad>] lock_acquire+0xcc/0x10d [<c1269c7c>] ? lnw_irq_type+0x63/0xe9 [<c1545da0>] _raw_spin_lock_irqsave+0x32/0x42 [<c1269c7c>] ? lnw_irq_type+0x63/0xe9 [<c1269c7c>] lnw_irq_type+0x63/0xe9 [<c108f454>] __irq_set_trigger+0x98/0x123 [<c1090225>] irq_set_irq_type+0x2f/0x51 [<c1090225>] ? irq_set_irq_type+0x2f/0x51 [<c1269d02>] ? lnw_irq_type+0xe9/0xe9 [<c1269d34>] lnw_gpio_irq_map+0x32/0x3b [<c10914f2>] irq_domain_add_legacy+0xe2/0x107 [<c1091b53>] irq_domain_add_simple+0x47/0x60 [<c1269f6e>] lnw_gpio_probe+0x119/0x217 [<c1271018>] pci_device_probe+0x5a/0x92
...
--- drivers/gpio/gpio-langwell.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/gpio/gpio-langwell.c +2 -2
@@ -380,6 +380,8 @@ static int lnw_gpio_probe(struct pci_dev *pdev, lnw->chip.can_sleep =0 ; lnw->pdev = pdev; +spin_lock_init (&lnw->lock); + lnw->domain =irq_domain_add_simple (pdev->dev.of_node, ngpio, irq_base, &lnw_gpio_irq_ops, lnw);if (!lnw->domain) {
@@ -399,8 +401,6 @@ static int lnw_gpio_probe(struct pci_dev *pdev,irq_set_handler_data (pdev->irq, lnw);irq_set_chained_handler (pdev->irq, lnw_irq_handler); -spin_lock_init (&lnw->lock); -pm_runtime_put_noidle (&pdev->dev);pm_runtime_allow (&pdev->dev);
Signature · 1 line
1.8.2.rc0.22.gb3600c3
Re: [PATCH v3 1/5] gpio-langwell: initialize lock before usage
Quoted 28 lines · Andy Shevchenko
Otherwise we will end up with traceback from LOCKDEP:
INFO: trying to register non-static key.
the code is fine but needs lockdep annotation.
turning off the locking correctness validator.CPU: 0 PID: 1 Comm: swapper/0 Not tainted 3.10.0-rc2-next-20130521-00028-g09aa9fc #487 00000000 00000000 f6c55c54 c1541fe4 f6040bf8 f6c55c8c c1069ef1 c1726bc1 c1726cc8 c1726c9e 00000000 f6c584e0 f6c58000 f6c55ce8 00000000 f6040bf8 f6040bf8 00000046 f6c58000 f6c55d00 c106a18d 00000a2b 00000003 00004f02 Call Trace: [<c1541fe4>] dump_stack+0x49/0x77 [<c1069ef1>] register_lock_class+0x58/0x260 [<c106a18d>] __lock_acquire+0x94/0xcff [<c106adc8>] ? __lock_acquire+0xccf/0xcff [<c106b2ad>] lock_acquire+0xcc/0x10d [<c1269c7c>] ? lnw_irq_type+0x63/0xe9 [<c1545da0>] _raw_spin_lock_irqsave+0x32/0x42 [<c1269c7c>] ? lnw_irq_type+0x63/0xe9 [<c1269c7c>] lnw_irq_type+0x63/0xe9 [<c108f454>] __irq_set_trigger+0x98/0x123 [<c1090225>] irq_set_irq_type+0x2f/0x51 [<c1090225>] ? irq_set_irq_type+0x2f/0x51 [<c1269d02>] ? lnw_irq_type+0xe9/0xe9 [<c1269d34>] lnw_gpio_irq_map+0x32/0x3b [<c10914f2>] irq_domain_add_legacy+0xe2/0x107 [<c1091b53>] irq_domain_add_simple+0x47/0x60 [<c1269f6e>] lnw_gpio_probe+0x119/0x217 [<c1271018>] pci_device_probe+0x5a/0x92
Quoted 4 lines
...
Signed-off-by Andy Shevchenko <[email protected]>Acked-by Mika Westerberg <[email protected]>
Patch applied.
Yours,
Linus Walleij
Re: [PATCH v3 1/5] gpio-langwell: initialize lock before usage
In reply to Andy ShevchenkoQuoted 1 line · Andy Shevchenko
Otherwise we will end up with traceback from LOCKDEP:
Andy do you consider this a regression that needs to go into fixes?
I.e. is this used in in-tree code and causing problems with v3.10...
I'm asking because it creates a mess as the rest of the series depend on it.
It is currently applied for v3.11.
Yours,
Linus Walleij
Re: [PATCH v3 1/5] gpio-langwell: initialize lock before usage
Quoted 6 lines · Linus Walleij
Quoted 1 line · Andy Shevchenko
Otherwise we will end up with traceback from LOCKDEP:
Andy do you consider this a regression that needs to go into fixes?
I think so. The commit 2519f9abced15b4327f03d7b8666827517582c29
was the recent one which probably brought such behaviour.
Quoted 6 lines
I.e. is this used in in-tree code and causing problems with v3.10...
I'm asking because it creates a mess as the rest of the series depend on it.
It is currently applied for v3.11.
Perhaps it should go to v3.10 as well.
--
With Best Regards,
Andy Shevchenko
PATCH v3 2/5 gpio-langwell: do not use direct access to iomapped memory
In reply to Andy ShevchenkoWe better to use readl() function instead of bad looking direct access.
--- drivers/gpio/gpio-langwell.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-)
drivers/gpio/gpio-langwell.c +7 -5
@@ -65,7 +65,7 @@ enum GPIO_REG {struct lnw_gpio {struct gpio_chip chip; -void *reg_base; +void __iomem *reg_base;spinlock_t lock;struct pci_dev *pdev;struct irq_domain *domain;
@@ -318,9 +318,9 @@ static const struct dev_pm_ops lnw_gpio_pm_ops = { };static int lnw_gpio_probe (struct pci_dev *pdev, -const struct pci_device_id *id) +const struct pci_device_id *id) { -void *base; +void __iomem *base;resource_size_t start, len;struct lnw_gpio *lnw;u32 gpio_base;
@@ -346,8 +346,10 @@ static int lnw_gpio_probe(struct pci_dev *pdev, retval = -EFAULT ; goto err_ioremap; } - irq_base = *(u32 *)base; - gpio_base = *((u32 *)base +1 ); + + irq_base =readl (base); + gpio_base =readl (sizeof (u32) + base); +/* release the IO mapping, since we already get the info from bar1 */ iounmap (base);/* get the register base from bar0 */
Signature · 1 line
1.8.2.rc0.22.gb3600c3
Re: [PATCH v3 2/5] gpio-langwell: do not use direct access to iomapped memory
Quoted 4 lines · Andy Shevchenko
We better to use
readl()function instead of bad looking direct access.Signed-off-by Andy Shevchenko <[email protected]>Acked-by Mika Westerberg <[email protected]>
Patch applied.
Yours,
Linus Walleij
PATCH v3 3/5 gpio-langwell: use managed functions pcim_* and devm_*
In reply to Andy ShevchenkoThis makes the error handling much more simpler than open-coding everything and in addition makes the probe function smaller an tidier.
--- drivers/gpio/gpio-langwell.c | 79 ++++++++++++-------------------------------- 1 file changed, 21 insertions(+), 58 deletions(-)
drivers/gpio/gpio-langwell.c +21 -58
@@ -321,55 +321,37 @@ static int lnw_gpio_probe(struct pci_dev *pdev, const struct pci_device_id *id) {void __iomem *base; -resource_size_t start, len;struct lnw_gpio *lnw;u32 gpio_base;u32 irq_base;int retval;int ngpio = id->driver_data; - retval =pci_enable_device (pdev); + retval =pcim_enable_device (pdev);if (retval)return retval; - retval =pci_request_regions (pdev,"langwell_gpio" ); + retval =pcim_iomap_regions (pdev,1 <<0 |1 <<1 ,pci_name (pdev));if (retval) { -dev_err (&pdev->dev,"error requesting resources\n" ); - goto err_pci_req_region; - } -/* get the gpio_base from bar1 */ - start =pci_resource_start (pdev,1 ); - len =pci_resource_len (pdev,1 ); - base =ioremap_nocache (start, len); -if (!base) { -dev_err (&pdev->dev,"error mapping bar1\n" ); - retval = -EFAULT ; - goto err_ioremap; +dev_err (&pdev->dev,"I/O memory mapping error\n" ); +return retval; } + base =pcim_iomap_table (pdev)[1 ]; + irq_base =readl (base); gpio_base =readl (sizeof (u32) + base);/* release the IO mapping, since we already get the info from bar1 */ -iounmap (base); -/* get the register base from bar0 */ - start =pci_resource_start (pdev,0 ); - len =pci_resource_len (pdev,0 ); - base =devm_ioremap_nocache (&pdev->dev, start, len); -if (!base) { -dev_err (&pdev->dev,"error mapping bar0\n" ); - retval = -EFAULT ; - goto err_ioremap; - } +pcim_iounmap_regions (pdev,1 <<1 ); lnw =devm_kzalloc (&pdev->dev,sizeof (*lnw),GFP_KERNEL );if (!lnw) {dev_err (&pdev->dev,"can't allocate langwell_gpio chip data\n" ); - retval = -ENOMEM ; - goto err_ioremap; +return -ENOMEM ; } - lnw->reg_base = base; + lnw->reg_base =pcim_iomap_table (pdev)[0 ]; lnw->chip.label =dev_name (&pdev->dev); lnw->chip.request = lnw_gpio_request; lnw->chip.direction_input = lnw_gpio_direction_input;
@@ -386,16 +368,14 @@ static int lnw_gpio_probe(struct pci_dev *pdev, lnw->domain =irq_domain_add_simple (pdev->dev.of_node, ngpio, irq_base, &lnw_gpio_irq_ops, lnw); -if (!lnw->domain) { - retval = -ENOMEM ; - goto err_ioremap; - } +if (!lnw->domain) +return -ENOMEM ;pci_set_drvdata (pdev, lnw); retval =gpiochip_add (&lnw->chip);if (retval) {dev_err (&pdev->dev,"langwell gpiochip_add error %d\n" , retval); - goto err_ioremap; +return retval; }lnw_irq_init_hw (lnw);
@@ -407,12 +387,6 @@ static int lnw_gpio_probe(struct pci_dev *pdev,pm_runtime_allow (&pdev->dev);return 0 ; - -err_ioremap: -pci_release_regions (pdev); -err_pci_req_region: -pci_disable_device (pdev); -return retval; }static struct pci_driver lnw_gpio_driver = {
@@ -430,23 +404,20 @@ static int wp_gpio_probe(struct platform_device *pdev)struct lnw_gpio *lnw;struct gpio_chip *gc;struct resource *rc; -int retval =0 ; - - rc =platform_get_resource (pdev,IORESOURCE_MEM ,0 ); -if (!rc) -return -EINVAL ; +int retval; - lnw =kzalloc (sizeof (struct lnw_gpio ),GFP_KERNEL ); + lnw =devm_kzalloc (&pdev->dev,sizeof (struct lnw_gpio ),GFP_KERNEL );if (!lnw) {dev_err (&pdev->dev,"can't allocate whitneypoint_gpio chip data\n" );return -ENOMEM ; } - lnw->reg_base =ioremap_nocache (rc->start,resource_size (rc)); -if (lnw->reg_base ==NULL ) { - retval = -EINVAL ; - goto err_kmalloc; - } + + rc =platform_get_resource (pdev,IORESOURCE_MEM ,0 ); + lnw->reg_base =devm_ioremap_resource (&pdev->dev, rc); +if (IS_ERR (lnw->reg_base)) +return PTR_ERR (lnw->reg_base); +spin_lock_init (&lnw->lock); gc = &lnw->chip; gc->label =dev_name (&pdev->dev);
@@ -463,15 +434,10 @@ static int wp_gpio_probe(struct platform_device *pdev)if (retval) {dev_err (&pdev->dev,"whitneypoint gpiochip_add error %d\n" , retval); - goto err_ioremap; +return retval; }platform_set_drvdata (pdev, lnw);return 0 ; -err_ioremap: -iounmap (lnw->reg_base); -err_kmalloc: -kfree (lnw); -return retval; }static int wp_gpio_remove (struct platform_device *pdev)
@@ -481,9 +447,6 @@ static int wp_gpio_remove(struct platform_device *pdev) err =gpiochip_remove (&lnw->chip);if (err)dev_err (&pdev->dev,"failed to remove gpio_chip.\n" ); -iounmap (lnw->reg_base); -kfree (lnw); -platform_set_drvdata (pdev,NULL );return 0 ; }
Signature · 1 line
1.8.2.rc0.22.gb3600c3
Re: [PATCH v3 3/5] gpio-langwell: use managed functions pcim_* and devm_*
Quoted 4 lines · Andy Shevchenko
This makes the error handling much more simpler than open-coding everything and in addition makes the probe function smaller an tidier.
Signed-off-by Andy Shevchenko <[email protected]>
Re: [PATCH v3 3/5] gpio-langwell: use managed functions pcim_* and devm_*
In reply to Andy ShevchenkoQuoted 4 lines · Andy Shevchenko
This makes the error handling much more simpler than open-coding everything and in addition makes the probe function smaller an tidier.
Signed-off-by Andy Shevchenko <[email protected]>
Applied with Mika's ACK.
I had to rebase this thing since there was a patch removing the line setting platform data to NULL on remove(), check that I did the right thing in the result.
Yours,
Linus Walleij
Re: [PATCH v3 3/5] gpio-langwell: use managed functions pcim_* and devm_*
Quoted 6 lines · Linus Walleij
Quoted 3 lines · Andy Shevchenko
This makes the error handling much more simpler than open-coding everything and in addition makes the probe function smaller an tidier.
Quoted 7 lines
Quoted 1 line
Signed-off-by Andy Shevchenko <[email protected]>Applied with Mika's ACK.
I had to rebase this thing since there was a patch removing the line setting platform data to NULL on
remove(), check that I did the right thing in the result.
Yes, that is correct. Thanks!
Signature · 2 lines
Andy Shevchenko <[email protected]> Intel Finland Oy
PATCH v3 4/5 gpio-langwell: amend error messages
In reply to Andy ShevchenkoThere is no need to use hardcoded device name in the error messages, because dev_err() prefixes the message with the device name anyway.
--- drivers/gpio/gpio-langwell.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-)
drivers/gpio/gpio-langwell.c +4 -6
@@ -347,7 +347,7 @@ static int lnw_gpio_probe(struct pci_dev *pdev, lnw =devm_kzalloc (&pdev->dev,sizeof (*lnw),GFP_KERNEL );if (!lnw) { -dev_err (&pdev->dev,"can't allocate langwell_gpio chip data\n" ); +dev_err (&pdev->dev,"can't allocate chip data\n" );return -ENOMEM ; }
@@ -374,7 +374,7 @@ static int lnw_gpio_probe(struct pci_dev *pdev,pci_set_drvdata (pdev, lnw); retval =gpiochip_add (&lnw->chip);if (retval) { -dev_err (&pdev->dev,"langwell gpiochip_add error %d\n" , retval); +dev_err (&pdev->dev,"gpiochip_add error %d\n" , retval);return retval; }
@@ -408,8 +408,7 @@ static int wp_gpio_probe(struct platform_device *pdev) lnw =devm_kzalloc (&pdev->dev,sizeof (struct lnw_gpio ),GFP_KERNEL );if (!lnw) { -dev_err (&pdev->dev, -"can't allocate whitneypoint_gpio chip data\n" ); +dev_err (&pdev->dev,"can't allocate chip data\n" );return -ENOMEM ; }
@@ -432,8 +431,7 @@ static int wp_gpio_probe(struct platform_device *pdev) gc->can_sleep =0 ; retval =gpiochip_add (gc);if (retval) { -dev_err (&pdev->dev,"whitneypoint gpiochip_add error %d\n" , - retval); +dev_err (&pdev->dev,"gpiochip_add error %d\n" , retval);return retval; }platform_set_drvdata (pdev, lnw);
Signature · 1 line
1.8.2.rc0.22.gb3600c3
Re: [PATCH v3 4/5] gpio-langwell: amend error messages
Quoted 5 lines · Andy Shevchenko
There is no need to use hardcoded device name in the error messages, because
dev_err()prefixes the message with the device name anyway.Signed-off-by Andy Shevchenko <[email protected]>Acked-by Mika Westerberg <[email protected]>
Patch applied.
Yours,
Linus Walleij
PATCH v3 5/5 gpio-langwell: drop away explicit casting
In reply to Andy ShevchenkoSince the type of the reg_base member is void __iomem * we don't need to have explicit casting in gpio_reg() and gpio_reg_2bit().
Update year in the copyright notice as well.
--- drivers/gpio/gpio-langwell.c | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-)
drivers/gpio/gpio-langwell.c +4 -8
@@ -1,7 +1,7 @@/* * Moorestown platform Langwell chip GPIO driver * -* Copyright (c) 2008 - 2009, Intel Corporation. +* Copyright (c) 2008, 2009, 2013, Intel Corporation. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2 as
@@ -74,15 +74,13 @@ struct lnw_gpio {#define to_lnw_priv (chip) container_of(chip, struct lnw_gpio, chip)static void __iomem *gpio_reg (struct gpio_chip *chip,unsigned offset, -enum GPIO_REG reg_type) +enum GPIO_REG reg_type) {struct lnw_gpio *lnw =to_lnw_priv (chip);unsigned nreg = chip->ngpio /32 ;u8 reg = offset /32 ; -void __iomem *ptr; - ptr = (void __iomem *)(lnw->reg_base + reg_type * nreg *4 + reg *4 ); -return ptr; +return lnw->reg_base + reg_type * nreg *4 + reg *4 ; } static void __iomem *gpio_reg_2bit(struct gpio_chip *chip, unsigned offset,
@@ -91,10 +89,8 @@ static void __iomem *gpio_reg_2bit(struct gpio_chip *chip, unsigned offset,struct lnw_gpio *lnw =to_lnw_priv (chip);unsigned nreg = chip->ngpio /32 ;u8 reg = offset /16 ; -void __iomem *ptr; - ptr = (void __iomem *)(lnw->reg_base + reg_type * nreg *4 + reg *4 ); -return ptr; +return lnw->reg_base + reg_type * nreg *4 + reg *4 ; }static int lnw_gpio_request (struct gpio_chip *chip,unsigned offset)
Signature · 1 line
1.8.2.rc0.22.gb3600c3
Re: [PATCH v3 5/5] gpio-langwell: drop away explicit casting
Quoted 6 lines · Andy Shevchenko
Since the type of the
reg_basemember is void__iomem* we don't need to have explicit casting ingpio_reg()andgpio_reg_2bit().Update year in the copyright notice as well.
Signed-off-by Andy Shevchenko <[email protected]>
Re: [PATCH v3 5/5] gpio-langwell: drop away explicit casting
In reply to Andy ShevchenkoQuoted 6 lines · Andy Shevchenko
Since the type of the
reg_basemember is void__iomem* we don't need to have explicit casting ingpio_reg()andgpio_reg_2bit().Update year in the copyright notice as well.
Signed-off-by Andy Shevchenko <[email protected]>
Patch applied with Mika's ACK.
Yours,
Linus Walleij
Quoted 20 lines · Andy Shevchenko
There is locking bug fix and few amendments. Each commit message verbose enoough I think.
Since v2:
- apply ACKs
- addressed Mika's comment for patch 3/4
- append patch 5/5Since v1:
- patch 2/4 ("amend error messages") moved to 4/4
- minor fix in patch 3/4 ("use managed ...")
- fix patch 4/4 ("amend error messages") to be real amendmentAndy Shevchenko (5):
gpio-langwell: initialize lock before usage
gpio-langwell: do not use direct access to iomapped memory
gpio-langwell: use managed functions pcim_* and devm_*
gpio-langwell: amend error messages
gpio-langwell: drop away explicit casting
Quoted 3 lines
drivers/gpio/gpio-langwell.c | 117 ++++++++++++++----------------------------- 1 file changed, 38 insertions(+), 79 deletions(-)
For the whole set:
Quoted 22 lines · David Cohen
Quoted 21 lines · Andy Shevchenko
There is locking bug fix and few amendments. Each commit message verbose enoough I think.
Since v2:
- apply ACKs
- addressed Mika's comment for patch 3/4
- append patch 5/5Since v1:
- patch 2/4 ("amend error messages") moved to 4/4
- minor fix in patch 3/4 ("use managed ...")
- fix patch 4/4 ("amend error messages") to be real amendmentAndy Shevchenko (5):
gpio-langwell: initialize lock before usage
gpio-langwell: do not use direct access to iomapped memory
gpio-langwell: use managed functions pcim_* and devm_*
gpio-langwell: amend error messages
gpio-langwell: drop away explicit casting
Quoted 5 lines
Quoted 3 lines
drivers/gpio/gpio-langwell.c | 117 ++++++++++++++----------------------------- 1 file changed, 38 insertions(+), 79 deletions(-)For the whole set:
Acked-by David Cohen <[email protected]>
Linus, do you have any comments on this?
--
With Best Regards,
Andy Shevchenko
Quoted 1 line · Andy Shevchenko
Linus, do you have any comments on this?
Sorry for the delay. I have applied the v3 patchset now.
I'll also edit in David Cohen's ACK on all patches.
Yours,
Linus Walleij