2020-11-02 11:22:10

by Tian Tao

[permalink] [raw]
Subject: [PATCH] drm/irq: Add irq as false detection

Add the detection of false for irq, so that the EINVAL is not
returned when dev->irq_enabled is false.

Signed-off-by: Tian Tao <[email protected]>
---
drivers/gpu/drm/drm_irq.c | 3 +++
1 file changed, 3 insertions(+)

diff --git a/drivers/gpu/drm/drm_irq.c b/drivers/gpu/drm/drm_irq.c
index 09d6e9e..7537a3d 100644
--- a/drivers/gpu/drm/drm_irq.c
+++ b/drivers/gpu/drm/drm_irq.c
@@ -172,6 +172,9 @@ int drm_irq_uninstall(struct drm_device *dev)
bool irq_enabled;
int i;

+ if (!dev->irq_enabled || !dev)
+ return 0;
+
irq_enabled = dev->irq_enabled;
dev->irq_enabled = false;

--
2.7.4


2020-11-02 12:11:52

by Thomas Zimmermann

[permalink] [raw]
Subject: Re: [PATCH] drm/irq: Add irq as false detection

Hi

Am 02.11.20 um 12:19 schrieb Tian Tao:
> Add the detection of false for irq, so that the EINVAL is not
> returned when dev->irq_enabled is false.
>
> Signed-off-by: Tian Tao <[email protected]>
> ---
> drivers/gpu/drm/drm_irq.c | 3 +++
> 1 file changed, 3 insertions(+)
>
> diff --git a/drivers/gpu/drm/drm_irq.c b/drivers/gpu/drm/drm_irq.c
> index 09d6e9e..7537a3d 100644
> --- a/drivers/gpu/drm/drm_irq.c
> +++ b/drivers/gpu/drm/drm_irq.c
> @@ -172,6 +172,9 @@ int drm_irq_uninstall(struct drm_device *dev)
> bool irq_enabled;
> int i;
>
> + if (!dev->irq_enabled || !dev)
> + return 0;
> +

Dereferencing a pointer before NULL-checking it, is Yoda programming. :)
I'd just drop the test for !dev and assume that dev is always valid.

I suggest to change the int return value to void and return nothing.

Re-reading the actual implementation of this function, this location
might be too early. Further below there already is a test for
irq_enabled. Put a drm_WARN_ON around it and it should be fine. This way
the vblank handlers will be disabled and erroneous callers will see a
warning in the kernel's log.

Best regards
Thomas

> irq_enabled = dev->irq_enabled;
> dev->irq_enabled = false;
>
>

--
Thomas Zimmermann
Graphics Driver Developer
SUSE Software Solutions Germany GmbH
Maxfeldstr. 5, 90409 Nürnberg, Germany
(HRB 36809, AG Nürnberg)
Geschäftsführer: Felix Imendörffer


Attachments:
OpenPGP_0x680DC11D530B7A23.asc (4.16 kB)
OpenPGP_signature (505.00 B)
OpenPGP digital signature
Download all attachments

2020-11-02 12:35:05

by tiantao (H)

[permalink] [raw]
Subject: Re: [PATCH] drm/irq: Add irq as false detection



在 2020/11/2 20:09, Thomas Zimmermann 写道:
> Hi
>
> Am 02.11.20 um 12:19 schrieb Tian Tao:
>> Add the detection of false for irq, so that the EINVAL is not
>> returned when dev->irq_enabled is false.
>>
>> Signed-off-by: Tian Tao <[email protected]>
>> ---
>> drivers/gpu/drm/drm_irq.c | 3 +++
>> 1 file changed, 3 insertions(+)
>>
>> diff --git a/drivers/gpu/drm/drm_irq.c b/drivers/gpu/drm/drm_irq.c
>> index 09d6e9e..7537a3d 100644
>> --- a/drivers/gpu/drm/drm_irq.c
>> +++ b/drivers/gpu/drm/drm_irq.c
>> @@ -172,6 +172,9 @@ int drm_irq_uninstall(struct drm_device *dev)
>> bool irq_enabled;
>> int i;
>>
>> + if (!dev->irq_enabled || !dev)
>> + return 0;
>> +
>
> Dereferencing a pointer before NULL-checking it, is Yoda programming. :)
> I'd just drop the test for !dev and assume that dev is always valid.
>
> I suggest to change the int return value to void and return nothing.
>
> Re-reading the actual implementation of this function, this location
> might be too early. Further below there already is a test for
> irq_enabled. Put a drm_WARN_ON around it and it should be fine. This way
> the vblank handlers will be disabled and erroneous callers will see a
> warning in the kernel's log.
>
thank you,I will send a new patch to fix that.
> Best regards
> Thomas
>
>> irq_enabled = dev->irq_enabled;
>> dev->irq_enabled = false;
>>
>>
>

2020-11-02 12:42:05

by Thomas Zimmermann

[permalink] [raw]
Subject: Re: [PATCH] drm/irq: Add irq as false detection

Hi

