2014-07-25 17:07:28

by Ian Abbott

[permalink] [raw]
Subject: [PATCH 0/3] staging: comedi: amplc_dio200 detach cleanups

Fix a double free_irq() and do a bit more cleaning up of the "detach"
routines.

1) staging: comedi: amplc_dio200_common: prevent extra free_irq()
2) staging: comedi: amplc_dio200_common: remove some tests from
amplc_dio200_common_detach()
3) staging: comedi: amplc_dio200_pci: no need to test board pointer in
dio200_pci_detach()

drivers/staging/comedi/drivers/amplc_dio200_common.c | 9 +++------
drivers/staging/comedi/drivers/amplc_dio200_pci.c | 5 +----
2 files changed, 4 insertions(+), 10 deletions(-)


2014-07-25 17:07:30

by Ian Abbott

[permalink] [raw]
Subject: [PATCH 3/3] staging: comedi: amplc_dio200_pci: no need to test board pointer in dio200_pci_detach()

`dio200_pci_detach()` doesn't need to check if the pointer to constant
board data (`thisboard`) and the pointer to private per-device data
(`devpriv`) are valid before calling `amplc_dio200_common_detach()`. It
has no further need to check `thisboard` so remove the variable
altogether. Move the test of `devpriv` to the first point it is needs
to be valid.

Signed-off-by: Ian Abbott <[email protected]>
---
drivers/staging/comedi/drivers/amplc_dio200_pci.c | 5 +----
1 file changed, 1 insertion(+), 4 deletions(-)

diff --git a/drivers/staging/comedi/drivers/amplc_dio200_pci.c b/drivers/staging/comedi/drivers/amplc_dio200_pci.c
index 3cec0e0..1954c1b 100644
--- a/drivers/staging/comedi/drivers/amplc_dio200_pci.c
+++ b/drivers/staging/comedi/drivers/amplc_dio200_pci.c
@@ -414,13 +414,10 @@ static int dio200_pci_auto_attach(struct comedi_device *dev,

static void dio200_pci_detach(struct comedi_device *dev)
{
- const struct dio200_board *thisboard = comedi_board(dev);
struct dio200_private *devpriv = dev->private;

- if (!thisboard || !devpriv)
- return;
amplc_dio200_common_detach(dev);
- if (devpriv->io.regtype == mmio_regtype)
+ if (devpriv && devpriv->io.regtype == mmio_regtype)
iounmap(devpriv->io.u.membase);
comedi_pci_disable(dev);
}
--
2.0.0

2014-07-25 17:07:29

by Ian Abbott

[permalink] [raw]
Subject: [PATCH 2/3] staging: comedi: amplc_dio200_common: remove some tests from amplc_dio200_common_detach()

`amplc_dio200_common_detach()` doesn't do much apart from freeing the
IRQ handler that was requested by `amplc_dio200_common_attach()` if
`dev->irq` is non-zero. There is no need to check if the pointer to
the constant board data or the pointer to private per-device data
exist, so remove those tests.

Signed-off-by: Ian Abbott <[email protected]>
---
drivers/staging/comedi/drivers/amplc_dio200_common.c | 5 -----
1 file changed, 5 deletions(-)

diff --git a/drivers/staging/comedi/drivers/amplc_dio200_common.c b/drivers/staging/comedi/drivers/amplc_dio200_common.c
index 3592e58..4cf9e9e 100644
--- a/drivers/staging/comedi/drivers/amplc_dio200_common.c
+++ b/drivers/staging/comedi/drivers/amplc_dio200_common.c
@@ -1197,11 +1197,6 @@ EXPORT_SYMBOL_GPL(amplc_dio200_common_attach);

void amplc_dio200_common_detach(struct comedi_device *dev)
{
- const struct dio200_board *thisboard = comedi_board(dev);
- struct dio200_private *devpriv = dev->private;
-
- if (!thisboard || !devpriv)
- return;
if (dev->irq) {
free_irq(dev->irq, dev);
dev->irq = 0;
--
2.0.0

2014-07-25 17:07:27

by Ian Abbott

[permalink] [raw]
Subject: [PATCH 1/3] staging: comedi: amplc_dio200_common: prevent extra free_irq()

`dio200_detach()` in "amplc_dio200.c" calls
`amplc_dio200_common_detach()` in "amplc_dio200_common.c", followed by
`comedi_legacy_detach()` in "../drivers.c". Both of those functions
call `free_irq()` if `dev->irq` is non-zero. The second call produces a
warning message because the handler has already been freed. Prevent
that by setting `dev->irq = 0` in `amplc_dio200_common_detach()`.

Signed-off-by: Ian Abbott <[email protected]>
---
drivers/staging/comedi/drivers/amplc_dio200_common.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/staging/comedi/drivers/amplc_dio200_common.c b/drivers/staging/comedi/drivers/amplc_dio200_common.c
index 78700e8..3592e58 100644
--- a/drivers/staging/comedi/drivers/amplc_dio200_common.c
+++ b/drivers/staging/comedi/drivers/amplc_dio200_common.c
@@ -1202,8 +1202,10 @@ void amplc_dio200_common_detach(struct comedi_device *dev)

if (!thisboard || !devpriv)
return;
- if (dev->irq)
+ if (dev->irq) {
free_irq(dev->irq, dev);
+ dev->irq = 0;
+ }
}
EXPORT_SYMBOL_GPL(amplc_dio200_common_detach);

--
2.0.0

2014-07-25 18:14:47

by Hartley Sweeten

[permalink] [raw]
Subject: RE: [PATCH 0/3] staging: comedi: amplc_dio200 detach cleanups

On Friday, July 25, 2014 10:07 AM, Ian Abbott wrote:
> Fix a double free_irq() and do a bit more cleaning up of the "detach"
> routines.
>
> 1) staging: comedi: amplc_dio200_common: prevent extra free_irq()
> 2) staging: comedi: amplc_dio200_common: remove some tests from
> amplc_dio200_common_detach()
> 3) staging: comedi: amplc_dio200_pci: no need to test board pointer in
> dio200_pci_detach()
>
> drivers/staging/comedi/drivers/amplc_dio200_common.c | 9 +++------
> drivers/staging/comedi/drivers/amplc_dio200_pci.c | 5 +----
> 2 files changed, 4 insertions(+), 10 deletions(-)

