diff mbox series

drm/i915/dp: Fix memory leak in parse_lfp_panel_dtd()

Message ID 20241010155552.994880-1-shuicheng.lin@intel.com (mailing list archive)
State New, archived
Headers show
Series drm/i915/dp: Fix memory leak in parse_lfp_panel_dtd() | expand

Commit Message

Shuicheng Lin Oct. 10, 2024, 3:55 p.m. UTC
The function parse_lfp_panel_dtd() is called when the driver
attempts to initialize the eDP connector, and it allocates memory,
which is recorded in panel->vbt.lfp_vbt_mode. However, since no
eDP panel is connected, the driver fails at intel_edp_init_dpcd()
and follows the failure path. Unfortunately, the allocated memory
is not freed in this case.

To fix this issue, free the memory in the failure path.

leak info from kmemleak:
"
unreferenced object 0xffff8881252f8800 (size 128):
  comm "systemd-udevd", pid 192, jiffies 4294896880
  hex dump (first 32 bytes):
    e8 fd 00 00 00 04 18 04 a0 04 40 05 00 00 00 03  ..........@.....
    03 03 09 03 26 03 00 00 0a 00 00 00 00 00 00 00  ....&...........
  backtrace (crc 7448f6b4):
    [<ffffffff82475c9b>] kmemleak_alloc+0x4b/0x80
    [<ffffffff814bb50e>] __kmalloc_cache_noprof+0x2be/0x390
    [<ffffffffa069862c>] intel_bios_init_panel+0x1c4c/0x2720 [xe]
    [<ffffffffa0699123>] intel_bios_init_panel_early+0x13/0x20 [xe]
    [<ffffffffa06fceb9>] intel_dp_init_connector+0x2f9/0x1080 [xe]
    [<ffffffffa06c370a>] intel_ddi_init+0xbba/0xf50 [xe]
    [<ffffffffa069b906>] intel_bios_for_each_encoder+0x36/0x60 [xe]
    [<ffffffffa06d7bd6>] intel_setup_outputs+0x206/0x450 [xe]
    [<ffffffffa06dad33>] intel_display_driver_probe_nogem+0x163/0x1f0 [xe]
    [<ffffffffa0680fc7>] xe_display_init_noaccel+0x27/0x70 [xe]
    [<ffffffffa05b30d6>] xe_device_probe+0x806/0x9a0 [xe]
    [<ffffffffa0612f0f>] xe_pci_probe+0x31f/0x590 [xe]
    [<ffffffff81b41718>] local_pci_probe+0x48/0xb0
    [<ffffffff81b432c8>] pci_device_probe+0xc8/0x280
    [<ffffffff81d5dde8>] really_probe+0xf8/0x390
    [<ffffffff81d5e11a>] __driver_probe_device+0x8a/0x170
"

Signed-off-by: Shuicheng Lin <shuicheng.lin@intel.com>
Cc: Jani Nikula <jani.nikula@intel.com>
---
 drivers/gpu/drm/i915/display/intel_dp.c | 1 +
 1 file changed, 1 insertion(+)

Comments

