diff mbox series

[4/4] vgaswitcheroo: do not check for NULL debugfs dentry

Message ID 20211011190607.104618-4-nirmoy.das@amd.com (mailing list archive)
State New, archived
Headers show
Series [1/4] dri: do not check for NULL debugfs dentry | expand

Commit Message

Das, Nirmoy Oct. 11, 2021, 7:06 p.m. UTC
Debugfs APIs returns encoded error on failure so use
debugfs_lookup() instead of checking for NULL.

CC: Lukas Wunner <lukas@wunner.de>
CC: David Airlie <airlied@linux.ie>
CC: Daniel Vetter <daniel@ffwll.ch>
CC: Maarten Lankhorst <maarten.lankhorst@linux.intel.com>
CC: Maxime Ripard <mripard@kernel.org>
CC: Thomas Zimmermann <tzimmermann@suse.de>

Signed-off-by: Nirmoy Das <nirmoy.das@amd.com>
---
 drivers/gpu/vga/vga_switcheroo.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

--
2.32.0

Comments

Lukas Wunner Oct. 11, 2021, 8:24 p.m. UTC | #1
On Mon, Oct 11, 2021 at 09:06:07PM +0200, Nirmoy Das wrote:
> Debugfs APIs returns encoded error on failure so use
> debugfs_lookup() instead of checking for NULL.
[...]
> --- a/drivers/gpu/vga/vga_switcheroo.c
> +++ b/drivers/gpu/vga/vga_switcheroo.c
> @@ -914,7 +914,7 @@ static void vga_switcheroo_debugfs_fini(struct vgasr_priv *priv)
>  static void vga_switcheroo_debugfs_init(struct vgasr_priv *priv)
>  {
>  	/* already initialised */
> -	if (priv->debugfs_root)
> +	if (debugfs_lookup("vgaswitcheroo", NULL))
>  		return;
> 
>  	priv->debugfs_root = debugfs_create_dir("vgaswitcheroo", NULL);

If debugfs_create_dir() returns an error code, it does make sense to
retry the call when another vga_switcheroo client registers later.
I like that.

However I'd prefer simply changing this to explicitly check for NULL, i.e.:

-	if (priv->debugfs_root)
+	if (priv->debugfs_root == NULL)

It's just as clear as calling debugfs_lookup() and it has way less
overhead.  Granted, this isn't a hot path, but it's called on boot,
and the less code we execute, the faster the machine boots.

Thanks,

Lukas
Lukas Wunner Oct. 12, 2021, 6:48 a.m. UTC | #2
On Mon, Oct 11, 2021 at 10:24:29PM +0200, Lukas Wunner wrote:
> On Mon, Oct 11, 2021 at 09:06:07PM +0200, Nirmoy Das wrote:
> > Debugfs APIs returns encoded error on failure so use
> > debugfs_lookup() instead of checking for NULL.
> [...]
> > --- a/drivers/gpu/vga/vga_switcheroo.c
> > +++ b/drivers/gpu/vga/vga_switcheroo.c
> > @@ -914,7 +914,7 @@ static void vga_switcheroo_debugfs_fini(struct vgasr_priv *priv)
> >  static void vga_switcheroo_debugfs_init(struct vgasr_priv *priv)
> >  {
> >  	/* already initialised */
> > -	if (priv->debugfs_root)
> > +	if (debugfs_lookup("vgaswitcheroo", NULL))
> >  		return;
> > 
> >  	priv->debugfs_root = debugfs_create_dir("vgaswitcheroo", NULL);
> 
> If debugfs_create_dir() returns an error code, it does make sense to
> retry the call when another vga_switcheroo client registers later.
> I like that.
> 
> However I'd prefer simply changing this to explicitly check for NULL, i.e.:
> 
> -	if (priv->debugfs_root)
> +	if (priv->debugfs_root == NULL)

Apologies, I meant:

-	if (priv->debugfs_root)
+	if (priv->debugfs_root && !IS_ERR(priv->debugfs_root))

Thanks,

Lukas

> It's just as clear as calling debugfs_lookup() and it has way less
> overhead.  Granted, this isn't a hot path, but it's called on boot,
> and the less code we execute, the faster the machine boots.
Das, Nirmoy Oct. 12, 2021, 8:57 a.m. UTC | #3
On 10/12/2021 8:48 AM, Lukas Wunner wrote:
> On Mon, Oct 11, 2021 at 10:24:29PM +0200, Lukas Wunner wrote:
>> On Mon, Oct 11, 2021 at 09:06:07PM +0200, Nirmoy Das wrote:
>>> Debugfs APIs returns encoded error on failure so use
>>> debugfs_lookup() instead of checking for NULL.
>> [...]
>>> --- a/drivers/gpu/vga/vga_switcheroo.c
>>> +++ b/drivers/gpu/vga/vga_switcheroo.c
>>> @@ -914,7 +914,7 @@ static void vga_switcheroo_debugfs_fini(struct vgasr_priv *priv)
>>>   static void vga_switcheroo_debugfs_init(struct vgasr_priv *priv)
>>>   {
>>>   	/* already initialised */
>>> -	if (priv->debugfs_root)
>>> +	if (debugfs_lookup("vgaswitcheroo", NULL))
>>>   		return;
>>>
>>>   	priv->debugfs_root = debugfs_create_dir("vgaswitcheroo", NULL);
>> If debugfs_create_dir() returns an error code, it does make sense to
>> retry the call when another vga_switcheroo client registers later.
>> I like that.
>>
>> However I'd prefer simply changing this to explicitly check for NULL, i.e.:
>>
>> -	if (priv->debugfs_root)
>> +	if (priv->debugfs_root == NULL)
> Apologies, I meant:
>
> -	if (priv->debugfs_root)
> +	if (priv->debugfs_root && !IS_ERR(priv->debugfs_root))


Thanks for the suggestion, Lukas. I will update that and resend.


Nirmoy


> Thanks,
>
> Lukas
>
>> It's just as clear as calling debugfs_lookup() and it has way less
>> overhead.  Granted, this isn't a hot path, but it's called on boot,
>> and the less code we execute, the faster the machine boots.
diff mbox series

Patch

diff --git a/drivers/gpu/vga/vga_switcheroo.c b/drivers/gpu/vga/vga_switcheroo.c
index 365e6ddbe90f..a331525f0b32 100644
--- a/drivers/gpu/vga/vga_switcheroo.c
+++ b/drivers/gpu/vga/vga_switcheroo.c
@@ -914,7 +914,7 @@  static void vga_switcheroo_debugfs_fini(struct vgasr_priv *priv)
 static void vga_switcheroo_debugfs_init(struct vgasr_priv *priv)
 {
 	/* already initialised */
-	if (priv->debugfs_root)
+	if (debugfs_lookup("vgaswitcheroo", NULL))
 		return;

 	priv->debugfs_root = debugfs_create_dir("vgaswitcheroo", NULL);