Reviewed-by: H Hartley Sweeten <[email protected]>

2014-07-25 18:23:12

by Hartley Sweeten

[permalink] [raw]
Subject: RE: [PATCH 1/3] staging: comedi: amplc_dio200_common: prevent extra free_irq()

On Friday, July 25, 2014 10:07 AM, Ian Abbott wrote:
> `dio200_detach()` in "amplc_dio200.c" calls
> `amplc_dio200_common_detach()` in "amplc_dio200_common.c", followed by
> `comedi_legacy_detach()` in "../drivers.c". Both of those functions
> call `free_irq()` if `dev->irq` is non-zero. The second call produces a
> warning message because the handler has already been freed. Prevent
> that by setting `dev->irq = 0` in `amplc_dio200_common_detach()`.
>
> Signed-off-by: Ian Abbott <[email protected]>
> ---
> drivers/staging/comedi/drivers/amplc_dio200_common.c | 4 +++-
> 1 file changed, 3 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/staging/comedi/drivers/amplc_dio200_common.c b/drivers/staging/comedi/drivers/amplc_dio200_common.c
> index 78700e8..3592e58 100644
> --- a/drivers/staging/comedi/drivers/amplc_dio200_common.c
> +++ b/drivers/staging/comedi/drivers/amplc_dio200_common.c
> @@ -1202,8 +1202,10 @@ void amplc_dio200_common_detach(struct comedi_device *dev)
>
> if (!thisboard || !devpriv)
> return;
> - if (dev->irq)
> + if (dev->irq) {
> free_irq(dev->irq, dev);
> + dev->irq = 0;
> + }
> }
> EXPORT_SYMBOL_GPL(amplc_dio200_common_detach);

Ian,

I have already gave a Reviewed-by signoff for this series.

After looking over the code I think a cleaner solution would be to:

1) Use comedi_legacy_detach() directly for the (*detach) in the
legacy ISA driver.
2) Move the code from amplc_dio200_common_detach() into the
(*detach) function for the PCI driver.
3) Remove the exported function amplc_dio200_common_detach().

Regards,
Hartley

2014-07-27 18:45:15

by Greg Kroah-Hartman

[permalink] [raw]
Subject: Re: [PATCH 1/3] staging: comedi: amplc_dio200_common: prevent extra free_irq()

On Fri, Jul 25, 2014 at 06:23:10PM +0000, Hartley Sweeten wrote:
> On Friday, July 25, 2014 10:07 AM, Ian Abbott wrote:
> > `dio200_detach()` in "amplc_dio200.c" calls
> > `amplc_dio200_common_detach()` in "amplc_dio200_common.c", followed by
> > `comedi_legacy_detach()` in "../drivers.c". Both of those functions
> > call `free_irq()` if `dev->irq` is non-zero. The second call produces a
> > warning message because the handler has already been freed. Prevent
> > that by setting `dev->irq = 0` in `amplc_dio200_common_detach()`.
> >
> > Signed-off-by: Ian Abbott <[email protected]>
> > ---
> > drivers/staging/comedi/drivers/amplc_dio200_common.c | 4 +++-
> > 1 file changed, 3 insertions(+), 1 deletion(-)
> >
> > diff --git a/drivers/staging/comedi/drivers/amplc_dio200_common.c b/drivers/staging/comedi/drivers/amplc_dio200_common.c
> > index 78700e8..3592e58 100644
> > --- a/drivers/staging/comedi/drivers/amplc_dio200_common.c
> > +++ b/drivers/staging/comedi/drivers/amplc_dio200_common.c
> > @@ -1202,8 +1202,10 @@ void amplc_dio200_common_detach(struct comedi_device *dev)
> >
> > if (!thisboard || !devpriv)
> > return;
> > - if (dev->irq)
> > + if (dev->irq) {
> > free_irq(dev->irq, dev);
> > + dev->irq = 0;
> > + }
> > }
> > EXPORT_SYMBOL_GPL(amplc_dio200_common_detach);
>
> Ian,
>
> I have already gave a Reviewed-by signoff for this series.
>
> After looking over the code I think a cleaner solution would be to:
>
> 1) Use comedi_legacy_detach() directly for the (*detach) in the
> legacy ISA driver.
> 2) Move the code from amplc_dio200_common_detach() into the
> (*detach) function for the PCI driver.
> 3) Remove the exported function amplc_dio200_common_detach().