Jani Nikula Oct. 11, 2024, 8:27 a.m. UTC | #1
On Thu, 10 Oct 2024, Shuicheng Lin <shuicheng.lin@intel.com> wrote:
> The function parse_lfp_panel_dtd() is called when the driver
> attempts to initialize the eDP connector, and it allocates memory,
> which is recorded in panel->vbt.lfp_vbt_mode. However, since no
> eDP panel is connected, the driver fails at intel_edp_init_dpcd()
> and follows the failure path. Unfortunately, the allocated memory
> is not freed in this case.
>
> To fix this issue, free the memory in the failure path.
>
> leak info from kmemleak:
> "
> unreferenced object 0xffff8881252f8800 (size 128):
>   comm "systemd-udevd", pid 192, jiffies 4294896880
>   hex dump (first 32 bytes):
>     e8 fd 00 00 00 04 18 04 a0 04 40 05 00 00 00 03  ..........@.....
>     03 03 09 03 26 03 00 00 0a 00 00 00 00 00 00 00  ....&...........
>   backtrace (crc 7448f6b4):
>     [<ffffffff82475c9b>] kmemleak_alloc+0x4b/0x80
>     [<ffffffff814bb50e>] __kmalloc_cache_noprof+0x2be/0x390
>     [<ffffffffa069862c>] intel_bios_init_panel+0x1c4c/0x2720 [xe]
>     [<ffffffffa0699123>] intel_bios_init_panel_early+0x13/0x20 [xe]
>     [<ffffffffa06fceb9>] intel_dp_init_connector+0x2f9/0x1080 [xe]
>     [<ffffffffa06c370a>] intel_ddi_init+0xbba/0xf50 [xe]
>     [<ffffffffa069b906>] intel_bios_for_each_encoder+0x36/0x60 [xe]
>     [<ffffffffa06d7bd6>] intel_setup_outputs+0x206/0x450 [xe]
>     [<ffffffffa06dad33>] intel_display_driver_probe_nogem+0x163/0x1f0 [xe]
>     [<ffffffffa0680fc7>] xe_display_init_noaccel+0x27/0x70 [xe]
>     [<ffffffffa05b30d6>] xe_device_probe+0x806/0x9a0 [xe]
>     [<ffffffffa0612f0f>] xe_pci_probe+0x31f/0x590 [xe]
>     [<ffffffff81b41718>] local_pci_probe+0x48/0xb0
>     [<ffffffff81b432c8>] pci_device_probe+0xc8/0x280
>     [<ffffffff81d5dde8>] really_probe+0xf8/0x390
>     [<ffffffff81d5e11a>] __driver_probe_device+0x8a/0x170
> "
>
> Signed-off-by: Shuicheng Lin <shuicheng.lin@intel.com>
> Cc: Jani Nikula <jani.nikula@intel.com>

For future reference, the commit message and subject should indicate
this is v2, and what the changes were. See submitting-patches.rst.

No need to resend for this.

BR,
Jani.


> ---
>  drivers/gpu/drm/i915/display/intel_dp.c | 1 +
>  1 file changed, 1 insertion(+)
>
> diff --git a/drivers/gpu/drm/i915/display/intel_dp.c b/drivers/gpu/drm/i915/display/intel_dp.c
> index 90fa73575feb..7141e3ca0d83 100644
> --- a/drivers/gpu/drm/i915/display/intel_dp.c
> +++ b/drivers/gpu/drm/i915/display/intel_dp.c
> @@ -6801,6 +6801,7 @@ static bool intel_edp_init_connector(struct intel_dp *intel_dp,
>  
>  out_vdd_off:
>  	intel_pps_vdd_off_sync(intel_dp);
> +	intel_bios_fini_panel(&intel_connector->panel);
>  
>  	return false;
>  }
Shuicheng Lin Oct. 11, 2024, 8:57 p.m. UTC | #2
> -----Original Message-----
> From: Nikula, Jani <jani.nikula@intel.com>
> Sent: Friday, October 11, 2024 1:28 AM
> To: Lin, Shuicheng <shuicheng.lin@intel.com>; intel-xe@lists.freedesktop.org;
> intel-gfx@lists.freedesktop.org
> Cc: Lin, Shuicheng <shuicheng.lin@intel.com>
> Subject: Re: [PATCH] drm/i915/dp: Fix memory leak in parse_lfp_panel_dtd()
> 
> On Thu, 10 Oct 2024, Shuicheng Lin <shuicheng.lin@intel.com> wrote:
> > The function parse_lfp_panel_dtd() is called when the driver attempts
> > to initialize the eDP connector, and it allocates memory, which is
> > recorded in panel->vbt.lfp_vbt_mode. However, since no eDP panel is
> > connected, the driver fails at intel_edp_init_dpcd() and follows the
> > failure path. Unfortunately, the allocated memory is not freed in this
> > case.
> >
> > To fix this issue, free the memory in the failure path.
> >
> > leak info from kmemleak:
> > "
> > unreferenced object 0xffff8881252f8800 (size 128):
> >   comm "systemd-udevd", pid 192, jiffies 4294896880
> >   hex dump (first 32 bytes):
> >     e8 fd 00 00 00 04 18 04 a0 04 40 05 00 00 00 03  ..........@.....
> >     03 03 09 03 26 03 00 00 0a 00 00 00 00 00 00 00  ....&...........
> >   backtrace (crc 7448f6b4):
> >     [<ffffffff82475c9b>] kmemleak_alloc+0x4b/0x80
> >     [<ffffffff814bb50e>] __kmalloc_cache_noprof+0x2be/0x390
> >     [<ffffffffa069862c>] intel_bios_init_panel+0x1c4c/0x2720 [xe]
> >     [<ffffffffa0699123>] intel_bios_init_panel_early+0x13/0x20 [xe]
> >     [<ffffffffa06fceb9>] intel_dp_init_connector+0x2f9/0x1080 [xe]
> >     [<ffffffffa06c370a>] intel_ddi_init+0xbba/0xf50 [xe]
> >     [<ffffffffa069b906>] intel_bios_for_each_encoder+0x36/0x60 [xe]
> >     [<ffffffffa06d7bd6>] intel_setup_outputs+0x206/0x450 [xe]
> >     [<ffffffffa06dad33>] intel_display_driver_probe_nogem+0x163/0x1f0 [xe]
> >     [<ffffffffa0680fc7>] xe_display_init_noaccel+0x27/0x70 [xe]
> >     [<ffffffffa05b30d6>] xe_device_probe+0x806/0x9a0 [xe]
> >     [<ffffffffa0612f0f>] xe_pci_probe+0x31f/0x590 [xe]
> >     [<ffffffff81b41718>] local_pci_probe+0x48/0xb0
> >     [<ffffffff81b432c8>] pci_device_probe+0xc8/0x280
> >     [<ffffffff81d5dde8>] really_probe+0xf8/0x390
> >     [<ffffffff81d5e11a>] __driver_probe_device+0x8a/0x170 "
> >
> > Signed-off-by: Shuicheng Lin <shuicheng.lin@intel.com>
> > Cc: Jani Nikula <jani.nikula@intel.com>
> 
> For future reference, the commit message and subject should indicate this is v2,
> and what the changes were. See submitting-patches.rst.
> 
> No need to resend for this.