Am 02.11.20 um 13:09 schrieb Thomas Zimmermann:
> Hi
>
> Am 02.11.20 um 12:19 schrieb Tian Tao:
>> Add the detection of false for irq, so that the EINVAL is not
>> returned when dev->irq_enabled is false.
>>
>> Signed-off-by: Tian Tao <[email protected]>
>> ---
>> drivers/gpu/drm/drm_irq.c | 3 +++
>> 1 file changed, 3 insertions(+)
>>
>> diff --git a/drivers/gpu/drm/drm_irq.c b/drivers/gpu/drm/drm_irq.c
>> index 09d6e9e..7537a3d 100644
>> --- a/drivers/gpu/drm/drm_irq.c
>> +++ b/drivers/gpu/drm/drm_irq.c
>> @@ -172,6 +172,9 @@ int drm_irq_uninstall(struct drm_device *dev)
>> bool irq_enabled;
>> int i;
>>
>> + if (!dev->irq_enabled || !dev)
>> + return 0;
>> +
>
> Dereferencing a pointer before NULL-checking it, is Yoda programming. :)
> I'd just drop the test for !dev and assume that dev is always valid.
>
> I suggest to change the int return value to void and return nothing.
>
> Re-reading the actual implementation of this function, this location
> might be too early. Further below there already is a test for
> irq_enabled. Put a drm_WARN_ON around it and it should be fine. This way
> the vblank handlers will be disabled and erroneous callers will see a
> warning in the kernel's log.

In addition to these changes, you could also add a managed
implementation of drm_irq_install(). The canonical name should be
devm_drm_irq_install(). The function would call drm_irq_install() and
register a cleanup handler via devm_add_action(). Example code is at [1].

KMS drivers, such as hibmc, would then not have to bother about
uninstalling the DRM irq.

Best regards
Thomas

[1]
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/drivers/gpu/drm/drm_drv.c#n664


>
> Best regards
> Thomas
>
>> irq_enabled = dev->irq_enabled;
>> dev->irq_enabled = false;
>>
>>
>
>
> _______________________________________________
> dri-devel mailing list
> [email protected]
> https://lists.freedesktop.org/mailman/listinfo/dri-devel
>

--
Thomas Zimmermann
Graphics Driver Developer
SUSE Software Solutions Germany GmbH
Maxfeldstr. 5, 90409 Nürnberg, Germany
(HRB 36809, AG Nürnberg)
Geschäftsführer: Felix Imendörffer


Attachments:
OpenPGP_0x680DC11D530B7A23.asc (4.16 kB)
OpenPGP_signature (505.00 B)
OpenPGP digital signature
Download all attachments

2020-11-02 12:55:50

by Daniel Vetter

[permalink] [raw]
Subject: Re: [PATCH] drm/irq: Add irq as false detection

On Mon, Nov 2, 2020 at 1:40 PM Thomas Zimmermann <[email protected]> wrote:
>
> Hi
>
> Am 02.11.20 um 13:09 schrieb Thomas Zimmermann:
> > Hi
> >
> > Am 02.11.20 um 12:19 schrieb Tian Tao:
> >> Add the detection of false for irq, so that the EINVAL is not
> >> returned when dev->irq_enabled is false.
> >>
> >> Signed-off-by: Tian Tao <[email protected]>
> >> ---
> >> drivers/gpu/drm/drm_irq.c | 3 +++
> >> 1 file changed, 3 insertions(+)
> >>
> >> diff --git a/drivers/gpu/drm/drm_irq.c b/drivers/gpu/drm/drm_irq.c
> >> index 09d6e9e..7537a3d 100644
> >> --- a/drivers/gpu/drm/drm_irq.c
> >> +++ b/drivers/gpu/drm/drm_irq.c
> >> @@ -172,6 +172,9 @@ int drm_irq_uninstall(struct drm_device *dev)
> >> bool irq_enabled;
> >> int i;
> >>
> >> + if (!dev->irq_enabled || !dev)
> >> + return 0;
> >> +
> >
> > Dereferencing a pointer before NULL-checking it, is Yoda programming. :)
> > I'd just drop the test for !dev and assume that dev is always valid.
> >
> > I suggest to change the int return value to void and return nothing.
> >
> > Re-reading the actual implementation of this function, this location
> > might be too early. Further below there already is a test for
> > irq_enabled. Put a drm_WARN_ON around it and it should be fine. This way
> > the vblank handlers will be disabled and erroneous callers will see a
> > warning in the kernel's log.
>
> In addition to these changes, you could also add a managed
> implementation of drm_irq_install(). The canonical name should be
> devm_drm_irq_install(). The function would call drm_irq_install() and
> register a cleanup handler via devm_add_action(). Example code is at [1].
>
> KMS drivers, such as hibmc, would then not have to bother about
> uninstalling the DRM irq.

Yup, devm_ is the right fix here imo, not trying to make the uninstall
hook resilient against drivers which can't keep track of stuff. So if
that's all there is, imo this patch is a bad idea, since we have
proper tools to make driver unloading easier on driver author's
nowadays.
-Daniel

> Best regards
> Thomas
>
> [1]
> https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/drivers/gpu/drm/drm_drv.c#n664
>
>
> >
> > Best regards
> > Thomas
> >
> >> irq_enabled = dev->irq_enabled;
> >> dev->irq_enabled = false;
> >>
> >>
> >
> >
> > _______________________________________________
> > dri-devel mailing list
> > [email protected]
> > https://lists.freedesktop.org/mailman/listinfo/dri-devel
> >
>
> --
> Thomas Zimmermann
> Graphics Driver Developer
> SUSE Software Solutions Germany GmbH
> Maxfeldstr. 5, 90409 Nürnberg, Germany
> (HRB 36809, AG Nürnberg)
> Geschäftsführer: Felix Imendörffer



--
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch

2020-11-02 18:35:58

by Dan Carpenter

[permalink] [raw]
Subject: [kbuild] Re: [PATCH] drm/irq: Add irq as false detection

_______________________________________________
kbuild mailing list -- [email protected]
To unsubscribe send an email to [email protected]


Attachments:
(No filename) (2.40 kB)
.config.gz (29.98 kB)
(No filename) (152.00 B)
Download all attachments