So should I not apply these patches?

confused,

greg k-h

2014-07-28 09:27:46

by Ian Abbott

[permalink] [raw]
Subject: Re: [PATCH 1/3] staging: comedi: amplc_dio200_common: prevent extra free_irq()

On 2014-07-27 19:45, Greg Kroah-Hartman wrote:
> On Fri, Jul 25, 2014 at 06:23:10PM +0000, Hartley Sweeten wrote:
>> On Friday, July 25, 2014 10:07 AM, Ian Abbott wrote:
>>> `dio200_detach()` in "amplc_dio200.c" calls
>>> `amplc_dio200_common_detach()` in "amplc_dio200_common.c", followed by
>>> `comedi_legacy_detach()` in "../drivers.c". Both of those functions
>>> call `free_irq()` if `dev->irq` is non-zero. The second call produces a
>>> warning message because the handler has already been freed. Prevent
>>> that by setting `dev->irq = 0` in `amplc_dio200_common_detach()`.
>>>
>>> Signed-off-by: Ian Abbott <[email protected]>
>>> ---
>>> drivers/staging/comedi/drivers/amplc_dio200_common.c | 4 +++-
>>> 1 file changed, 3 insertions(+), 1 deletion(-)
>>>
>>> diff --git a/drivers/staging/comedi/drivers/amplc_dio200_common.c b/drivers/staging/comedi/drivers/amplc_dio200_common.c
>>> index 78700e8..3592e58 100644
>>> --- a/drivers/staging/comedi/drivers/amplc_dio200_common.c
>>> +++ b/drivers/staging/comedi/drivers/amplc_dio200_common.c
>>> @@ -1202,8 +1202,10 @@ void amplc_dio200_common_detach(struct comedi_device *dev)
>>>
>>> if (!thisboard || !devpriv)
>>> return;
>>> - if (dev->irq)
>>> + if (dev->irq) {
>>> free_irq(dev->irq, dev);
>>> + dev->irq = 0;
>>> + }
>>> }
>>> EXPORT_SYMBOL_GPL(amplc_dio200_common_detach);
>>
>> Ian,
>>
>> I have already gave a Reviewed-by signoff for this series.
>>
>> After looking over the code I think a cleaner solution would be to:
>>
>> 1) Use comedi_legacy_detach() directly for the (*detach) in the
>> legacy ISA driver.
>> 2) Move the code from amplc_dio200_common_detach() into the
>> (*detach) function for the PCI driver.
>> 3) Remove the exported function amplc_dio200_common_detach().
>
> So should I not apply these patches?
>
> confused,
>
> greg k-h

It fixes a bug (harmless, apart from a kernel warning), and does no
harm, so might as well apply them. Hartley's suggestion can be done later.

--
-=( Ian Abbott @ MEV Ltd. E-mail: <[email protected]> )=-
-=( Tel: +44 (0)161 477 1898 FAX: +44 (0)161 718 3587 )=-

2014-07-28 16:35:05

by Hartley Sweeten

[permalink] [raw]
Subject: RE: [PATCH 1/3] staging: comedi: amplc_dio200_common: prevent extra free_irq()

On Sunday, July 27, 2014 11:45 AM, Greg Kroah-Hartman wrote:
> On Fri, Jul 25, 2014 at 06:23:10PM +0000, Hartley Sweeten wrote:
>> On Friday, July 25, 2014 10:07 AM, Ian Abbott wrote:
>>> `dio200_detach()` in "amplc_dio200.c" calls
>>> `amplc_dio200_common_detach()` in "amplc_dio200_common.c", followed by
>>> `comedi_legacy_detach()` in "../drivers.c". Both of those functions
>>> call `free_irq()` if `dev->irq` is non-zero. The second call produces a
>>> warning message because the handler has already been freed. Prevent
>>> that by setting `dev->irq = 0` in `amplc_dio200_common_detach()`.
>>>
>>> Signed-off-by: Ian Abbott <[email protected]>
>>>
>> I have already gave a Reviewed-by signoff for this series.
>>
>> After looking over the code I think a cleaner solution would be to:
>>
>> 1) Use comedi_legacy_detach() directly for the (*detach) in the
>> legacy ISA driver.
>> 2) Move the code from amplc_dio200_common_detach() into the
>> (*detach) function for the PCI driver.
>> 3) Remove the exported function amplc_dio200_common_detach().
>
> So should I not apply these patches?

Greg,

Yes, please apply this series from Ian. It does fix a bug with the
duplicate free_irq().

The comments I gave can be addressed in a later patch.

Sorry for the confusion.
Hartley