Thanks Jani for your guidance. I will follow the rules for my new patches.

> 
> BR,
> Jani.
> 
> 
> > ---
> >  drivers/gpu/drm/i915/display/intel_dp.c | 1 +
> >  1 file changed, 1 insertion(+)
> >
> > diff --git a/drivers/gpu/drm/i915/display/intel_dp.c
> > b/drivers/gpu/drm/i915/display/intel_dp.c
> > index 90fa73575feb..7141e3ca0d83 100644
> > --- a/drivers/gpu/drm/i915/display/intel_dp.c
> > +++ b/drivers/gpu/drm/i915/display/intel_dp.c
> > @@ -6801,6 +6801,7 @@ static bool intel_edp_init_connector(struct
> > intel_dp *intel_dp,
> >
> >  out_vdd_off:
> >  	intel_pps_vdd_off_sync(intel_dp);
> > +	intel_bios_fini_panel(&intel_connector->panel);
> >
> >  	return false;
> >  }
> 
> --
> Jani Nikula, Intel
Shuicheng Lin Oct. 15, 2024, 4:26 p.m. UTC | #3
> On Fri, 11 Oct 2024,  Shuicheng Lin <shuicheng.lin@intel.com> wrote:
> > -----Original Message-----
> > From: Nikula, Jani <jani.nikula@intel.com>
> > Sent: Friday, October 11, 2024 1:28 AM
> > To: Lin, Shuicheng <shuicheng.lin@intel.com>;
> > intel-xe@lists.freedesktop.org; intel-gfx@lists.freedesktop.org
> > Cc: Lin, Shuicheng <shuicheng.lin@intel.com>
> > Subject: Re: [PATCH] drm/i915/dp: Fix memory leak in
> > parse_lfp_panel_dtd()
> >
> > On Thu, 10 Oct 2024, Shuicheng Lin <shuicheng.lin@intel.com> wrote:
> > > The function parse_lfp_panel_dtd() is called when the driver
> > > attempts to initialize the eDP connector, and it allocates memory,
> > > which is recorded in panel->vbt.lfp_vbt_mode. However, since no eDP
> > > panel is connected, the driver fails at intel_edp_init_dpcd() and
> > > follows the failure path. Unfortunately, the allocated memory is not
> > > freed in this case.
> > >
> > > To fix this issue, free the memory in the failure path.
> > >
> > > leak info from kmemleak:
> > > "
> > > unreferenced object 0xffff8881252f8800 (size 128):
> > >   comm "systemd-udevd", pid 192, jiffies 4294896880
> > >   hex dump (first 32 bytes):
> > >     e8 fd 00 00 00 04 18 04 a0 04 40 05 00 00 00 03  ..........@.....
> > >     03 03 09 03 26 03 00 00 0a 00 00 00 00 00 00 00  ....&...........
> > >   backtrace (crc 7448f6b4):
> > >     [<ffffffff82475c9b>] kmemleak_alloc+0x4b/0x80
> > >     [<ffffffff814bb50e>] __kmalloc_cache_noprof+0x2be/0x390
> > >     [<ffffffffa069862c>] intel_bios_init_panel+0x1c4c/0x2720 [xe]
> > >     [<ffffffffa0699123>] intel_bios_init_panel_early+0x13/0x20 [xe]
> > >     [<ffffffffa06fceb9>] intel_dp_init_connector+0x2f9/0x1080 [xe]
> > >     [<ffffffffa06c370a>] intel_ddi_init+0xbba/0xf50 [xe]
> > >     [<ffffffffa069b906>] intel_bios_for_each_encoder+0x36/0x60 [xe]
> > >     [<ffffffffa06d7bd6>] intel_setup_outputs+0x206/0x450 [xe]
> > >     [<ffffffffa06dad33>] intel_display_driver_probe_nogem+0x163/0x1f0
> [xe]
> > >     [<ffffffffa0680fc7>] xe_display_init_noaccel+0x27/0x70 [xe]
> > >     [<ffffffffa05b30d6>] xe_device_probe+0x806/0x9a0 [xe]
> > >     [<ffffffffa0612f0f>] xe_pci_probe+0x31f/0x590 [xe]
> > >     [<ffffffff81b41718>] local_pci_probe+0x48/0xb0
> > >     [<ffffffff81b432c8>] pci_device_probe+0xc8/0x280
> > >     [<ffffffff81d5dde8>] really_probe+0xf8/0x390
> > >     [<ffffffff81d5e11a>] __driver_probe_device+0x8a/0x170 "
> > >
> > > Signed-off-by: Shuicheng Lin <shuicheng.lin@intel.com>
> > > Cc: Jani Nikula <jani.nikula@intel.com>
> >
> > For future reference, the commit message and subject should indicate
> > this is v2, and what the changes were. See submitting-patches.rst.
> >
> > No need to resend for this.
> 
> Thanks Jani for your guidance. I will follow the rules for my new patches.
> 
> >
> > BR,
> > Jani.
> >
> >
> > > ---
> > >  drivers/gpu/drm/i915/display/intel_dp.c | 1 +
> > >  1 file changed, 1 insertion(+)
> > >
> > > diff --git a/drivers/gpu/drm/i915/display/intel_dp.c
> > > b/drivers/gpu/drm/i915/display/intel_dp.c
> > > index 90fa73575feb..7141e3ca0d83 100644
> > > --- a/drivers/gpu/drm/i915/display/intel_dp.c
> > > +++ b/drivers/gpu/drm/i915/display/intel_dp.c
> > > @@ -6801,6 +6801,7 @@ static bool intel_edp_init_connector(struct
> > > intel_dp *intel_dp,
> > >
> > >  out_vdd_off:
> > >  	intel_pps_vdd_off_sync(intel_dp);
> > > +	intel_bios_fini_panel(&intel_connector->panel);
> > >
> > >  	return false;
> > >  }
> >
> > --
> > Jani Nikula, Intel

Hi all,
Could you please help me review the patch and let me know if there are any questions?
Thanks.

Shuicheng
diff mbox series

Patch

diff --git a/drivers/gpu/drm/i915/display/intel_dp.c b/drivers/gpu/drm/i915/display/intel_dp.c
index 90fa73575feb..7141e3ca0d83 100644
--- a/drivers/gpu/drm/i915/display/intel_dp.c
+++ b/drivers/gpu/drm/i915/display/intel_dp.c
@@ -6801,6 +6801,7 @@  static bool intel_edp_init_connector(struct intel_dp *intel_dp,
 
 out_vdd_off:
 	intel_pps_vdd_off_sync(intel_dp);
+	intel_bios_fini_panel(&intel_connector->panel);
 
 	return false;
 }