* [PATCH] i2c: thunderx: Fix some resource leak
@ 2021-10-16 8:48 Christophe JAILLET
2021-10-18 21:15 ` Robert Richter
0 siblings, 1 reply; 3+ messages in thread
From: Christophe JAILLET @ 2021-10-16 8:48 UTC (permalink / raw)
To: rric, jan.glauber, wsa
Cc: linux-i2c, linux-kernel, kernel-janitors, Christophe JAILLET
We need to undo a 'pci_request_regions()' call in the error handling path
of the probe function and in the remove function.
Fixes: 22d40209de3b ("i2c: thunderx: Add i2c driver for ThunderX SOC")
Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
---
drivers/i2c/busses/i2c-thunderx-pcidrv.c | 9 +++++++--
1 file changed, 7 insertions(+), 2 deletions(-)
diff --git a/drivers/i2c/busses/i2c-thunderx-pcidrv.c b/drivers/i2c/busses/i2c-thunderx-pcidrv.c
index 12c90aa0900e..2d37096a6968 100644
--- a/drivers/i2c/busses/i2c-thunderx-pcidrv.c
+++ b/drivers/i2c/busses/i2c-thunderx-pcidrv.c
@@ -177,8 +177,10 @@ static int thunder_i2c_probe_pci(struct pci_dev *pdev,
return ret;
i2c->twsi_base = pcim_iomap(pdev, 0, pci_resource_len(pdev, 0));
- if (!i2c->twsi_base)
- return -EINVAL;
+ if (!i2c->twsi_base) {
+ ret = -EINVAL;
+ goto err_release_regions;
+ }
thunder_i2c_clock_enable(dev, i2c);
ret = device_property_read_u32(dev, "clock-frequency", &i2c->twsi_freq);
@@ -231,6 +233,8 @@ static int thunder_i2c_probe_pci(struct pci_dev *pdev,
error:
thunder_i2c_clock_disable(dev, i2c->clk);
+err_release_regions:
+ pci_release_regions(pdev);
return ret;
}
@@ -241,6 +245,7 @@ static void thunder_i2c_remove_pci(struct pci_dev *pdev)
thunder_i2c_smbus_remove(i2c);
thunder_i2c_clock_disable(&pdev->dev, i2c->clk);
i2c_del_adapter(&i2c->adap);
+ pci_release_regions(pdev);
}
static const struct pci_device_id thunder_i2c_pci_id_table[] = {
--
2.30.2
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] i2c: thunderx: Fix some resource leak
2021-10-16 8:48 [PATCH] i2c: thunderx: Fix some resource leak Christophe JAILLET
@ 2021-10-18 21:15 ` Robert Richter
2021-10-19 17:29 ` Christophe JAILLET
0 siblings, 1 reply; 3+ messages in thread
From: Robert Richter @ 2021-10-18 21:15 UTC (permalink / raw)
To: Christophe JAILLET
Cc: jan.glauber, wsa, linux-i2c, linux-kernel, kernel-janitors
On 16.10.21 10:48:26, Christophe JAILLET wrote:
> We need to undo a 'pci_request_regions()' call in the error handling path
> of the probe function and in the remove function.
Isn't that devm and thus not needed?
>
> Fixes: 22d40209de3b ("i2c: thunderx: Add i2c driver for ThunderX SOC")
> Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
> ---
> drivers/i2c/busses/i2c-thunderx-pcidrv.c | 9 +++++++--
> 1 file changed, 7 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/i2c/busses/i2c-thunderx-pcidrv.c b/drivers/i2c/busses/i2c-thunderx-pcidrv.c
> index 12c90aa0900e..2d37096a6968 100644
> --- a/drivers/i2c/busses/i2c-thunderx-pcidrv.c
> +++ b/drivers/i2c/busses/i2c-thunderx-pcidrv.c
> @@ -177,8 +177,10 @@ static int thunder_i2c_probe_pci(struct pci_dev *pdev,
> return ret;
>
There is a pcim_enable_device() call before all that, so the regions
should be removed on device release, see pcim_release().
-Robert
> i2c->twsi_base = pcim_iomap(pdev, 0, pci_resource_len(pdev, 0));
> - if (!i2c->twsi_base)
> - return -EINVAL;
> + if (!i2c->twsi_base) {
> + ret = -EINVAL;
> + goto err_release_regions;
> + }
>
> thunder_i2c_clock_enable(dev, i2c);
> ret = device_property_read_u32(dev, "clock-frequency", &i2c->twsi_freq);
> @@ -231,6 +233,8 @@ static int thunder_i2c_probe_pci(struct pci_dev *pdev,
>
> error:
> thunder_i2c_clock_disable(dev, i2c->clk);
> +err_release_regions:
> + pci_release_regions(pdev);
> return ret;
> }
>
> @@ -241,6 +245,7 @@ static void thunder_i2c_remove_pci(struct pci_dev *pdev)
> thunder_i2c_smbus_remove(i2c);
> thunder_i2c_clock_disable(&pdev->dev, i2c->clk);
> i2c_del_adapter(&i2c->adap);
> + pci_release_regions(pdev);
> }
>
> static const struct pci_device_id thunder_i2c_pci_id_table[] = {
> --
> 2.30.2
>
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] i2c: thunderx: Fix some resource leak
2021-10-18 21:15 ` Robert Richter
@ 2021-10-19 17:29 ` Christophe JAILLET
0 siblings, 0 replies; 3+ messages in thread
From: Christophe JAILLET @ 2021-10-19 17:29 UTC (permalink / raw)
To: Robert Richter; +Cc: jan.glauber, wsa, linux-i2c, linux-kernel, kernel-janitors
Le 18/10/2021 à 23:15, Robert Richter a écrit :
> On 16.10.21 10:48:26, Christophe JAILLET wrote:
>> We need to undo a 'pci_request_regions()' call in the error handling path
>> of the probe function and in the remove function.
>
> Isn't that devm and thus not needed?
My bad, you are obviously right, sorry for the noise.
I was aware that 'pcim_enable_device()' was turning automagically
'pci_alloc_irq_vectors()' into a managed function. But I wasn't for
'pci_request_regions()'. Now I'm :)
CJ
>
>>
>> Fixes: 22d40209de3b ("i2c: thunderx: Add i2c driver for ThunderX SOC")
>> Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
>> ---
>> drivers/i2c/busses/i2c-thunderx-pcidrv.c | 9 +++++++--
>> 1 file changed, 7 insertions(+), 2 deletions(-)
>>
>> diff --git a/drivers/i2c/busses/i2c-thunderx-pcidrv.c b/drivers/i2c/busses/i2c-thunderx-pcidrv.c
>> index 12c90aa0900e..2d37096a6968 100644
>> --- a/drivers/i2c/busses/i2c-thunderx-pcidrv.c
>> +++ b/drivers/i2c/busses/i2c-thunderx-pcidrv.c
>> @@ -177,8 +177,10 @@ static int thunder_i2c_probe_pci(struct pci_dev *pdev,
>> return ret;
>>
>
> There is a pcim_enable_device() call before all that, so the regions
> should be removed on device release, see pcim_release().
>
> -Robert
>
>> i2c->twsi_base = pcim_iomap(pdev, 0, pci_resource_len(pdev, 0));
>> - if (!i2c->twsi_base)
>> - return -EINVAL;
>> + if (!i2c->twsi_base) {
>> + ret = -EINVAL;
>> + goto err_release_regions;
>> + }
>>
>> thunder_i2c_clock_enable(dev, i2c);
>> ret = device_property_read_u32(dev, "clock-frequency", &i2c->twsi_freq);
>> @@ -231,6 +233,8 @@ static int thunder_i2c_probe_pci(struct pci_dev *pdev,
>>
>> error:
>> thunder_i2c_clock_disable(dev, i2c->clk);
>> +err_release_regions:
>> + pci_release_regions(pdev);
>> return ret;
>> }
>>
>> @@ -241,6 +245,7 @@ static void thunder_i2c_remove_pci(struct pci_dev *pdev)
>> thunder_i2c_smbus_remove(i2c);
>> thunder_i2c_clock_disable(&pdev->dev, i2c->clk);
>> i2c_del_adapter(&i2c->adap);
>> + pci_release_regions(pdev);
>> }
>>
>> static const struct pci_device_id thunder_i2c_pci_id_table[] = {
>> --
>> 2.30.2
>>
>
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2021-10-19 17:29 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-10-16 8:48 [PATCH] i2c: thunderx: Fix some resource leak Christophe JAILLET
2021-10-18 21:15 ` Robert Richter
2021-10-19 17:29 ` Christophe JAILLET
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).