[PATCH v3] hw/cxl: Fix CFMW config memory leak

Li Zhijian posted 1 patch 11 months ago
Failed in applying to current master (apply log)
Maintainers: Jonathan Cameron <jonathan.cameron@huawei.com>, Fan Ni <fan.ni@samsung.com>
hw/cxl/cxl-host.c | 12 ++++++------
1 file changed, 6 insertions(+), 6 deletions(-)
[PATCH v3] hw/cxl: Fix CFMW config memory leak
Posted by Li Zhijian 11 months ago
Allocate targets and targets[n] resources when all sanity checks are
passed to avoid memory leaks.

Suggested-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Signed-off-by: Li Zhijian <lizhijian@cn.fujitsu.com>
---
V3: allocte further resource when we can't fail # Philippe
V2: Delete unnecesarry check
---
 hw/cxl/cxl-host.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/hw/cxl/cxl-host.c b/hw/cxl/cxl-host.c
index 034c7805b3e..f0920da956d 100644
--- a/hw/cxl/cxl-host.c
+++ b/hw/cxl/cxl-host.c
@@ -39,12 +39,6 @@ static void cxl_fixed_memory_window_config(CXLState *cxl_state,
         return;
     }
 
-    fw->targets = g_malloc0_n(fw->num_targets, sizeof(*fw->targets));
-    for (i = 0, target = object->targets; target; i++, target = target->next) {
-        /* This link cannot be resolved yet, so stash the name for now */
-        fw->targets[i] = g_strdup(target->value);
-    }
-
     if (object->size % (256 * MiB)) {
         error_setg(errp,
                    "Size of a CXL fixed memory window must be a multiple of 256MiB");
@@ -64,6 +58,12 @@ static void cxl_fixed_memory_window_config(CXLState *cxl_state,
         fw->enc_int_gran = 0;
     }
 
+    fw->targets = g_malloc0_n(fw->num_targets, sizeof(*fw->targets));
+    for (i = 0, target = object->targets; target; i++, target = target->next) {
+        /* This link cannot be resolved yet, so stash the name for now */
+        fw->targets[i] = g_strdup(target->value);
+    }
+
     cxl_state->fixed_windows = g_list_append(cxl_state->fixed_windows,
                                              g_steal_pointer(&fw));
 
-- 
2.31.1




Re: [PATCH v3] hw/cxl: Fix CFMW config memory leak
Posted by Philippe Mathieu-Daudé 11 months ago
On 31/5/23 08:07, Li Zhijian wrote:
> Allocate targets and targets[n] resources when all sanity checks are
> passed to avoid memory leaks.
> 
> Suggested-by: Philippe Mathieu-Daudé <philmd@linaro.org>
> Signed-off-by: Li Zhijian <lizhijian@cn.fujitsu.com>
> ---
> V3: allocte further resource when we can't fail # Philippe

Thanks for the v3!

Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>

> V2: Delete unnecesarry check
> ---
>   hw/cxl/cxl-host.c | 12 ++++++------
>   1 file changed, 6 insertions(+), 6 deletions(-)


Re: [PATCH v3] hw/cxl: Fix CFMW config memory leak
Posted by Jonathan Cameron via 11 months ago
On Wed, 31 May 2023 09:51:43 +0200
Philippe Mathieu-Daudé <philmd@linaro.org> wrote:

> On 31/5/23 08:07, Li Zhijian wrote:
> > Allocate targets and targets[n] resources when all sanity checks are
> > passed to avoid memory leaks.
> > 
> > Suggested-by: Philippe Mathieu-Daudé <philmd@linaro.org>
> > Signed-off-by: Li Zhijian <lizhijian@cn.fujitsu.com>
> > ---
> > V3: allocte further resource when we can't fail # Philippe  
> 
> Thanks for the v3!
> 
> Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>

Thanks.  I've added this near the top of my queue so will send
it out along with other similar fixes as a series for Michael
to consider picking up.

Jonathan

> 
> > V2: Delete unnecesarry check
> > ---
> >   hw/cxl/cxl-host.c | 12 ++++++------
> >   1 file changed, 6 insertions(+), 6 deletions(-)  
> 
Re: [PATCH v3] hw/cxl: Fix CFMW config memory leak
Posted by Michael Tokarev 8 months, 3 weeks ago
31.05.2023 14:08, Jonathan Cameron via wrote:
> On Wed, 31 May 2023 09:51:43 +0200
> Philippe Mathieu-Daudé <philmd@linaro.org> wrote:
> 
>> On 31/5/23 08:07, Li Zhijian wrote:
>>> Allocate targets and targets[n] resources when all sanity checks are
>>> passed to avoid memory leaks.
>>>
>>> Suggested-by: Philippe Mathieu-Daudé <philmd@linaro.org>
>>> Signed-off-by: Li Zhijian <lizhijian@cn.fujitsu.com>
>>> ---
>>> V3: allocte further resource when we can't fail # Philippe
>>
>> Thanks for the v3!
>>
>> Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
> 
> Thanks.  I've added this near the top of my queue so will send
> it out along with other similar fixes as a series for Michael
> to consider picking up.

Hi!

Has this been forgotten? Is it still needed?

/mjt

Re: [PATCH v3] hw/cxl: Fix CFMW config memory leak
Posted by Jonathan Cameron via 8 months, 3 weeks ago
On Sat, 5 Aug 2023 08:46:29 +0300
Michael Tokarev <mjt@tls.msk.ru> wrote:

> 31.05.2023 14:08, Jonathan Cameron via wrote:
> > On Wed, 31 May 2023 09:51:43 +0200
> > Philippe Mathieu-Daudé <philmd@linaro.org> wrote:
> >   
> >> On 31/5/23 08:07, Li Zhijian wrote:  
> >>> Allocate targets and targets[n] resources when all sanity checks are
> >>> passed to avoid memory leaks.
> >>>
> >>> Suggested-by: Philippe Mathieu-Daudé <philmd@linaro.org>
> >>> Signed-off-by: Li Zhijian <lizhijian@cn.fujitsu.com>
> >>> ---
> >>> V3: allocte further resource when we can't fail # Philippe  
> >>
> >> Thanks for the v3!
> >>
> >> Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>  
> > 
> > Thanks.  I've added this near the top of my queue so will send
> > it out along with other similar fixes as a series for Michael
> > to consider picking up.  
> 
> Hi!
> 
> Has this been forgotten? Is it still needed?
> 
> /mjt
> 

Sorry, I'm running a bit behind.  Have this one a few other fixes
still queued up - I didn't consider any of them particularly critical
for the release so wasn't rushing.

I'll aim to get them out as a series soon though so they are
available for start of next cycle if not for slipping in before
the release.

Jonathan
Re: [PATCH v3] hw/cxl: Fix CFMW config memory leak
Posted by Michael Tokarev 7 months, 2 weeks ago
08.08.2023 17:44, Jonathan Cameron:

> Sorry, I'm running a bit behind.  Have this one a few other fixes
> still queued up - I didn't consider any of them particularly critical
> for the release so wasn't rushing.
> 
> I'll aim to get them out as a series soon though so they are
> available for start of next cycle if not for slipping in before
> the release.

A month later, friendly ping? :)
(this is sent to -stable too, fwiw).

/mjt
Re: [PATCH v3] hw/cxl: Fix CFMW config memory leak
Posted by Jonathan Cameron via 7 months, 2 weeks ago
On Fri, 8 Sep 2023 20:02:41 +0300
Michael Tokarev <mjt@tls.msk.ru> wrote:

> 08.08.2023 17:44, Jonathan Cameron:
> 
> > Sorry, I'm running a bit behind.  Have this one a few other fixes
> > still queued up - I didn't consider any of them particularly critical
> > for the release so wasn't rushing.
> > 
> > I'll aim to get them out as a series soon though so they are
> > available for start of next cycle if not for slipping in before
> > the release.  
> 
> A month later, friendly ping? :)
> (this is sent to -stable too, fwiw).

https://lore.kernel.org/qemu-devel/20230904132806.6094-2-Jonathan.Cameron@huawei.com/

Posted a series with this in last week.  Hopefully Michael will queue this
in his next pull.

Jonathan
> 
> /mjt
> 
>